cistrome / MIRA

Python package for analysis of multiomic single cell RNA-seq and ATAC-seq.
52 stars 7 forks source link

IndexError in mira.pl.plot_stream #26

Closed jmmuncie closed 1 year ago

jmmuncie commented 1 year ago

I am trying to generate plot streams using the following code:

data_RNA.obs.Genotype = data_RNA.obs.Genotype.astype(str)

mira.pl.plot_stream(data_RNA, data = 'Genotype', log_pseudotime=False, max_bar_height=0.99, title = 'Genotype',
                    figsize=(10,5), style = 'swarm', palette='Set3', size = 5, max_swarm_density = 100)

But I receive the following error. I had no trouble with the preceding step of defining pseudotime and parsing lineage probabilities. In fact, I was previously able to generate plot streams, but for some reason, I now get this error. I haven't made any changes to my conda environment. Please let me know if you have any ideas about what may be causing this issue.

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
/scratch/jmuncie/ipykernel_170397/3103921715.py in <module>
      2 
      3 mira.pl.plot_stream(data_RNA, data = 'Genotype', log_pseudotime=False, max_bar_height=0.99, title = 'Genotype',
----> 4                     figsize=(10,5), style = 'swarm', palette='Set3', size = 5, max_swarm_density = 100)
      5 

~/.conda/envs/mira-env/lib/python3.7/site-packages/mira/adata_interface/core.py in _run(adata, *args, **kwargs)
     70             #print(fetch(None, adata, **getter_kwargs))
     71 
---> 72             output = func(**fetch(None, adata, **getter_kwargs), **function_kwargs)
     73             #print(output, adata, adder_kwargs)
     74             return add(adata, output, **adder_kwargs)

~/.conda/envs/mira-env/lib/python3.7/site-packages/mira/plots/streamplot.py in plot_stream(style, split, log_pseudotime, scale_features, order, title, show_legend, legend_cols, max_bar_height, size, max_swarm_density, hide_feature_threshold, palette, color, linecolor, linewidth, hue_order, pseudotime_triangle, scaffold_linecolor, scaffold_linewidth, min_pseudotime, orientation, figsize, ax, plots_per_row, height, aspect, tree_structure, center_baseline, window_size, clip, alpha, vertical, enforce_max, feature_labels, group_names, tree_graph, features, pseudotime, group)
    761             fig, ax = plt.subplots(1,1,figsize=figsize)
    762 
--> 763         make_plot(ax, features)
    764 
    765         if not title is None:

~/.conda/envs/mira-env/lib/python3.7/site-packages/mira/plots/streamplot.py in make_plot(ax, features)
    738         if tree_structure:
    739             _build_tree(**build_tree_kwargs, features = features, ax = ax, plot_fn=scaffold_fn)
--> 740             plot_bottom = _build_tree(**build_tree_kwargs, features = features, ax = ax, plot_fn=segment_fn)
    741 
    742         else:

~/.conda/envs/mira-env/lib/python3.7/site-packages/mira/plots/streamplot.py in _build_tree(cell_colors, size, shape, max_bar_height, ax, features, pseudotime, cluster_id, tree_graph, lineage_names, min_pseudotime, plot_fn)
    311 
    312             plot_fn(features = segment_features, pseudotime = segment_pseudotime, is_leaf = segment_is_leaf, is_root = not has_plotted, ax = ax,
--> 313                 centerline = centerline, lineage_name = lineage_names[end_clus], segment_connection = connection, cell_colors = segment_cell_colors)
    314             has_plotted = True
    315 

~/.conda/envs/mira-env/lib/python3.7/site-packages/mira/plots/swarmplot.py in _plot_swarm_segment(is_leaf, centerline, palette, feature_labels, linecolor, linewidth, hue_order, show_legend, size, is_root, max_swarm_density, orientation, color, min_pseudotime, max_bar_height, ax, features, pseudotime, cell_colors, **kwargs)
    255         )
    256 
--> 257         Beeswarm(orient='h', width = max_bar_height)(points, centerline)
    258 
    259     ax.axis('off')

~/.conda/envs/mira-env/lib/python3.7/site-packages/mira/plots/swarmplot.py in __call__(self, points, center)
     51         # Adjust points along the categorical axis to prevent overlaps
     52         new_xyr = np.empty_like(orig_xyr)
---> 53         new_xyr[sorter] = self.beeswarm(orig_xyr)
     54 
     55         # Transform the point coordinates back to data coordinates

~/.conda/envs/mira-env/lib/python3.7/site-packages/mira/plots/swarmplot.py in beeswarm(self, orig_xyr)
     79         # In this method, `x` is always the categorical axis
     80         # Center of the swarm, in point coordinates
---> 81         midline = orig_xyr[0, 0]
     82 
     83         # Start the swarm with the first point

~/.conda/envs/mira-env/lib/python3.7/site-packages/numpy/ma/core.py in __getitem__(self, indx)
   3222         # mask of being reshaped if it hasn't been set up properly yet
   3223         # So it's easier to stick to the current version
-> 3224         dout = self.data[indx]
   3225         _mask = self._mask
   3226 

IndexError: index 0 is out of bounds for axis 0 with size 0
jmmuncie commented 1 year ago

Nevermind. I don't think this was a bug, but an issue introduced by my analysis. I believe this was resulting from an issue with the parsing of lineage probabilities where zero cells were being placed into one or more of the terminal states.