grassp.pp.aggregate_samples

grassp.pp.aggregate_samples#

aggregate_samples(data, grouping_columns, agg_func=<function median>, keep_raw=False)[source]#

Aggregates sample expression across samples using a given function.

Parameters:
data AnnData

The annotated data matrix with proteins as observations (rows).

grouping_columns Union[str, List[str]]

Column name(s) in data.obs to group proteins.

agg_func Callable[[ndarray, Optional[int]], ndarray] (default: <function median at 0x11512c2b0>)

Function to use for aggregation. Defaults to np.median.

keep_raw bool (default: False)

Whether to keep the raw data in the returned AnnData object.

Return type:

AnnData

Returns:

A new AnnData object with aggregated expression values. The number of observations (proteins) remains the same, but the number of variables (samples) will correspond to the number of unique groups defined by grouping_columns.

Notes

This function is useful for combining replicates or creating an averaged profile across conditions. For each sample, it groups the samples based on the provided grouping_columns and then aggregates the expression values using the specified agg_func.