gedi2py.tools.gradient¶
- gedi2py.tools.gradient(adata, pathway_idx=None, *, key='gedi', copy=False)[source]¶
Compute gradient of pathway activity across cells.
Uses the pathway coefficient matrix A and cell loadings B to compute the gradient of pathway activity in the latent space.
- Parameters:
adata (
AnnData) – Annotated data matrix with GEDI results.pathway_idx (
int|None, default:None) – Index of the pathway to compute gradient for. IfNone, computes gradients for all pathways.key (
str, default:'gedi') – Key inadata.unswhere GEDI results are stored.copy (
bool, default:False) – IfTrue, return the gradient array instead of storing inadata.
- Return type:
- Returns:
If ``copy=True``–If
pathway_idxis specified: (n_cells, K) gradient arrayIf
pathway_idxisNone: (n_cells, K, n_pathways) gradient array
Otherwise,stores in ``adata.obsm[``’{key}_gradient’:py:class:`]`andreturns ``None`.`
Notes
The gradient represents the direction in latent space that maximally increases pathway activity. This can be used for trajectory analysis or identifying cells transitioning along a pathway.
This requires that a pathway prior matrix C was provided during model training.
Examples
>>> import gedi2py as gd >>> gd.tl.gedi(adata, batch_key="sample", C=pathway_matrix) >>> gd.tl.gradient(adata, pathway_idx=0) >>> adata.obsm["gedi_gradient"] # direction to increase pathway 0