Subsetted adata object not behaving as expected
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.
Hello, I am working with an adata object (adata.shape produces (8648, 18074)) that I have subset to only include 990 genes of interest (and only include cells that express my genes of interest), with the hopes of clustering cells based on expression of my genes of interest (I got this idea from issue #510). After I subset my adata object, I confirmed that the shape of adata_sub is as expected (adata_sub.shape produces (6603, 990)). However, after running a new embedding and clustering on adata_sub, I have noticed that I can plot genes that shouldn't be in adata_sub (but were in adata), and that when I run sc.tl.rank_genes_groups my results aren't restricted to my 990 genes of interest. I am guessing that I subsetted my data incorrectly (though, why would I have the correct shape?).
Minimal code sample (that we can copy&paste without having any data)
# subset adata to genes of interest
adata_sub = adata[:, [g in genes_list for g in adata.var_names]].copy()
# filter out cells that don't express any genes of interest
sc.pp.filter_cells(adata_sub, min_genes=1)
# run new embedding and clustering
sc.pp.pca(adata_sub, n_comps=50, use_highly_variable=False, svd_solver='arpack')
sc.pp.neighbors(adata_sub)
sc.tl.umap(adata_sub)
sc.tl.leiden(adata_sub, key_added='leiden_sub')
When I use sc.pl.umap(adata_sub) to plot expression of a gene that is not one of my genes of interest, it is still plotted (I would expect an error telling me that the gene is not found in my adata_sub object). Similarly, the results of sc.tl.rank_genes_groups(adata_sub, groupby='leiden_sub', key_added='rank_genes_sub', method='wilcoxon') returns top ranked genes that are not (or should not be) in my adata_sub object.
Thank you for any help/clarification as to what's going on!
Versions
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Run the minimal Python example using adata_sub, sc.pl.umap, and sc.tl.rank_genes_groups, then inspect whether the subset's gene names and expression data remain restricted to the 990 selected genes. Trace how these entry points resolve genes and rank results; done means identifying the cause and adding or documenting behavior that prevents genes outside the subset from appearing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data, data-visualization, machine-learning
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100