grassp.pp.aggregate_proteins

grassp.pp.aggregate_proteins#

aggregate_proteins(data, grouping_columns, agg_func=<function median>)[source]#

Aggregates protein intensities 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 samples into replicates.

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

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

Return type:

AnnData

Returns:

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

Notes

This function is useful for e.g. combining multiple proteins that belong to the same gene. For each protein, it groups the samples based on the provided grouping_columns and then aggregates the intensity values using the specified agg_func.

Examples

>>> import grassp as gr
>>> adata = gr.datasets.hein_2024(enrichment="raw")
>>> adata.shape
(14551, 222)
>>> aggregated = gr.pp.aggregate_proteins(
...     adata,
...     grouping_columns='Gene names'
... )
>>> aggregated.shape  # Fewer proteins after aggregation
(12617, 222)

Proteins with a missing value in grouping_columns are not merged with anything: each is kept as its own row under its original name (here the 2,371 proteins without a gene name). n_merged_proteins counts the input proteins behind each row, and adds up when an already aggregated object is aggregated again.