scanpy.pp.downsample_counts

scanpy.pp.downsample_counts(adata, counts_per_cell=None, total_counts=None, random_state=0, replace=False, copy=False)

Downsample counts from count matrix.

If counts_per_cell is specified, each cell will downsampled. If total_counts is specified, expression matrix will be downsampled to contain at most total_counts.

Parameters
adata : AnnDataAnnData

Annotated data matrix.

counts_per_cell : int, Collection[int], NoneUnion[int, Collection[int], None]

Target total counts per cell. If a cell has more than ‘counts_per_cell’, it will be downsampled to this number. Resulting counts can be specified on a per cell basis by passing an array.Should be an integer or integer ndarray with same length as number of obs.

total_counts : int, NoneOptional[int]

Target total counts. If the count matrix has more than total_counts it will be downsampled to have this number.

random_state : int, RandomState, NoneUnion[int, RandomState, None]

Random seed for subsampling.

replace : boolbool

Whether to sample the counts with replacement.

copy : boolbool

If an AnnData is passed, determines whether a copy is returned.

Return type

AnnData, NoneOptional[AnnData]

Returns

Depending on copy returns or updates an adata with downsampled .X.