opendvp.tl.stats_average_samples

opendvp.tl.stats_average_samples#

stats_average_samples(adata, categories)#

Average samples based on specified categories in adata.obs.

This function groups cells by unique combinations of the provided categories and computes the mean expression for each feature within each group. The result is a new, smaller AnnData object where each observation corresponds to a unique category combination.

The original, pre-averaged AnnData object is stored in the .uns attribute of the returned object under the key ‘pre_averaged_adata’.

Parameters:
  • adata (anndata.AnnData) – The annotated data matrix to be averaged.

  • categories (list of str) – A list of column names in adata.obs to group by for averaging.

Returns:

A new AnnData object where observations are the unique category combinations and variables are the averaged features.

Return type:

anndata.AnnData

Raises:

ValueError – If any of the specified categories are not in adata.obs.columns.