subsample

Contents

subsample#

alphagenome.models.v2.gene_counts_condition.subsample(adata, n_cells, label_key, label_values=None, seed=None, copy=True)[source]#

Subsamples an AnnData object into a mapping of condition label to AnnData.

For each label in adata.obs[label_key], extracts up to n_cells observations by sampling integer positional indices from adata.obs first and then slicing adata, avoiding unnecessary copies or densification of .X.

Parameters:
  • adata (AnnData) – Input single-cell AnnData object.

  • n_cells (int) – Maximum number of cells to sample per label.

  • label_key (str) – Column name in adata.obs representing the condition or cell type label.

  • label_values (Sequence[str] | None (default: None)) – Optional sequence of label values in adata.obs[label_key] to include. If None, all non-empty groups in adata.obs[label_key] are included.

  • seed (int | None (default: None)) – Optional random seed for reproducible subsampling.

  • copy (bool (default: True)) – Whether to return a copy of each subsetted AnnData slice.

Return type:

dict[str, AnnData]

Returns:

A dictionary mapping condition label to subsampled AnnData with at most n_cells observations.

Raises: