mantispy.pp.downsample#

mantispy.pp.downsample(adata, n_per_group=500, by=('Metadata_Plate', 'Metadata_Well'), stratify=None, seed=0)[source]#

Return at most n_per_group rows from each group.

Parameters:
adata AnnData

Object to sample from. Never modified.

n_per_group int (default: 500)

Cap per group. Groups smaller than this are kept whole, so groups are capped but not balanced.

by Sequence[str] | str | None (default: ('Metadata_Plate', 'Metadata_Well'))

Columns defining a group. The default caps each well, so every well is represented instead of the densest wells filling the sample.

stratify str | None (default: None)

Keep this column’s proportions inside each group, so a rare perturbation is not lost to the sampling.

seed int (default: 0)

Seed for reproducibility.

Return type:

AnnData

Returns:

A new object holding the sampled rows in their original order, with the call recorded in uns["mantispy"]["params"].

Raises:

ValueError – If n_per_group is below 1.