gedi2py.tools.vector_field

gedi2py.tools.vector_field(adata, start_contrast, end_contrast, *, n_steps=10, key='gedi', key_added=None, copy=False)[source]

Compute vector field for trajectory between two conditions.

Uses the differential expression framework to compute a vector field representing the transcriptional trajectory from one condition to another.

Parameters:
  • adata (AnnData) – Annotated data matrix with GEDI results.

  • start_contrast (ndarray | list) – Contrast vector defining the starting condition.

  • end_contrast (ndarray | list) – Contrast vector defining the ending condition.

  • n_steps (int, default: 10) – Number of interpolation steps between conditions.

  • key (str, default: 'gedi') – Key in adata.uns where GEDI results are stored.

  • key_added (str | None, default: None) – Key to store results. Defaults to {key}_vector_field.

  • copy (bool, default: False) – If True, return the vector field dict instead of storing in adata.

Return type:

AnnData | dict | None

Returns:

  • If ``copy=True``, returns dict with keys

    • vectors: (n_steps, n_genes) array of expression changes

    • positions: (n_steps, L) array of contrast positions

  • Otherwise, stores in ``adata.uns[key_added]`` and returns ``None`.`

Notes

The vector field represents the direction and magnitude of transcriptional change at each point along the trajectory from start to end condition.

This requires that a covariate matrix H was provided during model training.

Examples

>>> import gedi2py as gd
>>> import numpy as np
>>> # Define trajectory from control to treatment
>>> start = np.array([0, 1])  # control
>>> end = np.array([1, 0])    # treatment
>>> gd.tl.vector_field(adata, start, end, n_steps=20)
>>> adata.uns["gedi_vector_field"]