Unable to subset cells from backed anndata object after preprocessing

オープン
#512 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
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. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

scverse/SnapATAC2 のほかの issue

scverse/SnapATAC2 の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。