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

Custom QC policies

Objective: replace the built-in metric set and set metric-specific tail directions, transforms, and MAD cutoffs.

Metric columns must already exist in adata.obs or a pandas DataFrame. This example creates a proportion under an explicit name from Scanpy’s mitochondrial percentage column, then specifies the full policy. The example uses the adata created in the quick start.

import verymadpy as vm

adata.obs["mitochondrial_fraction"] = adata.obs["pct_counts_mt"] / 100.0
vm.pp.flag_mad_outliers(
    adata,
    metrics={
        "total_counts": {"tail": "both", "transform": "log1p"},
        "n_genes_by_counts": {"tail": "both", "transform": "log1p"},
        "mitochondrial_fraction": {
            "tail": "upper",
            "transform": "none",
            "n_mads": 3,
        },
    },
    n_mads=4,
    batch_key="sample_id",
    mad_scale="scaled",
    key_added="custom_qc",
)
custom_table = vm.pp.summarize_mad(adata, key_added="custom_qc", include_combined=True)

Passing metrics replaces the default metric set. Global values apply where a metric does not specify its own value; a per-metric setting takes precedence. Supported tails are lower, upper, and both; supported transformations are none, log1p, and log10. log1p requires nonnegative values and log10 requires positive values. veryMADpy does not infer percentage units or clip boundaries.

The default convention uses scaled MAD, 1.4826 × raw_MAD. Three scaled MADs correspond to about 4.4478 raw MADs; five raw MADs correspond to about 3.3725 scaled MADs. Use flag_mad_outliers for all settings and precedence rules.