Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error plotting velocity_embedding #1098

Closed
johnjeang opened this issue Jul 14, 2023 · 1 comment
Closed

error plotting velocity_embedding #1098

johnjeang opened this issue Jul 14, 2023 · 1 comment
Labels
bug Something isn't working duplicate Duplicated issue

Comments

@johnjeang
Copy link

Hello, I am using the scvelo package to analyze my RNAseq data. I think this is a great tool, but I'm just running into a few errors when trying to follow the tutorial here: https://scvelo.readthedocs.io/en/stable/getting_started/

...

To simplify the reproducibility I am using the pancreas dataset provided by scvelo.

import scvelo as scv
adata = scv.datasets.pancreas()
scv.pp.filter_and_normalize(adata)
scv.pp.moments(adata)
scv.tl.velocity(adata, mode='stochastic')
scv.tl.velocity_graph(adata)

The above code appears to work fine and creates what I think are the correct fields in the adata.uns and adata.layers attributes of the anndata object. However I run into the following error when plotting.

# All of these produce the same error
# scv.pl.velocity_embedding(adata, basis='umap', color = ['clusters'])
# scv.pl.velocity_embedding_grid(adata, basis='umap', color = ['clusters'])
# scv.pl.velocity_embedding_stream(adata, basis='velocity_umap', color = ['clusters'])
# scv.pl.velocity(adata, var_names=['Sox17','Xkr4'], color = ['clusters'])
Error output
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[25], line 3
      1 # scv.pl.velocity_embedding(adata, basis='umap')
      2 # scv.pl.velocity_embedding_grid(adata, basis='umap')
----> 3 scv.pl.velocity_embedding_stream(adata, basis='velocity_umap')
      4 # scv.pl.velocity(adata, var_names=['Sox17','Xkr4'])

File ~/opt/anaconda3/envs/cellrank/lib/python3.9/site-packages/scvelo/plotting/velocity_embedding_stream.py:252, in velocity_embedding_stream(adata, basis, vkey, density, smooth, min_mass, cutoff_perc, arrow_color, arrow_size, arrow_style, max_length, integration_direction, linewidth, n_neighbors, recompute, color, use_raw, layer, color_map, colorbar, palette, size, alpha, perc, X, V, X_grid, V_grid, sort_order, groups, components, legend_loc, legend_fontsize, legend_fontweight, xlabel, ylabel, title, fontsize, figsize, dpi, frameon, show, save, ax, ncols, **kwargs)
    249 ax.streamplot(X_grid[0], X_grid[1], V_grid[0], V_grid[1], **stream_kwargs)
    251 size = 8 * default_size(adata) if size is None else size
--> 252 ax = scatter(
    253     adata,
    254     layer=layer,
    255     color=color,
    256     size=size,
    257     title=title,
    258     ax=ax,
    259     zorder=0,
    260     **scatter_kwargs,
    261 )
    262 if save is True:
    263     save = "embedding_stream"

File ~/opt/anaconda3/envs/cellrank/lib/python3.9/site-packages/scvelo/plotting/scatter.py:668, in scatter(adata, basis, x, y, vkey, color, use_raw, layer, color_map, colorbar, palette, size, alpha, linewidth, linecolor, perc, groups, sort_order, components, projection, legend_loc, legend_loc_lines, legend_fontsize, legend_fontweight, legend_fontoutline, legend_align_text, xlabel, ylabel, title, fontsize, figsize, xlim, ylim, add_density, add_assignments, add_linfit, add_polyfit, add_rug, add_text, add_text_pos, add_margin, add_outline, outline_width, outline_color, n_convolve, smooth, normalize_data, rescale_color, color_gradients, dpi, frameon, zorder, ncols, nrows, wspace, hspace, show, save, ax, **kwargs)
    666     if not (add_outline is None or g_bool is None):
    667         groups = add_outline
--> 668     set_legend(
    669         adata,
    670         ax,
    671         color,
    672         legend_loc,
    673         scatter_array,
    674         legend_fontweight,
    675         legend_fontsize,
    676         legend_fontoutline,
    677         legend_align_text,
    678         groups,
    679     )
    680 if add_density:
    681     plot_density(x, y, add_density, ax=ax)

File ~/opt/anaconda3/envs/cellrank/lib/python3.9/site-packages/scvelo/plotting/utils.py:555, in set_legend(adata, ax, value_to_plot, legend_loc, scatter_array, legend_fontweight, legend_fontsize, legend_fontoutline, legend_align_text, groups)
    553     legend_fontoutline = 1
    554 obs_vals = adata.obs[value_to_plot]
--> 555 obs_vals.cat.categories = obs_vals.cat.categories.astype(str)
    556 color_keys = adata.uns[f"{value_to_plot}_colors"]
    557 if isinstance(color_keys, dict):

File ~/opt/anaconda3/envs/cellrank/lib/python3.9/site-packages/pandas/core/base.py:178, in NoNewAttributesMixin.__setattr__(self, key, value)
    172 if getattr(self, "__frozen", False) and not (
    173     key == "_cache"
    174     or key in type(self).__dict__
    175     or getattr(self, key, None) is not None
    176 ):
    177     raise AttributeError(f"You cannot add any new attribute '{key}'")
--> 178 object.__setattr__(self, key, value)

File ~/opt/anaconda3/envs/cellrank/lib/python3.9/site-packages/pandas/core/accessor.py:99, in PandasDelegate._add_delegate_accessors.<locals>._create_delegator_property.<locals>._setter(self, new_values)
     98 def _setter(self, new_values):
---> 99     return self._delegate_property_set(name, new_values)

File ~/opt/anaconda3/envs/cellrank/lib/python3.9/site-packages/pandas/core/arrays/categorical.py:2460, in CategoricalAccessor._delegate_property_set(self, name, new_values)
   2459 def _delegate_property_set(self, name, new_values):
-> 2460     return setattr(self._parent, name, new_values)

AttributeError: can't set attribute

To be fair, plots actually are produced, but I wondered whether I should be worried about this error -- like if the plots have incomplete calculations? The plots also seem to be missing their legend.

Versions

Here are the package versions I am using. Originally I had numpy==1.24.4, but I was having some compatibility issues so I downgraded to 1.21.5.

scvelo==0.2.5  scanpy==1.9.3  anndata==0.9.1  loompy==3.0.7  numpy==1.21.5  scipy==1.11.1  matplotlib==3.7.2  sklearn==1.1.3  pandas==2.0.3 

Thanks so much!

@johnjeang johnjeang added the bug Something isn't working label Jul 14, 2023
@WeilerP WeilerP added the duplicate Duplicated issue label Jul 14, 2023
@WeilerP WeilerP closed this as completed Jul 14, 2023
@anemartinezlarrinaga2898

Hello,

I'm having the same issue how did you solved it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate Duplicated issue
Projects
None yet
Development

No branches or pull requests

3 participants