Error when running sc.tl.rank_genes_groups
Please make sure these conditions are met
- [x] I have checked that this issue has not already been reported.
- [x] I have confirmed this bug exists on the latest version of scanpy.
- [ ] (optional) I have confirmed this bug exists on the main branch of scanpy.
What happened?
Hello, I got an error when trying to run sc.tl.rank_genes_groups on xenium data. The error message show below: Could you please help? Thank you very much
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[134], [line 1](vscode-notebook-cell:?execution_count=134&line=1)
----> [1](vscode-notebook-cell:?execution_count=134&line=1) sc.tl.rank_genes_groups(adata_tcell, 'Enriched_Factor', method='t-test', key_added = "t-test")
[2](vscode-notebook-cell:?execution_count=134&line=2) sc.pl.rank_genes_groups(adata_tcell, n_genes=25, sharey=False, key = "t-test")
[4](vscode-notebook-cell:?execution_count=134&line=4) # results are stored in the adata.uns["t-test"] slot
File /opt/anaconda3/envs/istar2/lib/python3.9/site-packages/legacy_api_wrap/__init__.py:80, in legacy_api.<locals>.wrapper.<locals>.fn_compatible(*args_all, **kw)
[77](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/istar2/lib/python3.9/site-packages/legacy_api_wrap/__init__.py:77) @wraps(fn)
[78](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/istar2/lib/python3.9/site-packages/legacy_api_wrap/__init__.py:78) def fn_compatible(*args_all: P.args, **kw: P.kwargs) -> R:
[79](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/istar2/lib/python3.9/site-packages/legacy_api_wrap/__init__.py:79) if len(args_all) <= n_positional:
---> [80](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/istar2/lib/python3.9/site-packages/legacy_api_wrap/__init__.py:80) return fn(*args_all, **kw)
[82](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/istar2/lib/python3.9/site-packages/legacy_api_wrap/__init__.py:82) args_pos: P.args
[83](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/istar2/lib/python3.9/site-packages/legacy_api_wrap/__init__.py:83) args_pos, args_rest = args_all[:n_positional], args_all[n_positional:]
File /opt/anaconda3/envs/istar2/lib/python3.9/site-packages/scanpy/tools/_rank_genes_groups.py:682, in rank_genes_groups(adata, groupby, mask_var, use_raw, groups, reference, n_genes, rankby_abs, pts, key_added, copy, method, corr_method, tie_correct, layer, **kwds)
[679](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/istar2/lib/python3.9/site-packages/scanpy/tools/_rank_genes_groups.py:679) logg.debug(f"consider {groupby!r} groups:")
[680](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/istar2/lib/python3.9/site-packages/scanpy/tools/_rank_genes_groups.py:680) logg.debug(f"with sizes: {np.count_nonzero(test_obj.groups_masks_obs, axis=1)}")
--> [682](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/istar2/lib/python3.9/site-packages/scanpy/tools/_rank_genes_groups.py:682) test_obj.compute_statistics(
[683](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/istar2/lib/python3.9/site-packages/scanpy/tools/_rank_genes_groups.py:683) method,
[684](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/istar2/lib/python3.9/site-packages/scanpy/tools/_rank_genes_groups.py:684) corr_method=corr_method,
[685](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/istar2/lib/python3.9/site-packages/scanpy/tools/_rank_genes_groups.py:685) n_genes_user=n_genes_user,
[686](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/istar2/lib/python3.9/site-packages/scanpy/tools/_rank_genes_groups.py:686) rankby_abs=rankby_abs,
[687](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/istar2/lib/python3.9/site-packages/scanpy/tools/_rank_genes_groups.py:687) tie_correct=tie_correct,
[688](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/istar2/lib/python3.9/site-packages/scanpy/tools/_rank_genes_groups.py:688) **kwds,
...
[220](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/istar2/lib/python3.9/site-packages/numpy/matrixlib/defmatrix.py:220) return N.dot(self, other)
File <__array_function__ internals>:180, in dot(*args, **kwargs)
ValueError: shapes (224,5090) and (224,5090) not aligned: 5090 (dim 1) != 224 (dim 0)
Minimal code sample
sc.tl.rank_genes_groups(adata_tcell, 'Enriched_Factor', method='t-test', key_added = "t-test")
sc.pl.rank_genes_groups(adata_tcell, n_genes=25, sharey=False, key = "t-test")
Error output
Versions
Based on the debug information you provided, the immediate issue is a dimension mismatch during a dot product operation when sc.tl.rank_genes_groups was called.
I recommend checking the shape of adata_tcell.X to ensure it aligns with Scanpy's expected format (cells as rows, genes as columns). Additionally, more details about how the dataset was constructed would be helpful for further diagnosis.
That's just based on my experience—hope this helps
Hi, please create a minimal reproducible example. Trying to reproduce this with one of the built-in datasets just works.
Also you didn't fill in the "Versions" field and ignored the instructions:
Paste the output of
import scanpy; scanpy.logging.print_versions()between the lines of backticks (```)
Please make up leeway.