MAD-based QC
veryMADpy applies established median absolute deviation (MAD) thresholds to observation-level QC metrics. A flag indicates a statistical outlier under the selected policy; it is not a biological annotation or an automatic decision to remove a cell.
Estimation and thresholds
For valid transformed metric values (z_1, \ldots, z_n), veryMADpy estimates the median (m) and raw MAD:
[ m = \operatorname{median}(z_i), \qquad \mathrm{MAD}_{\mathrm{raw}} = \operatorname{median}(|z_i - m|). ]
By default, it uses the normal-consistent scaled MAD:
[ \mathrm{MAD}{\mathrm{scaled}} = 1.4826,\mathrm{MAD}{\mathrm{raw}}. ]
For n_mads = k, the lower and upper limits are (m-k,\mathrm{MAD}) and (m+k,\mathrm{MAD}). Raw and scaled MAD are distinct units: three scaled MADs are approximately 4.4478 raw MADs; five raw MADs are approximately 3.3725 scaled MADs.
Built-in policy
When metrics=None, veryMADpy uses the standard Scanpy metric columns below. The default is an opinionated starting policy, not a universal recommendation.
| Metric | Transformation | Tail | Default cutoff |
|---|---|---|---|
total_counts | log1p | lower and upper | 4 scaled MADs |
n_genes_by_counts | log1p | lower and upper | 4 scaled MADs |
pct_counts_mt | none | upper | 4 scaled MADs |
The library-size and detected-gene columns are required by the default policy. If pct_counts_mt is absent, veryMADpy warns and fits the two count metrics. Other percentage metrics are not included automatically. Supplying metrics replaces the default metric set. See Custom QC policies for metric-specific overrides.
Tail direction and transformation
The lower tail flags values below the lower threshold; upper flags values above the upper threshold; both applies both checks. none, log1p, and log10 are supported. Transformations are applied to the metric before fitting and flagging. Threshold metadata retains the fitted and inverse-transformed values for plotting and inspection.
Pooled and sample-wise fits
Without batch_key, a single threshold is fitted across all observations. With batch_key, medians, MADs, and cutoffs are estimated independently for each observed batch and applied only to that batch. veryMADpy does not silently fall back to pooled thresholds for small or degenerate groups. Sample-wise fitting can reduce shifts caused by technical differences, but it can also change which observations are flagged when distributions differ biologically.
Missing and undefined classifications
NaN metric values do not contribute to estimation and remain undefined when that metric cannot classify the observation. Infinite metric values are rejected. A batch label that is missing has no fitted batch threshold. Groups with fewer than min_n valid values (five by default), all-missing metrics, and zero-MAD distributions are diagnosed and remain undefined under the default zero_mad="na" policy. zero_mad="zero" instead uses the median as the cutoff; zero_mad="error" raises.
Metric flags use nullable Boolean values. The combined result follows three-valued OR logic: a true metric flag makes the combined result true; it is false only when all metrics are defined and false; otherwise it remains undefined. Filtering raises on undefined classifications by default. Choose na_policy="keep" or "drop" explicitly after review.
Interpretation and limits
QC distributions can reflect both technical quality and genuine cell-state differences. Rare populations, large cells, or transcriptionally active cells may be flagged under a chosen policy. Inspect distributions, threshold summaries, and per-sample outcomes before filtering; use dataset-specific absolute rules where scientifically justified. MAD-based detection is a familiar robust univariate method, not a biological classifier.