Unable to subset cells from backed anndata object after preprocessing
还没有人认领这个 Issue。
评估
调研方向
Start by tracing the backed AnnData subsetting path used by subset(selected_cells) and compare it with filter_cells() after preprocessing. Reproduce the length mismatch with the 8,212-cell example, then determine which preprocessing data structures need updating or invalidating for arbitrary metadata or barcode filters. Done means supported backed-mode subsetting works after preprocessing and has regression coverage.
由索引模型根据 Issue 内容生成。
描述
Hi,
I am unable to subset cells in a fully preprocessed backed AnnData object using arbitrary filtering conditions.
So far, filtering based on the number of fragments (n_fragment) and/or the transcription start site enrichment score (tsse) using filter_cells() function seems to be the only reliable way to remove cells.
I have tried using the internal subset(selected_cells) function, but it fails once the AnnData object has been fully preprocessed. I have not yet identified the exact preprocessing step that causes this behavior. However, subsetting works right after applying filter_cells() and stops working at some point afterward.
Example
My AnnData object has the following structure:
AnnData object with n_obs × n_vars = 8212 × 6062095
backed at 'atac_1245.h5ad'
obs: 'n_fragment', 'frac_dup', 'frac_mito', 'tsse',
'doublet_probability', 'doublet_score'
var: 'count', 'selected'
uns: 'library_tsse', 'n_obs_before_filtering',
'frac_overlap_TSS', 'n_obs_after_filtering',
'reference_sequences', 'doublet_rate',
'scrublet_sim_doublet_score', 'TSS_profile',
'frag_size_distr'
obsm: 'fragment_paired'
When I try to subset the object using a Boolean pandas.Series of length 8212, I get the following error:
adata.subset(selected_cells)
RuntimeError: lengths don't match: could not create a new DataFrame:
height of column 'n_fragment' (8212) does not match
DataFrame height (8132)
The Boolean mask has the same length as the original AnnData object (8212 cells).
Expected behavior
I would expect to be able to subset cells based on arbitrary metadata columns or lists of cell barcodes, similar to how subsetting works with a standard AnnData object.
For example, filtering by a Boolean column in adata.obs:
adata = adata[adata.obs["condition"]]
Or selecting specific cells by barcode:
adata = adata[list_of_cell_barcodes, :]
Ideally, this functionality would remain available after preprocessing, without requiring the entire analysis to be rerun.
Why this matters
This limitation makes it difficult to remove cells based on criteria discovered during downstream analysis, such as identifying an unexpected cluster that needs to be excluded.
Reprocessing the entire dataset from import_fragments() is time-consuming. Being able to subset cells after preprocessing would make it much easier to refine cell selection without repeating computationally expensive steps.
I understand that some preprocessing results or derived data structures might need to be updated or discarded when cells are removed. However, even if subsetting invalidates certain intermediate results, it would be useful to have a supported way to filter cells without restarting the entire workflow.
Questions
- Is arbitrary cell subsetting after preprocessing currently supported?
- If so, is there a recommended way to subset cells based on metadata or cell barcodes?
- If not, could support for this functionality be considered, even if some derived data structures need to be discarded or recomputed?
- Could this be backed-mode specific ?
Thank you for your work on SnapATAC2!
- 主要语言
- Python
- 星标
- 331
- 派生
- 44
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
scverse/SnapATAC2 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 48/100
-
难度 3/5 1-2 天 新手友好度 45/100
-
难度 4/5 3-5 天 新手友好度 22/100
-
难度 2/5 1-3 小时 新手友好度 48/100
-
Make igraph optional可能重新可做 @kaizhang 于 65 天前认领,目前没有进行中的 PR。 未关闭
查看 scverse/SnapATAC2 的全部 Issue
相似的 Issue
-
area/network kind/documentation triage/needs-human
难度 1/5 1-3 小时 新手友好度 88/100
canonical/k8s-snap#3533 · 1 条评论 ·
维护者通常 1 天内回复
-
area: ops bug effort: small
难度 1/5 1 小时以内 新手友好度 91/100
juandresrodca/AdminForge#71 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
fossasia/eventyay-exhibition#465 · 3 条评论 · 1 个 reaction ·
维护者通常 3 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
Deltakit/deltakit-circuit#28 ·
-
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复