Unable to subset cells from backed anndata object after preprocessing

未关闭
#512 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
35/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
活跃
技术栈
python
领域
data

调研方向

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,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

scverse/SnapATAC2 的其他 Issue

查看 scverse/SnapATAC2 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。