Skip to content

f"Values {list(not_found)}, from {list(indexer)}, " "are not valid obs/ var names or indices." #1487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
brianpenghe opened this issue Nov 7, 2020 · 4 comments
Labels
good first issue easy first issue to get started in OSS community contribution!

Comments

@brianpenghe
Copy link

brianpenghe commented Nov 7, 2020

This bug only occurred in 1.6.0 but not 1.5.0

I was running scanpy 1.6.0 this:

sc.tl.filter_rank_genes_groups(adata, groupby=obs,\ max_out_group_fraction=max_out_group_fraction, min_fold_change=min_fold_change,use_raw=use_raw, min_in_group_fraction=0.25,log=log)

But got this error:

Filtering genes using: min_in_group_fraction: 0.25 min_fold_change: 2, max_out_group_fraction: 0.25

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-91-d477dca208af> in <module>
      2                     max_out_group_fraction=max_out_group_fraction,
      3                     min_fold_change=min_fold_change,use_raw=use_raw,
----> 4                     min_in_group_fraction=0.25,log=log)

/usr/local/lib/python3.6/dist-packages/scanpy/tools/_rank_genes_groups.py in filter_rank_genes_groups(adata, key, groupby, use_raw, log, key_added, min_in_group_fraction, min_fold_change, max_out_group_fraction)
    725             var_names,
    726             groupby='__is_in_cluster__',
--> 727             use_raw=use_raw,
    728         )
    729 

/usr/local/lib/python3.6/dist-packages/scanpy/plotting/_anndata.py in _prepare_dataframe(adata, var_names, groupby, use_raw, log, num_categories, layer, gene_symbols)
   1808         matrix = adata.raw[:, var_names].X
   1809     else:
-> 1810         matrix = adata[:, var_names].X
   1811 
   1812     if issparse(matrix):

/usr/local/lib/python3.6/dist-packages/anndata/_core/anndata.py in __getitem__(self, index)
   1085     def __getitem__(self, index: Index) -> "AnnData":
   1086         """Returns a sliced view of the object."""
-> 1087         oidx, vidx = self._normalize_indices(index)
   1088         return AnnData(self, oidx=oidx, vidx=vidx, asview=True)
   1089 

/usr/local/lib/python3.6/dist-packages/anndata/_core/anndata.py in _normalize_indices(self, index)
   1066 
   1067     def _normalize_indices(self, index: Optional[Index]) -> Tuple[slice, slice]:
-> 1068         return _normalize_indices(index, self.obs_names, self.var_names)
   1069 
   1070     # TODO: this is not quite complete...

/usr/local/lib/python3.6/dist-packages/anndata/_core/index.py in _normalize_indices(index, names0, names1)
     33     ax0, ax1 = unpack_index(index)
     34     ax0 = _normalize_index(ax0, names0)
---> 35     ax1 = _normalize_index(ax1, names1)
     36     return ax0, ax1
     37 

/usr/local/lib/python3.6/dist-packages/anndata/_core/index.py in _normalize_index(indexer, index)
     99                 not_found = indexer[positions < 0]
    100                 raise KeyError(
--> 101                     f"Values {list(not_found)}, from {list(indexer)}, "
    102                     "are not valid obs/ var names or indices."
    103                 )

KeyError: "Values ['LINC00601', 'DPYS', 'AC136604.2', 'AC023137.1', 'MATN3', 'AL359921.1' 
...
 'FAM129C', 'TCL1A'], are not valid obs/ var names or indices."
@brianpenghe brianpenghe added the bug label Nov 7, 2020
@gokceneraslan gokceneraslan added the good first issue easy first issue to get started in OSS community contribution! label Nov 10, 2020
@LisaSikkema
Copy link
Contributor

Hi Brian,
Did you do any subsetting of your adata between running rank_genes_groups and filter_rank_genes_groups? The only way I can reproduce your error is by removing genes from my adata in between the two commands.

@brianpenghe
Copy link
Author

Hi Lisa, I didn't remove genes. Currently I'm using scanpy1.5.0 and everything is fine.

@LisaSikkema
Copy link
Contributor

Okay, when I run this:
adata = sc.datasets.pbmc68k_reduced()
sc.tl.rank_genes_groups(adata, "bulk_labels", method="wilcoxon")
sc.tl.filter_rank_genes_groups(adata, min_fold_change=3)
I get no error.
Can you find a reproducible example of your error?

@jnmark
Copy link

jnmark commented May 26, 2021

@brianpenghe Did you find a solution for this? I am getting the same error in scanpy 1.7.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue easy first issue to get started in OSS community contribution!
Projects
None yet
Development

No branches or pull requests

5 participants