mossjacob / pyslingshot

Python implementation of the Slingshot pseudotime algorithm
51 stars 7 forks source link

ZeroDivisonError #10

Closed dsm-72 closed 1 year ago

dsm-72 commented 1 year ago

Sometimes happens. Don't know why. https://github.com/mossjacob/pyslingshot/blob/master/slingshot/plotter.py#L48

hmassalha commented 1 year ago

I am facing the same error when using my data, while it is not raise with the synthetic dataset.. any suggestions? thanks.

---------------------------------------------------------------------------
ZeroDivisionError                         Traceback (most recent call last)
Input In [16], in <module>
      4 # plt.setp(axes, xlim=custom_xlim, ylim=custom_ylim)
      6 slingshot = Slingshot(data, cluster_labels_onehot, start_node=start_node, debug_level='verbose')
----> 8 slingshot.fit(num_epochs=2, debug_axes=axes)

File ~/my-conda-envs/sc_Harm/lib/python3.10/site-packages/slingshot/slingshot.py:135, in Slingshot.fit(self, num_epochs, debug_axes)
    133 self._set_debug_axes(debug_axes)
    134 if self.curves is None:  # Initial curves and pseudotimes:
--> 135     self.get_lineages()
    136     self.construct_initial_curves()
    137     self.cell_weights = [self.cluster_labels_onehot[:, self.lineages[l].clusters].sum(axis=1)
    138                          for l in range(len(self.lineages))]

File ~/my-conda-envs/sc_Harm/lib/python3.10/site-packages/slingshot/slingshot.py:195, in Slingshot.get_lineages(self)
    194 def get_lineages(self):
--> 195     tree = self.construct_mst(self.start_node)
    197     # Determine lineages by parsing the MST
    198     branch_clusters = deque()

File ~/my-conda-envs/sc_Harm/lib/python3.10/site-packages/slingshot/slingshot.py:123, in Slingshot.construct_mst(self, start_node)
    121 # Plot clusters and MST
    122 if self.debug_plot_mst:
--> 123     self.plotter.clusters(self.debug_axes[0, 0], alpha=0.5)
    124     for root, kids in children.items():
    125         for child in kids:

File ~/my-conda-envs/sc_Harm/lib/python3.10/site-packages/slingshot/plotter.py:77, in SlingshotPlotter.clusters(self, ax, labels, s, alpha, color_mode)
     75 if color_mode == 'clusters':
     76     colors = np.array(sns.color_palette('cubehelix', n_colors=sling.num_clusters))
---> 77     colors = generate_colormap(sling.num_clusters)
     79     handles = [
     80         Patch(color=colors.colors[k], label=labels[k]) for k in range(sling.num_clusters)
     81     ]
     82     ax.legend(handles=handles)

File ~/my-conda-envs/sc_Harm/lib/python3.10/site-packages/slingshot/plotter.py:48, in generate_colormap(number_of_distinct_colors)
     46 lower_half = lower_partitions_half * number_of_shades
     47 for i in range(3):
---> 48     initial_cm[0:lower_half, i] *= np.arange(0.2, 1, 0.8/lower_half)
     50 # Modify second half in such way that colours towards end of partition are less intense and brighter
     51 # Colours closer to the middle are affected less, colours closer to the end are affected more
     52 for i in range(3):

ZeroDivisionError: float division by zero