cellina.make_perturbed_expression#
- cellina.make_perturbed_expression(adata, perturbations=None, groupby=None, layer_key='counts_cf', base=2.718281828459045, add_shift=False, renormalize=True, inplace=True)#
Apply Node perturbations to counts and store the result as a layer.
Counts-space analog of
make_neighbor_perturbation(). Cellina scales counts; the GCN aggregates over the spatial graph at inference time when this layer is supplied viacf_layer.- Parameters:
adata (
AnnData) – AnnData with raw counts inadata.X.perturbations (
Optional[dict] (default:None)) –Dict[str, float]mapping gene → perturbation value (\(\delta_g\), global) whengroupby=None.Dict[str, pd.Series]mapping cell-type label → gene-indexed perturbation value (\(\delta_g\)) Series whengroupbyis set. Values are interpreted as additive shifts whenadd_shift=True(\(T_g(x) = x + \delta_g\)) or as logFCs whenadd_shift=False(\(T_g(x) = x \cdot e^{\delta_g}\)).Nonecopiesadata.Xunchanged.groupby (
Optional[str] (default:None)) – Column inadata.obsfor cell-type-specific perturbations.layer_key (
str(default:'counts_cf')) – Key to write inadata.layers.base (
float(default:2.718281828459045)) – Base for logFC → fold-change conversion. Defaultnp.e.add_shift (
bool(default:False)) – If True, add the logFC directly to counts instead of multiplying.renormalize (
bool(default:True)) – If True, rescale rows after perturbation to preserve library sizes.inplace (
bool(default:True)) – If True, write toadata.layers[layer_key]and return None. If False, return the perturbed matrix without modifying adata.
- Raises:
ValueError – If
groupbyis set andperturbationscontains unknown cell types.