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 ton_cellsobservations by sampling integer positional indices fromadata.obsfirst and then slicingadata, 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 inadata.obsrepresenting the condition or cell type label.label_values (
Sequence[str] |None(default:None)) – Optional sequence of label values inadata.obs[label_key]to include. If None, all non-empty groups inadata.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:
- Returns:
A dictionary mapping condition label to subsampled AnnData with at most
n_cellsobservations.- Raises:
KeyError – If
label_keyis not found inadata.obs.ValueError – If
n_cells<= 0.