Skip to content

scdef.tl.filter

filter(model: scDEF, batch_key: Optional[str] = None, diagnostics_kwargs: Optional[Mapping[str, Any]] = None, **filter_kwargs: Any) -> None

Filter factors and refresh the diagnostics and signatures in one step.

model.filter_factors renames factors, which invalidates everything keyed by those names — the stored signatures, the hierarchies, and the frozen upper-layer subset used by factor_diagnostics. Calling the two separately leaves the model in that in-between state, where scd.pl.make_graph(show_signatures=True) raises until diagnostics are re-run. This wrapper does both, so the model is immediately usable::

scd.tl.filter(model, batch_key="Experiment", brd_min=1.0)

Equivalent to::

model.filter_factors(brd_min=1.0)
scd.tl.factor_diagnostics(model, batch_key="Experiment")

Parameters:

Name Type Description Default
model scDEF

scDEF model instance.

required
batch_key Optional[str]

passed to factor_diagnostics, which computes the batch metrics (batch_purity, frac_dom_batch, batch_split_corr). Defaults to the model's own batch_key when it has one, so a batch-aware model does not need it restated here. It plays no part in the filtering itself.

None
diagnostics_kwargs Optional[Mapping[str, Any]]

optional extra keyword arguments for factor_diagnostics (e.g. {"mc_samples": 200}).

None
**filter_kwargs Any

forwarded to filter_factors (brd_min, ard_min, n_eff_parents_max, keep, ...).

{}
Example

scdef.tl.filter(model, batch_key="Experiment", brd_min=1.0) scdef.pl.make_graph(model, show_signatures=True) # works right away