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.

mito_genes and ValueError Traceback (most recent call last)

See original GitHub issue
mito_genes = adata.var_names.str.startswith('MT-')
adata.obs['percent_mito'] = np.sum(adata[:, mito_genes].X, axis=1).A1 / np.sum(adata.X, axis=1).A1
adata.obs['n_counts'] = adata.X.sum(axis=1).A1
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-31-4b64d0e9fd7f> in <module>
      2 # for each cell compute fraction of counts in mito genes vs. all genes
      3 # the `.A1` is only necessary as X is sparse (to transform to a dense array after summing)
----> 4 adata.obs['percent_mito'] = np.sum(adata[:, mito_genes].X, axis=1).A1 / np.sum(adata.X, axis=1).A1
      5 # add the total counts per cell as observations-annotation to adata
      6 adata.obs['n_counts'] = adata.X.sum(axis=1).A1

c:\users\gsy\miniconda3\second\lib\site-packages\anndata\base.py in __getitem__(self, index)
   1297     def __getitem__(self, index: Index) -> 'AnnData':
   1298         """Returns a sliced view of the object."""
-> 1299         return self._getitem_view(index)
   1300 
   1301     def _getitem_view(self, index: Index) -> 'AnnData':

c:\users\gsy\miniconda3\second\lib\site-packages\anndata\base.py in _getitem_view(self, index)
   1300 
   1301     def _getitem_view(self, index: Index) -> 'AnnData':
-> 1302         oidx, vidx = self._normalize_indices(index)
   1303         return AnnData(self, oidx=oidx, vidx=vidx, asview=True)
   1304 

c:\users\gsy\miniconda3\second\lib\site-packages\anndata\base.py in _normalize_indices(self, index)
   1277         obs, var = super()._unpack_index(index)
   1278         obs = _normalize_index(obs, self.obs_names)
-> 1279         var = _normalize_index(var, self.var_names)
   1280         return obs, var
   1281 

c:\users\gsy\miniconda3\second\lib\site-packages\anndata\base.py in _normalize_index(index, names)
    264         # incredibly faster one
    265         positions = pd.Series(index=names, data=range(len(names)))
--> 266         positions = positions[index]
    267         if positions.isnull().values.any():
    268             raise KeyError(

c:\users\gsy\miniconda3\second\lib\site-packages\pandas\core\series.py in __getitem__(self, key)
    906             key = list(key)
    907 
--> 908         if com.is_bool_indexer(key):
    909             key = check_bool_indexer(self.index, key)
    910 

c:\users\gsy\miniconda3\second\lib\site-packages\pandas\core\common.py in is_bool_indexer(key)
    122             if not lib.is_bool_array(key):
    123                 if isna(key).any():
--> 124                     raise ValueError(na_msg)
    125                 return False
    126             return True

ValueError: cannot index with vector containing NA / NaN values

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
LuckyMDcommented, May 16, 2019

If you have no mitochondrial genes, you can’t plot them. The first line of your code looks for genes whose names start with “MT-”. For mouse data that should be “mt-”, or maybe you have a different nomenclature… or you don’t have any mitochondrial genes in your dataset (possible for Cell ranger versions < 2.0).

I can’t really debug this, as it requires looking and playing with your dataset.

Good luck!

0reactions
sygongcodecommented, May 16, 2019

If you have no mitochondrial genes, you can’t plot them. The first line of your code looks for genes whose names start with “MT-”. For mouse data that should be “mt-”, or maybe you have a different nomenclature… or you don’t have any mitochondrial genes in your dataset (possible for Cell ranger versions < 2.0).

I can’t really debug this, as it requires looking and playing with your dataset.

Good luck!

Thank you for your help. My data is Drosophila data. I think maybe there are no mitochondrial genes in the data. Your reply is very helpful.

Read more comments on GitHub >

github_iconTop Results From Across the Web

mito_genes and ValueError Traceback (most recent call last)
Is your mito_genes vector all boolean? And does it have a non-zero sum? You seem to be getting NA values according to the...
Read more >
ValueError Traceback (most recent call last), python scrapy ...
i run this code on in terminal scrapy shell, it produce an error as ValueError Traceback. too many values to ...
Read more >
leapp preupgrade command is failing with a python ...
leapp preupgrade is failing with the following error. Raw. # leapp preupgrade Traceback (most recent call last): File "/bin/leapp", line 5, in < ......
Read more >
Dissertation
Hence, cell cycle entry is blocked in the absence of mitogens and nutrients by a checkpoint called Start in yeast and restriction point...
Read more >
Modulating the interaction between hgf beta chain and c-met
The invention provides methods and compositions for modulating the HGF/c-met signaling pathway ... Current Assignee (The listed assignees may be inaccurate.
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