.calculate_cv
- proteopy.pp.calculate_cv(adata, group_by=None, layer=None, zero_to_na=True, min_samples=2, force=False, key_added=None, inplace=True)[source]
Compute the coefficient of variation (CV = std / mean) for each variable.
Performed within
group_bygroups optionally. CV is calculated ignoring NaNs.- Parameters:
adata (AnnData) –
AnnDataobject containing data.group_by (str or None, optional) – Column in
adata.obsdefining groups. If None, computes CV across all samples without grouping.layer (str or None, optional) – Layer to use for data. If None, uses
adata.X.zero_to_na (bool, optional) – Treat zeros as missing values (NaN).
min_samples (int, optional) – Minimum number of non-NaN samples (obs) required to compute a CV.
force (bool, optional) – If True, bypass the log-transform check. Use when you are certain the data is on the appropriate scale for CV calculation.
key_added (str or None, optional) – Key under which to store results. When
group_byis provided, defaults to'cv_by_<group_by>_<layer>'and stores inadata.varm. Whengroup_byis None, defaults to'cv_<layer>'and stores inadata.var.inplace (bool, optional) – If True, modify
adatain place. If False, return a copy ofadatawith the added key.
- Returns:
Returns the modified AnnData object if
inplace=False, otherwise returns None.- Return type:
AnnData or None
- Raises:
ValueError – If the data appears to be log-transformed. CVs should be computed on raw (linear-scale) data.
KeyError – If
group_byis provided but does not exist inadata.obs.