Skip to content

msmu.pp.apply_sdrf_to_obs

Project columns of the attached SDRF (.uns["sdrf"]) onto each modality's .obs.

The SDRF spans both axes, so it is reduced to the .obs axis by the match key on and only columns that are a function of that key (one value per key group) are projected. Columns that vary within a key (e.g., comment[fraction identifier] under a channel key) cannot be represented on the .obs axis; they are left untouched in .uns["sdrf"] and skipped with a DEBUG message -- or, if named explicitly in columns, raise. .obs never silently collapses SDRF data.

By default the observations are also reordered to follow the SDRF rows, so an order written into the SDRF (plate wells, acquisition sequence) carries into .obs and into the category order every plot derives from it. Readers order .obs by file name or quant-table column.

Parameters:

Name Type Description Default
mdata MuData

MuData with an SDRF attached via attach_sdrf.

required
on str | Sequence[str] | None

SDRF column (or list of columns) matched against .obs.index. Default None auto-picks: after split_tmt (which records its set_key in .uns) it builds the composite [comment[label], set_key] matching the channel_set .obs automatically; otherwise comment[label] for TMT and comment[data file] elsewhere. Pass a str or list to override (a list forces a "_"-joined composite key).

None
columns str | Sequence[str] | None

SDRF column(s) to project. Default None projects every projectable column; naming a non-projectable column raises instead of skipping it.

None
set_index str | None

After projection, replace .obs.index with this SDRF column's values. Must be projectable and unique across .obs. Default None keeps the index.

None
order_obs bool

Reorder every modality's .obs, and the global .obs, to the SDRF row order: each observation takes the position of the first SDRF row carrying its match key, and observations absent from the SDRF follow the matched ones in their current order (none is dropped; removing samples stays with apply_filter). Default True; False keeps the reader's order.

True

Returns:

Type Description
MuData

A copy of mdata with projected SDRF columns merged into each modality's .obs and, by

MuData

default, .obs in SDRF row order; .uns["sdrf"] is left unchanged as the source of truth.