scverse / scverse/scanpy

Error when running sc.tl.rank_genes_groups

Open
#3,671 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Please make sure these conditions are met
  • I have checked that this issue has not already been reported.
  • 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

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

Start in scanpy/tools/_rank_genes_groups.py around rank_genes_groups and its compute_statistics call, then reproduce the minimal sc.tl.rank_genes_groups example. The report does not include versions or a reproducible dataset, so first determine whether the shape mismatch can be reproduced; done means identifying the cause and confirming the call no longer raises the reported ValueError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
bioinformatics
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.