mantispy.pp.calculate_qc_metrics#
- mantispy.pp.calculate_qc_metrics(adata, image_shape=None, border_margin=10, max_nan_fraction=0.5, area_feature=None, qc_metrics=('nan', 'border', 'area_outlier'), copy=False)[source]#
Compute per-cell and per-feature QC metrics.
- Parameters:
- adata
AnnData Object to annotate.
- image_shape
tuple[int,int] |None(default:None) (height, width)of a field of view. Without it, and withoutMetadata_Center_X/_Yinobs, the border flag staysFalse.- border_margin
int(default:10) Distance from the image edge, in pixels, inside which a cell is a border cell.
- max_nan_fraction
float(default:0.5) Largest fraction of missing features a cell may have before it is flagged. Partial NaN is routine in CellProfiler output (Zernike and RadialDistribution features are undefined for small objects), so requiring no missing values would flag almost every cell.
- area_feature
str|None(default:None) The
varname of the area measurement to score for outliers. By default the columns whose parsedfeatureisAreaare used; pass this for a table whose names do not parse (mt.io.stampcould not fillvar["feature"]).- qc_metrics
Sequence[str] (default:('nan', 'border', 'area_outlier')) Metrics to compute.
"nan"writesobs["qc_n_nan_features"],obs["qc_nan_fraction"]andvar["qc_n_nan"];"border"writesobs["qc_is_border"];"area_outlier"writesobs["qc_area_outlier"];"variance"and"n_unique"writevar["qc_variance"]andvar["qc_n_unique"]. The per-feature"variance"and"n_unique"are left out by default:filter_cells()reads neither, and"n_unique"sorts every feature, which dominates the runtime on large single-cell objects.- copy
bool(default:False) Return a modified copy instead of mutating in place.
- adata
- Return type:
- Returns:
None, or the modified copy. Writes the columns of each metric inqc_metrics, andobs["qc_fail"]. Everyqc_*boolean isTruefor a problem, matching the ecosystem convention;qc_failis the union of the computed flags and of a missing fraction abovemax_nan_fraction, and is the flagfilter_cells()reads. When no area column is found andarea_featureis not given,qc_area_outlieris skipped (left allFalse) with a warning and the other metrics are still computed.- Raises:
KeyError –
area_featureis given but is not avarname.ValueError –
qc_metricsnames an unknown metric.