scdef.pl.factor_diagnostics ¶
factor_diagnostics(model: scDEF, brd_min: float = 1.0, ard_min: float = 0.001, clarity_min: float = 0.5, batch_purity_max: Optional[float] = None, batch_purity_soft_max: Optional[float] = None, n_eff_parents_max: float = 1.5, brd_exceptional: Optional[float] = None, figsize: tuple = (6, 4), ax: Optional[Axes] = None, annotate_factors: bool = False, annotation_fontsize: int = 8, annotation_alpha: float = 0.8, all_factors: bool = False, local_l0_scores: bool = False, x: FactorDiagQuantity = 'BRD', y: Optional[FactorDiagQuantity] = None, color: Optional[FactorDiagQuantity] = None, size: Optional[FactorDiagQuantity] = 'ARD', batch_panel: Optional[bool] = None, show: bool = True, _draw_colorbar: bool = True, _draw_size_legend: bool = True) -> Optional[Union[Axes, ndarray]]
Diagnostic scatter plot of layer-0 factors with flexible axis/color/size mapping.
By default plots BRD vs effective parents with marker size scaled by ARD.
When batch_purity_max or batch_purity_soft_max is set and color
is not overridden, points are colored by the corresponding batch purity
(sizes still default to ARD).
Any per-factor column of factor_obs can be mapped to an axis, color or
size. That includes the batch-split diagnostics written by
scdef.tools.factor_diagnostics(..., batch_key=...), so a
within-cell-type per-batch split can be inspected directly, e.g.::
scdef.pl.factor_diagnostics(
model, x="avg_n_eff_parents", y="batch_split_corr", color="frac_dom_batch"
)
When those diagnostics exist and the axes are left at their defaults, a
second panel showing them is drawn automatically (see batch_panel). Both
batch_split_corr and frac_dom_batch are dense — every kept factor has
a value — so nothing is silently dropped from either panel. A high
batch_split_corr at a balanced frac_dom_batch (top-left of that
panel) is the batch-corrected cell-type factor, not a split half.
This plot renders diagnostics; it issues no verdict, and neither does any
tool it draws from. To describe the shape of the batch structure — which
factors are batch-skewed, which have an opposite-batch sibling under the
same parent, and how separable the batches are inside each branch — use
batch_structure_report::
rep = scdef.tl.batch_structure_report(model, batch_key="Experiment")
splits = rep.index[rep["shape"] == "branch_split"]
shape is geometry, never cause: only the experimental design can say
whether a per-batch split is a technical duplication or a genuine
condition-specific program.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
scDEF
|
scDEF model instance |
required |
brd_min
|
float
|
minimum BRD filter threshold |
1.0
|
ard_min
|
float
|
minimum ARD filter threshold (fraction of total ARD) |
0.001
|
clarity_min
|
float
|
used for the horizontal cutoff when filtering on local
|
0.5
|
batch_purity_max
|
Optional[float]
|
optional upper bound on hard-assignment batch purity.
Factors pass when |
None
|
batch_purity_soft_max
|
Optional[float]
|
optional upper bound on soft batch purity (from
|
None
|
n_eff_parents_max
|
float
|
used when filtering on lineage
|
1.5
|
brd_exceptional
|
Optional[float]
|
if set, dashed vertical line on BRD and pass rule
allowing high-BRD factors to be kept even when effective parents
exceed |
None
|
figsize
|
tuple
|
Figure size (if ax is None) |
(6, 4)
|
ax
|
Optional[Axes]
|
matplotlib Axes to plot on |
None
|
annotate_factors
|
bool
|
whether to annotate each point with its factor label |
False
|
annotation_fontsize
|
int
|
fontsize for factor text annotations |
8
|
annotation_alpha
|
float
|
alpha value for factor text annotations |
0.8
|
all_factors
|
bool
|
if True, plot diagnostics for all layer-0 factors from the
complete snapshot |
False
|
local_l0_scores
|
bool
|
when |
False
|
x
|
FactorDiagQuantity
|
quantity for the x-axis ( |
'BRD'
|
y
|
Optional[FactorDiagQuantity]
|
quantity for the y-axis; default follows |
None
|
color
|
Optional[FactorDiagQuantity]
|
quantity for marker color. Default |
None
|
size
|
Optional[FactorDiagQuantity]
|
quantity for marker size. Default |
'ARD'
|
batch_panel
|
Optional[bool]
|
draw a second panel with the per-batch split diagnostics
( |
None
|
show
|
bool
|
whether to show the plot |
True
|
Returns:
| Type | Description |
|---|---|
Optional[Union[Axes, ndarray]]
|
Axes object if show is False, None otherwise. With two panels, an array |
Optional[Union[Axes, ndarray]]
|
of the two Axes. |