gedi2py.tools.pathway_associations

gedi2py.tools.pathway_associations(adata, *, sparse_output=False, key='gedi', key_added=None, copy=False)[source]

Compute pathway-gene associations from GEDI model.

Uses the pathway coefficient matrix A and gene loading matrix Z to compute associations between pathways and genes, accounting for the learned latent structure.

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

  • sparse_output (bool, default: False) – If True, return a sparse matrix. Useful for large pathway sets.

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

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

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

Return type:

AnnData | ndarray | None

Returns:

  • If ``copy=True``, returns pathway association matrix (n_genes, n_pathways).

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

Notes

Pathway associations require that a gene-level prior matrix C was provided during model training via gd.tl.gedi(..., C=pathway_matrix).

The association matrix represents how strongly each gene is associated with each pathway through the learned latent factors.

Examples

>>> import gedi2py as gd
>>> # C is (n_genes, n_pathways) pathway membership matrix
>>> gd.tl.gedi(adata, batch_key="sample", C=pathway_matrix)
>>> gd.tl.pathway_associations(adata)
>>> adata.varm["gedi_pathway_assoc"]  # (n_genes, n_pathways)