scverse / scverse/scanpy

dotplot cannot set gene_symbols

Open
#1,636 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Area - Plotting 🌺 Needs info❔
Dominant language
Python
Stars
2.6k
Forks
779
Avg merge
1d 4h
Merged PRs (30d)
27

Description

I would like to change the var name when plotting dotplot by setting the gene_symbols to the desired name. But this generates the NameError. Below is an example using the scanpy built-in dataset.

adata = sc.datasets.pbmc68k_reduced()
ax = sc.pl.dotplot(adata, 'C1QA', groupby=['bulk_labels'], swap_axes=False, gene_symbols='TEST')
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-45-206578ef4fd5> in <module>
      1 adata = sc.datasets.pbmc68k_reduced()
----> 2 ax = sc.pl.dotplot(adata, 'C1QA', groupby=['bulk_labels'], swap_axes=False, gene_symbols='TEST')
      3 

~/anaconda3/envs/scRNA/lib/python3.6/site-packages/scanpy/plotting/_dotplot.py in dotplot(adata, var_names, groupby, use_raw, log, num_categories, expression_cutoff, mean_only_expressed, cmap, dot_max, dot_min, standard_scale, smallest_dot, title, colorbar_title, size_title, figsize, dendrogram, gene_symbols, var_group_positions, var_group_labels, var_group_rotation, layer, swap_axes, dot_color_df, show, save, ax, return_fig, **kwds)
    930         dot_color_df=dot_color_df,
    931         ax=ax,
--> 932         **kwds,
    933     )
    934 

~/anaconda3/envs/scRNA/lib/python3.6/site-packages/scanpy/plotting/_dotplot.py in __init__(self, adata, var_names, groupby, use_raw, log, num_categories, categories_order, title, figsize, gene_symbols, var_group_positions, var_group_labels, var_group_rotation, layer, expression_cutoff, mean_only_expressed, standard_scale, dot_color_df, dot_size_df, ax, **kwds)
    142             layer=layer,
    143             ax=ax,
--> 144             **kwds,
    145         )
    146 

~/anaconda3/envs/scRNA/lib/python3.6/site-packages/scanpy/plotting/_baseplot_class.py in __init__(self, adata, var_names, groupby, use_raw, log, num_categories, categories_order, title, figsize, gene_symbols, var_group_positions, var_group_labels, var_group_rotation, layer, ax, **kwds)
    111             num_categories,
    112             layer=layer,
--> 113             gene_symbols=gene_symbols,
    114         )
    115 

~/anaconda3/envs/scRNA/lib/python3.6/site-packages/scanpy/plotting/_anndata.py in _prepare_dataframe(adata, var_names, groupby, use_raw, log, num_categories, layer, gene_symbols)
   1837         # translate the column names to the symbol names
   1838         obs_tidy.rename(
-> 1839             columns={var_names[x]: symbols[x] for x in range(len(var_names))},
   1840             inplace=True,
   1841         )

~/anaconda3/envs/scRNA/lib/python3.6/site-packages/scanpy/plotting/_anndata.py in <dictcomp>(.0)
   1837         # translate the column names to the symbol names
   1838         obs_tidy.rename(
-> 1839             columns={var_names[x]: symbols[x] for x in range(len(var_names))},
   1840             inplace=True,
   1841         )

NameError: free variable 'symbols' referenced before assignment in enclosing scope
Versions

scanpy==1.6.0 anndata==0.7.4 umap==0.3.10 numpy==1.18.4 scipy==1.4.1 pandas==1.0.3 scikit-learn==0.21.3 statsmodels==0.10.1 python-igraph==0.8.2 louvain==0.6.1 leidenalg==0.8.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the example with scanpy.pl.dotplot and trace the gene_symbols handling through plotting/_dotplot.py, plotting/_baseplot_class.py, and plotting/_anndata.py. Verify that the call no longer raises the reported NameError and that the requested gene symbol is used for the plotted label.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data-visualization
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.