Scanpy: sc.pl.scatter for var

Created on 2 Aug 2019  路  8Comments  路  Source: theislab/scanpy

I get the following error when trying to use sc.pl.scatter to plot gene expression, with use_raw=False. I am using sc.pl.scatter instead of sc.pl.umap, .tsne, etc., because of the need to use custom basis names.

  File "/opt/Python/3.6.5/lib/python3.6/site-packages/scanpy/plotting/_anndata.py", line 118, in scatter
    ax=ax)
  File "/opt/Python/3.6.5/lib/python3.6/site-packages/scanpy/plotting/_anndata.py", line 390, in _scatter_obs
    c = adata.raw.obs_vector(key, layer=layers[2])
TypeError: obs_vector() got an unexpected keyword argument 'layer'

The following snippet is copied from _scatter_obs() in /scanpy/plotting/_anndata.py

        # coloring according to gene expression
        elif (use_raw
              and adata.raw is not None
              and key in adata.raw.var_names):
            c = adata.raw.obs_vector(key)
        elif key in adata.var_names:
            c = adata.raw.obs_vector(key, layer=layers[2])

Should line 390 be c = adata.obs_vector(key, layer=layers[2]) since it is handling the case when use_raw==False and adata.raw.obs_vector does not take layer as argument.

bug

All 8 comments

Thanks for the bug report! That sounds totally right, would you mind submitting a PR to fix that?

@coh-racng I would like to add that for your specific intention the best way is to load the plot_scatter function that accepts basis as parameter and works well with layers.

The code should be:

from scanpy._plotting.scatterplots import plot_scatter`
plot_scatter(adata, basis='<name>'....)

@ivirshup, @falexwolf I think we should add plot_scatter to the API maybe renaming it plot_embedding to help users like @coh-racng. Currently we have two different ways to make scatter plots: One for embeddings (plot_scatter) and other more generic for obs and vars (sc.pl.scatter) that accepts x and y parameters.

Definitely agree with you @fidelram, I think the main thing stopping us before was unfortunately just picking the name. plot_{...} doesn't really match any of our other functions. Names that come up for me are: sc.pl.scatter (obviously taken), sc.pl.dimred, or sc.pl.scatter_obsm.

@ivirshup we can use sc.pl.embedding. Thats what scvelo did but adding the velocity part scv.pl.velocity_embedding(adata, ... basis=...).

That'd work for me! Otherwise I'd been thinking sc.pl.obsm.

I will add this later together with other goodies

Hi @fidelram, did you get around to it? Can this be closed?

Update: The initial issue has been fixed, we don't have a more generic embedding plotting function yet.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wangjiawen2013 picture wangjiawen2013  路  5Comments

koalap-2018 picture koalap-2018  路  3Comments

tkisss picture tkisss  路  5Comments

falexwolf picture falexwolf  路  4Comments

MichaelPeibo picture MichaelPeibo  路  6Comments