Skip to content

scdef.iscDEF

iscDEF(adata: AnnData, markers_dict: Mapping[str, Sequence[str]], add_other: Optional[int] = 0, markers_layer: Optional[int] = 0, add_root: Optional[bool] = None, cn_small_mean: Optional[float] = 1.0, cn_big_mean: Optional[float] = 10.0, cn_small_strength: Optional[float] = 0.1, cn_big_strength: Optional[float] = 1.0, gs_small_scale: Optional[float] = 1.0, gs_big_scale: Optional[float] = 10.0, marker_strength: Optional[float] = 1.0, nonmarker_strength: Optional[float] = 0.1, other_strength: Optional[float] = 0.1, penalize_other: Optional[bool] = True, **kwargs: Any)

Bases: scDEF

Informed Single-cell Deep Exponential Families (iscDEF) model.

iscDEF extends scDEF with marker gene sets that shape the layer-0 loading prior W. Each typed factor is encouraged to use its own marker genes, may load other genes more weakly, and can share biology with add_other residual factors.

Tuning how much the model relies on markers vs. augments signatures

Marker reliance is controlled mainly by the Gamma prior on W at the markers layer (for markers_layer=0, that is L0). For a typed factor, each listed marker gene has prior mean loading ≈ gs_big_scale (tighter when marker_strength is high); all other genes default to ≈ gs_small_scale. Fitted signatures can still add genes beyond your list if the data and these priors allow it.

  • Stay close to the input marker lists (typing, strict gene programs): increase gs_big_scale and marker_strength; keep the default penalize_other=True so off-type markers are discouraged on the wrong factor; keep add_other small when you only have a few types to avoid ignoring the marker factors.

  • Augment markers with data-driven genes: decrease gs_big_scale and marker_strength; increase gs_small_scale or nonmarker_strength so non-marker genes are not overly suppressed on typed factors; use add_other ≥ 1 for programs not in markers_dict; set penalize_other=False if overlapping lists should not hard-reject shared genes.

List design matters as much as numeric knobs: non-overlapping marker sets per type separate factors more reliably than tuning alone. Use markers_layer=0 for one factor per type; use markers_layer>0 for coarse types at the top and finer substructure at L0.

Parameters:

Name Type Description Default
adata AnnData

AnnData object containing the gene expression count matrix. Counts must be present in either adata.X or a specified layer.

required
markers_dict Mapping[str, Sequence[str]]

dictionary mapping marker/factor names to gene lists (gene sets). These guide the formation of factors in the chosen layer.

required
add_other Optional[int]

if > 0, adds one or more other{i} residual categories. At markers_layer=0, each is a separate L0 factor. At markers_layer>0, each gets a block of L0 sub-factors (add_other * n_factors_per_marker columns at L0) and one coarse factor at the marker layer.

0
markers_layer Optional[int]

index of the layer at which gene sets are enforced as factors (0 = lowest/finest, higher = top layer). If > 0, total layers determined by this value.

0
add_root Optional[bool]

when markers_layer > 0 (default True), append a width-1 root above the marker layer. Fitting runs in two phases (main fit with frozen root, then root_epochs on the root only); see fit. Ignored when markers_layer=0.

None
cn_small_mean Optional[float]

mean prior connectivity for "small" (weakly-connected) genes between factors and gene sets.

1.0
cn_big_mean Optional[float]

mean prior connectivity for "big" (strongly-connected) genes between factors and gene sets.

10.0
cn_small_strength Optional[float]

concentration parameter for low connectivity (see scDEF prior specification).

0.1
cn_big_strength Optional[float]

concentration parameter for high connectivity.

1.0
gs_small_scale Optional[float]

prior mean scale for genes not in a factor's marker list (higher → more non-marker loading).

1.0
gs_big_scale Optional[float]

prior mean scale for genes in that factor's marker list (higher → stronger marker reliance).

10.0
marker_strength Optional[float]

Gamma prior concentration on marker-gene loadings (higher → less augmentation away from markers).

1.0
nonmarker_strength Optional[float]

prior concentration on non-marker loadings (higher → tighter; overridden to 1.0 if use_brd).

0.1
other_strength Optional[float]

prior concentration when penalizing marker genes on the wrong factor or on other rows.

0.1
penalize_other Optional[bool]

if True (default), typed factors penalize other groups' marker genes; other factors penalize all typed markers.

True
**kwargs Any

additional arguments passed to scDEF. hierarchy_weight defaults to 0.25 (scales coverage-derived alpha when set_alpha_from_cov=True).

{}

Methods:

Name Description
filter_factors

Filter factors while preserving existing marker-based factor names.

fit

Fit iscDEF, warm-starting from previous fit when available.

filter_factors

filter_factors(brd_min: Optional[float] = 1.0, ard_min: Optional[float] = 0.001, clarity_min: Optional[float] = 0.5, n_eff_parents_max: float = 1.5, brd_exceptional: Optional[float] = None, local_l0_scores: bool = False, batch_purity_max: Optional[float] = None, batch_purity_soft_max: Optional[float] = None, min_cells_upper: Optional[float] = 0.001, min_cells_lower: Optional[float] = 0.0, filter_up: Optional[bool] = True, annotate: Optional[bool] = True, upper_only: Optional[bool] = False, keep: Optional[Sequence[str]] = None)

Filter factors while preserving existing marker-based factor names.

This override keeps the base filtering behavior but restores names by subsetting the previous factor_names. This avoids marker-prefix relabeling across filter/refit workflows.

fit

fit(nmf_init: bool = False, max_cells_init: int = 1024, z_init_concentration: float = 10.0, z_init_from_score_genes: bool = True, z_init_score_temperature: float = 1.0, z_init_other_mass: Optional[float] = None, z_init_other_mode: str = 'inverse_union', score_genes_layer: Optional[str] = None, score_genes_kwargs: Optional[Dict[str, Any]] = None, root_epochs: int = 0, **kwargs)

Fit iscDEF, warm-starting from previous fit when available.

On refit, all layers are initialized from the previous posterior means (z and W), while BRD/ARD are initialized from layer 0. Existing marker-aware names are preserved through the refit path.

On the first fit, z can be initialized from Scanpy score_genes on typed marker sets. For markers_layer == 0 only layer 0 is set this way. For markers_layer > 0, every layer uses the same score softmax among typed markers, replicated uniformly within each marker block at that layer (and uniform other blocks when add_other is used). With z_init_other_mass=None (default), the fraction of mass on other columns at each layer equals the number of other factors at that layer divided by that layer width. With z_init_other_mode='inverse_union' (default), per-cell other init is scaled by 1 / (1 + union_marker_score) from score_genes on the union of typed marker genes; use z_init_other_mode='uniform' for constant other init. nmf_init is not used by iscDEF.

When add_root=True (markers_layer > 0 only), a width-1 root is appended and fitting runs in two phases: all layers except the root, then root_epochs on the root only (default 10 when add_root and root_epochs is 0).