cellina.make_neighbor_perturbation#
- cellina.make_neighbor_perturbation(adata, perturbations, connectivity_key='spatial_connectivities', groupby=None, neighbor_genes=None, obsm_key_out='spatial_x_cf', layer_key='counts_cf', base=2.718281828459045, add_shift=False, renormalize=True)#
Apply Node perturbations to neighbour expression and re-aggregate.
Perturbed expression is written to
adata.layers[layer_key]and the resulting spatial features toadata.obsm[obsm_key_out]. The original count matrixadata.Xis not modified.- Parameters:
adata (
AnnData) – AnnData object.connectivity_key (
str(default:'spatial_connectivities')) – Key inadata.obspfor the spatial connectivity matrix.perturbations (
dict) – Whengroupby=None:Dict[str, float]mapping gene → perturbation value (\(\delta_g\)) applied globally to all cells. Whengroupbyis set:Dict[str, pd.Series]mapping cell-type label → gene-indexed perturbation value (\(\delta_g\)) Series. 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}\)).groupby (
Optional[str] (default:None)) – Column inadata.obsused to apply cell-type-specific perturbations. WhenNone, perturbations are applied globally to all cells.neighbor_genes (
Optional[List[str]] (default:None)) – Subset of genes to aggregate.Nonemeans all genes.obsm_key_out (
str(default:'spatial_x_cf')) – Key inadata.obsmfor the counterfactual spatial features.layer_key (
str(default:'counts_cf')) – Key inadata.layerswhere the perturbed counts are stored.
- Raises:
ValueError – If
perturbationscontains cell-type keys that are not present inadata.obs[groupby]. Partial dictionaries (covering only a subset of cell types) are allowed — unspecified cell types are left unmodified.- Return type:
None