Skip to content

msmu.pp.calculate_missingness

Count missing values per feature and record the counts in .var (and on the decoys).

Writes .var["n_missing"], the number of samples without a value for the feature, and .var["missing_ratio"], that count divided by the number of samples. With group_obs, an .obs column of the modality, .var["missing_ratio_<level>"] is added for every level present, so a filter can be set within one group. Existing columns are overwritten: recompute after removing samples, because apply_filter does not update them.

Decoys have identifications but no quantification, so a missingness filter has nothing to judge them on. They receive the same columns with 0 / 0.0, which the usual "missing at most" filters (le/lt) keep; a filter in the other direction (ge/gt on missingness) would drop every decoy.

Parameters:

Name Type Description Default
mdata MuData

MuData with the modality to annotate; a copy is returned.

required
modality str

Modality whose .X is counted along the sample axis.

required
group_obs str | None

Optional .obs column of the modality. One missing_ratio_<level> column is written per level present; samples with a missing label contribute only to the overall columns, with a warning.

None

Returns:

Type Description
MuData

A copy of mdata with the columns added to .var and to .uns["decoy"] when present.

Examples:

import msmu as mm
mdata = mm.pp.calculate_missingness(mdata, modality="protein", group_obs="condition")
mdata = mm.pp.add_filter(mdata, modality="protein", column="missing_ratio", keep="lt", value=0.5)
mdata = mm.pp.apply_filter(mdata, modality="protein")