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.

sc.pl.matrixplot index error

See original GitHub issue

Since I update to scanpy==1.4.5.1 I am getting multiple plotting errors. sc.pl.rank_genes_groups() and sc.pl.violin() are still working fine but I am getting errors in the rank_genes functions like sc.pl.rank_genes_groups_violin() and sc.pl.tracksplot()

##still working fine
sc.tl.rank_genes_groups(adata, 'louvain', method='wilcoxon')
sc.pl.rank_genes_groups(adata, n_genes=25, sharey=False)
result = adata.uns['rank_genes_groups']
groups = result['names'].dtype.names

pd.DataFrame(
    {group + '_' + key[:1]: result[key][group]
    for group in groups for key in ['names', 'pvals']}).head(5)
##gives error
sc.pl.rank_genes_groups_violin(adata, groups='2', n_genes=8)

---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
~/anaconda3/lib/python3.7/site-packages/pandas/core/frame.py in _ensure_valid_index(self, value)
   3169             try:
-> 3170                 value = Series(value)
   3171             except:

~/anaconda3/lib/python3.7/site-packages/pandas/core/series.py in __init__(self, data, index, dtype, name, copy, fastpath)
    273                 data = _sanitize_array(data, index, dtype, copy,
--> 274                                        raise_cast_failure=True)
    275 

~/anaconda3/lib/python3.7/site-packages/pandas/core/series.py in _sanitize_array(data, index, dtype, copy, raise_cast_failure)
   4160         if isinstance(data, np.ndarray):
-> 4161             raise Exception('Data must be 1-dimensional')
   4162         else:

Exception: Data must be 1-dimensional

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
<ipython-input-23-ccdbf8b7836c> in <module>
----> 1 sc.pl.rank_genes_groups_violin(adata, groups='2', n_genes=8) ## 200316 error fix later, also when I run the entire script from the start

~/anaconda3/lib/python3.7/site-packages/scanpy/plotting/_tools/__init__.py in rank_genes_groups_violin(adata, groups, n_genes, gene_names, gene_symbols, use_raw, key, split, scale, strip, jitter, size, ax, show, save)
    727             if issparse(X_col): X_col = X_col.toarray().flatten()
    728             new_gene_names.append(g)
--> 729             df[g] = X_col
    730         df['hue'] = adata.obs[groups_key].astype(str).values
    731         if reference == 'rest':

~/anaconda3/lib/python3.7/site-packages/pandas/core/frame.py in __setitem__(self, key, value)
   3114         else:
   3115             # set column
-> 3116             self._set_item(key, value)
   3117 
   3118     def _setitem_slice(self, key, value):

~/anaconda3/lib/python3.7/site-packages/pandas/core/frame.py in _set_item(self, key, value)
   3188         """
   3189 
-> 3190         self._ensure_valid_index(value)
   3191         value = self._sanitize_column(key, value)
   3192         NDFrame._set_item(self, key, value)

~/anaconda3/lib/python3.7/site-packages/pandas/core/frame.py in _ensure_valid_index(self, value)
   3170                 value = Series(value)
   3171             except:
-> 3172                 raise ValueError('Cannot set a frame with no defined index '
   3173                                  'and a value that cannot be converted to a '
   3174                                  'Series')

ValueError: Cannot set a frame with no defined index and a value that cannot be converted to a Series

Versions:

scanpy==1.4.5.1 anndata==0.7.1 umap==0.3.10 numpy==1.18.1 scipy==1.4.1 pandas==0.23.0 scikit-learn==0.21.3 statsmodels==0.11.0 python-igraph==0.7.1 louvain==0.6.1 scvelo==0.1.25 scanpy==1.4.5.1 anndata==0.7.1 loompy==3.0.6 numpy==1.18.1 scipy==1.4.1 matplotlib==3.1.3 sklearn==0.21.3 pandas==0.23.0

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ivirshupcommented, May 12, 2021

@Maarten-vd-Sande, it looks like the issue here is a bug with handling dense data. With your particular example here, you should be fine to work around this by using a sparse matrix.

from scipy import sparse
All.X = sparse.csr_matrix(All.X)
0reactions
Maarten-vd-Sandecommented, Jun 23, 2021

@ivirshup I never replied, sorry. Your solution indeed fixed it for us. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

sc.pl.matrixplot index error · Issue #1114 · scverse/scanpy
Since I update to scanpy==1.4.5.1 I am getting multiple plotting errors. sc.pl.rank_genes_groups() and sc.pl.violin() are still working fine ...
Read more >
scanpy.pl.matrixplot — Scanpy 1.9.1 documentation
var DataFrame that stores gene symbols. By default var_names refer to the index column of the .var DataFrame. Setting this option allows alternative...
Read more >
CITE-seq analysis — scvi 0.7.0 documentation
Matrix plot displays totalVI denoised protein expression per leiden cluster. [20]:. sc.pl.
Read more >
Plotting a diagonal correlation matrix - Seaborn - PyData |
Plotting a diagonal correlation matrix# ../_images/many_pairwise_correlations.png. seaborn components used: set_theme() , diverging_palette() , heatmap().
Read more >
Cell-Phenotyping using Scimap
sc.tl.umap(adata) # Build a UMAP to visualize the neighbourhood graph ... sc.pl.matrixplot(adata, var_names= adata.var.index, ...
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