Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

vm.pp.flag_mad_outliers

Flag observations outside fitted median absolute deviation thresholds.

Signature

def flag_mad_outliers(
    data: anndata.AnnData | pandas.DataFrame,
    *,
    metrics: collections.abc.Mapping[str, str | collections.abc.Mapping[str, str | float]]
    | collections.abc.Sequence[str]
    | None = None,
    n_mads: float | None = None,
    transform: str | collections.abc.Mapping[str, str] | None = None,
    min_n: int = 5,
    zero_mad: str = "na",
    overwrite: bool = False,
    copy: bool = False,
    batch_key: str | None = None,
    mad_scale: str = "scaled",
    key_added: str | None = None,
) -> anndata.AnnData | pandas.DataFrame | None: ...

Parameters

NameTypeDefaultDescription
data`anndata.AnnDatapandas.DataFrame`required
metrics`collections.abc.Mapping[str, strcollections.abc.Mapping[str, strfloat]]
n_mads`floatNone`None
transform`strcollections.abc.Mapping[str, str]None`
min_nint5Minimum number of finite values required per metric and batch.
zero_madstr'na'Use missing flags (na), use the median as the threshold (zero), or raise an error (error) when the fitted MAD is zero.
overwriteboolFalseAllow replacing output columns and metadata for this run.
copyboolFalseReturn a modified AnnData copy. DataFrames always return a copy.
batch_key`strNone`None
mad_scalestr'scaled'Use scaled (1.4826 times raw MAD) or raw MAD.
key_added`strNone`None

Returns

AnnData, DataFrame, or None

With copy=True, return an annotated copy. Otherwise, annotate AnnData in place and return None; DataFrame input always returns a copy.

Raises

TypeError

If the input, metric values, or Boolean options have invalid types.

ValueError

If a setting is invalid or a transformation is outside its domain.

KeyError

If a required metric or batch column is missing.

Notes

AnnData flags are written to .obs and fitted settings and thresholds to .uns['verymad']. DataFrame metadata is stored in .attrs. Missing metric values and observations that cannot be classified remain undefined. The default policy requires total_counts and n_genes_by_counts; absent pct_counts_mt is omitted with a warning. Supplying metrics replaces the default metric set.

See Also

Examples

import verymadpy as vm

vm.pp.flag_mad_outliers(adata, batch_key="sample_id")