Skip to content

scdef.tl.get_batch_specific_genes_from_gene_scale

get_batch_specific_genes_from_gene_scale(model: 'scDEF', *, eps: float = 1e-12, log_base: float = 2.0, reference: Literal['mean_other_batches', 'global_mean'] = 'mean_other_batches') -> DataFrame

Per-gene log-ratios of batch-specific gene_scale vs a reference profile.

After fitting (and annotate_adata), scDEF stores inferred positive gene scaling factors in model.pmeans["gene_scale"] with shape (n_batches, n_genes) when batch_key was set with at least two batches. Higher scale for a gene in a batch means the model explains more variance / signal for that gene in that batch (relative to the Gamma prior mean encoded in gene_ratio).

For each batch b, this computes::

log_ratio[g, b] = log( scale[b, g] + eps ) - log( ref[g] + eps )

with log at the chosen base (default log2), and ref either the mean of the other batches at gene g (default) or the global mean across all batches at g.

Parameters:

Name Type Description Default
model 'scDEF'

Fitted scDEF model whose pmeans['gene_scale'] has shape (n_batches, n_genes) with n_batches >= 2.

required
eps float

Small constant for numerical stability.

1e-12
log_base float

Logarithm base (2 for log2, np.e for natural log).

2.0
reference Literal['mean_other_batches', 'global_mean']

mean_other_batches compares each batch to the mean of the remaining batches per gene. global_mean compares to the mean across all batches (same reference column for every batch).

'mean_other_batches'

Returns:

Type Description
DataFrame

DataFrame indexed like model.adata.var_names, one column per batch

DataFrame

label in model.batches (length must match gene_scale batch

DataFrame

dimension). Positive entries indicate relatively higher gene_scale in

DataFrame

that batch vs the chosen reference.

Raises:

Type Description
ValueError

If gene_scale has fewer than two batch rows or is missing.