msmu.pp.collapse_obs
Collapse obs rows by sample_key, aggregating duplicates into one row per group.
Common use cases (with recommended agg_method):
- LFQ fractions (sample × LC fraction → sample):
agg_method="sum". Standard LFQ rollup since each fraction holds a different portion of the sample's peptides. - Technical replicates (sample × injection/process repeats → sample):
agg_method="median"or"mean". Replicates measure the same analyte, so the central tendency is the right estimate ("sum"would inflate). - Other obs-axis duplicates (plate replicates, etc.): pick
agg_methodthat matches the meaning of the duplication.
The effect on a given modality depends on its var structure:
- When
varrows are file-specific (e.g. DIA-NN psm where the var index isfilename.Precursor.Id), each(sample, var)cell still holds at most one non-NaN value, so this function only reduces the obs dimension; the actual cross-fraction precursor aggregation happens later into_peptide. - When
varrows are identity-based (e.g. DDA-LFQ peptide modality where the var index is the peptide identity), a single(sample, var)cell may collect values from multiple obs rows, andagg_methodperforms the real rollup.
Workflow contexts
- DIA-NN fractionated: read → psm/precursor →
collapse_obs→to_peptide→to_protein. - DDA-LFQ fractionated: read → psm + peptide →
collapse_obs(peptide gets real sum) →to_protein. - Any workflow with technical replicates:
collapse_obs(agg_method="median")early in the pipeline (typically before normalisation).
Applied uniformly across all modalities so the obs axis stays consistent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mdata
|
MuData
|
MuData whose obs rows contain duplicates to be collapsed. |
required |
sample_key
|
str
|
Column in |
required |
agg_method
|
Literal['sum', 'max', 'median', 'mean']
|
Aggregation across rows of the same group for each
|
'sum'
|
layer
|
str | None
|
Layer to aggregate. If None, |
None
|
log_transformed
|
bool
|
Whether the input quantification is in log2-space.
Defaults to |
False
|
Returns:
| Type | Description |
|---|---|
MuData
|
New MuData with collapsed obs. Obs columns uniform within a group retain |
MuData
|
their scalar value; non-uniform columns become lists preserving the original |
MuData
|
row order, so per-row metadata (e.g. filenames) is not lost. |
Notes
obsm/obspare not propagated through the collapse.varand modalityunsare preserved.