question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

showing gene expression on umap not working

See original GitHub issue

When I tried to plot the expression of a particular gene on umap map by the tutorial, it always showed the following error:

>>> sc.pl.umap(post_adata, color=['XKR4'])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\ProgramData\Miniconda3\lib\site-packages\scanpy\plotting\_tools\scatterplots.py", line 542, in umap
    return embedding(adata, 'umap', **kwargs)
  File "C:\ProgramData\Miniconda3\lib\site-packages\scanpy\plotting\_tools\scatterplots.py", line 207, in embedding
    use_raw=use_raw, gene_symbols=gene_symbols,
  File "C:\ProgramData\Miniconda3\lib\site-packages\scanpy\plotting\_tools\scatterplots.py", line 865, in _get_color_values
    values = adata.raw.obs_vector(value_to_plot)
  File "C:\ProgramData\Miniconda3\lib\site-packages\anndata\core\anndata.py", line 413, in obs_vector
    idx = self._normalize_indices((slice(None), k))
  File "C:\ProgramData\Miniconda3\lib\site-packages\anndata\core\anndata.py", line 364, in _normalize_indices
    var = _normalize_index(var, self.var_names)
  File "C:\ProgramData\Miniconda3\lib\site-packages\anndata\core\anndata.py", line 155, in _normalize_index
    return name_idx(index)
  File "C:\ProgramData\Miniconda3\lib\site-packages\anndata\core\anndata.py", line 142, in name_idx
    .format(i))
IndexError: Key "XKR4" is not valid observation/variable name/index.

However, the gene XKR4 did exist in the var_names:

>>> post_adata.var_names
Index(['XKR4', 'RP1', 'SOX17', 'MRPL15', 'LYPLA1', 'TCEA1', 'RGS20', 'ATP6V1H',
       'OPRK1', 'NPBWR1',
       ...
       '2700089I24RIK', 'RAB11FIP2', 'E330013P04RIK', 'NANOS1', 'EIF3A',
       'FAM45A', 'SFXN4', 'PRDX3', 'GRK5', 'CSF2RA'],
      dtype='object', length=16249)

The anndata object looked as below and it was fine when I tried to show the louvain clusters:

>>> post_adata
AnnData object with n_obs × n_vars = 88291 × 16249
    obs: 'CellID', 'batch_indices', 'labels', 'local_means', 'local_vars', 'louvain', 'clusters'
    var: 'gene_id'
    uns: 'neighbors', 'louvain', 'louvain_colors'
    obsm: 'X_scVI', 'X_umap'

>>> sc.pl.umap(post_adata, color=['louvain'])
...

Versions:

scanpy==1.4.5.post3 anndata==0.6.22.post1 umap==0.3.10 numpy==1.18.1 scipy==1.3.2 pandas==0.25.3 scikit-learn==0.22.1 statsmodels==0.11.0 python-igraph==0.7.1+5.3b99dbf6 louvain==0.6.1

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
aditiskcommented, Apr 23, 2020

@LuckyMD thanks a lot for the detailed explanation.

0reactions
LuckyMDcommented, Apr 22, 2020

@aditisk that depends on what you put in adata.raw 😉. Initially adata.raw was used to store the full gene object when adata.X was filtered to only include HVGs or remove genes that aren’t expressed in enough cells. Now, we just have a boolean mask in adata.var['highly_variable'] for HVGs and so it’s often not used anymore. I typically store my log-normalized expression data there if I do batch correction or regress anything out, as adata.raw is used as default to compute rank_genes_groups and to show expression values on an embedding plot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

showing gene expression on umap not working #1039 - GitHub
When I tried to plot the expression of a particular gene on umap map by the tutorial, it always showed the following error:...
Read more >
scanpy.pl.umap — Scanpy 1.9.1 documentation
Use .raw attribute of adata for coloring with gene expression. If None , defaults to True if layer isn't provided and adata.raw is...
Read more >
Dimensionality reduction by UMAP to visualize physical and ...
Dimensionality reduction is often used to visualize complex expression profiling data. Here, we use the Uniform Manifold Approximation and ...
Read more >
RNA-seq - UMAP Visualization - GitHub Pages
We want to filter out the genes that have not been expressed or that have low expression counts since these genes are likely...
Read more >
how to make the "reconstructed" value in intergated scRNA ...
A reconstructed matrix in the assays() contains the corrected expression values for each gene in each cell, obtained by projecting the low-dimensional ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found