scverse / scverse/scanpy

rank_genes_groups "groups" argument ignored or not clearly explained

Open
#1,519 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

  • 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 master branch of scanpy.

Hi,

My understanding of the "groups" argument in sc.tl.rank_genes_groups is that it subsets the data and then performs the differential expression testing. I.e. if I have clusters 1 to 10, and I set groups=[1,2], the output will give me the genes differentially expressed in cluster 1 as compared to cluster 2 (and 2 vs 1).
However, the current function still compares to all other clusters (see below).
Is that the intention? If so, we should update the readthedocs I think.
If this is a bug, let's try to fix it :) I can take a look myself in that case. Just wanted to check if I misinterpreted the readthedocs.

Minimal code sample (that we can copy&paste without having any data)
import scanpy as sc

# load data
adata = sc.datasets.pbmc68k_reduced()
# cluster
sc.tl.leiden(adata, key_added="clusters", resolution=0.5)
print("Clusters:", sorted(set(adata.obs["clusters"])))
# do test with groups="all"
sc.tl.rank_genes_groups(adata, groupby="clusters", groups="all")
# store results, sorting genes by logfc
genes_cluster_0_vs_all = [
    (name, logfc)
    for logfc, name in sorted(
        zip(
            adata.uns["rank_genes_groups"]["logfoldchanges"]["0"],
            adata.uns["rank_genes_groups"]["names"]["0"],
        ),
        reverse=True,
    )
]
# do test with groups=["0","1"], i.e. only a subset of the clusters
sc.tl.rank_genes_groups(adata, groupby="clusters", groups=["0", "1"])
# store result
genes_cluster_0_vs_1 = [
    (name, logfc)
    for logfc, name in sorted(
        zip(
            adata.uns["rank_genes_groups"]["logfoldchanges"]["0"],
            adata.uns["rank_genes_groups"]["names"]["0"],
        ),
        reverse=True,
    )
]
# print top 5 genes and logfcs for both,
# they're the same and should not be
print("Top genes cluster 0 versus all:\n", genes_cluster_0_vs_all[:5])
print("Top genes cluster 0 versus cluster 1:\n", genes_cluster_0_vs_1[:5])
Clusters: ['0', '1', '2', '3', '4', '5', '6', '7', '8']
WARNING: Default of the method has been changed to 't-test' from 't-test_overestim_var'
WARNING: Default of the method has been changed to 't-test' from 't-test_overestim_var'
Top genes cluster 0 versus all:
 [('LYPD2', 29.707254), ('C1QA', 7.7860994), ('FCGR3A', 7.2558727), ('HES4', 7.201066), ('C1QB', 6.6123295)]
Top genes cluster 0 versus cluster 1:
 [('LYPD2', 29.707254), ('C1QA', 7.7860994), ('FCGR3A', 7.2558727), ('HES4', 7.201066), ('C1QB', 6.6123295)]```


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 at sc.tl.rank_genes_groups and its ReadTheDocs description, then run the minimal pbmc68k_reduced example comparing groups="all" with groups=["0","1"]. Resolve whether groups should restrict the comparison or be documented as selection only; done when the implementation and documentation agree.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
bioinformatics, data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.