Skip to content

Readers and estimators

Readers

from_anndata

from_anndata(
    adata,
    *,
    layer: str | None = None,
    missing_value: float | str = "nan",
    obs_levels: list[str] | None = None,
    var_index: str | None = None,
    transpose: bool = True,
) -> pd.DataFrame

Convert an AnnData object to the features x samples DataFrame mismap-qc expects.

AnnData stores data as obs (rows, typically samples or cells) x var (columns, typically features). mismap-qc wants the inverse. With transpose=True (the default), the output is features x samples.

Parameters:

Name Type Description Default
adata AnnData

Input. Requires anndata to be installed (pip install mismap-qc[anndata]).

required
layer str

Layer name to use. None => adata.X.

None
missing_value float or str

How to treat missing values: - "nan" (default): keep NaN as missing. - "zero": treat exact zeros as missing. - float: treat values below this threshold as missing (useful for log-intensity matrices with a noise floor).

'nan'
obs_levels list of str

obs columns to use as additional MultiIndex levels on the sample axis. Example: obs_levels=["batch", "condition"] produces a 3-level MultiIndex with levels [batch, condition, sample].

None
var_index str

var column to use as feature names. None => adata.var_names.

None
transpose bool

If True (default), output is features x samples. Set False if your AnnData is already in features x samples orientation (rare).

True

Returns:

Type Description
DataFrame

features (rows) x samples (columns). When obs_levels is set, columns are a MultiIndex with the obs levels and the sample name as the innermost level.

Raises:

Type Description
ImportError

If anndata is not installed.

ValueError

If layer, obs_levels, var_index, or missing_value is invalid.

Examples:

>>> df = from_anndata(adata)
>>> df = from_anndata(adata, obs_levels=["Batch", "Condition"])
>>> df = from_anndata(adata, missing_value=0.0, var_index="gene_symbol")

Estimators

estimate_lod

estimate_lod(
    df: DataFrame,
    *,
    method: str = "min",
    quantile: float = 0.05,
    min_present: int = 3,
) -> pd.Series

Estimate a per-feature limit of detection from observed values.

For each feature, returns either the minimum observed value (method="min") or a low-quantile observed value (method="quantile"). Features with fewer than min_present observations return NaN (cannot estimate).

Parameters:

Name Type Description Default
df DataFrame

features (rows) x samples (columns). NaN = missing.

required
method str

"min" (default) or "quantile".

'min'
quantile float

Quantile in [0, 1] used when method="quantile". Default 0.05.

0.05
min_present int

Minimum non-NaN observations required to estimate. Features below this threshold return NaN.

3

Returns:

Type Description
Series

Per-feature LOD estimate, indexed by feature name.

Raises:

Type Description
ValueError

If method is not one of {"min", "quantile"} or quantile is outside [0, 1].

Examples:

>>> lod = estimate_lod(df)
>>> lod = estimate_lod(df, method="quantile", quantile=0.1)