Skip to content

scdef.tl.get_obs_score_rankings

get_obs_score_rankings(model: scDEF, layer: Union[int, str], obs_key: str, obs_values: Union[str, Sequence[str]], mode: Literal['f1', 'fracs', 'weights', 'prob', 'soft_prec', 'score'] = 'fracs', ascending: bool = False, recompute: bool = False) -> DataFrame

Return per-obs-value factor rankings by observation association score.

This reads cached matrices from model.adata.uns['obs_scores'] (written by scd.pl.obs_scores). If cache is missing/stale for the requested key/model, it is recomputed on demand for the requested obs_key and mode.

Parameters:

Name Type Description Default
model scDEF

fitted scDEF model.

required
layer Union[int, str]

layer to rank factors in, as an index or a name from model.layer_names.

required
obs_key str

column in model.adata.obs holding the annotation to score against.

required
obs_values Union[str, Sequence[str]]

one or more values of obs_key to rank factors for. A single string is treated as a one-element list.

required
mode Literal['f1', 'fracs', 'weights', 'prob', 'soft_prec', 'score']

which association score to rank by — "fracs" (fraction of the annotation's cells assigned to the factor), "f1" (F1 of the assignment), "weights", "prob", "soft_prec", or "score" (mean factor score).

'fracs'
ascending bool

if True, rank from lowest score to highest. Ranking is always grouped by obs_values in the order given, and sorted by score within each group.

False
recompute bool

force the score matrix to be recomputed even when a cache entry for this obs_key and mode matches the current fit.

False

Returns:

Type Description
DataFrame

One row per (obs_value, factor) with columns factor, layer,

DataFrame

layer_idx, obs_key, obs_value, mode and score.