gedi2py.tools.pca

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

Compute PCA coordinates from GEDI decomposition.

PCA coordinates are computed as V @ diag(d) from the factorized SVD, where V are the right singular vectors (cell embeddings).

Parameters:
  • adata (AnnData) – Annotated data matrix with GEDI results in .uns[key].

  • n_components (int | None, default: None) – Number of PCs to compute. If None, uses all K latent factors.

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

  • key_added (str | None, default: None) – Key to store PCA in adata.obsm. Defaults to X_{key}_pca.

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

Return type:

AnnData | ndarray | None

Returns:

  • If ``copy=True``, returns PCA coordinates as numpy array (n_cells, n_components).

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

Examples

>>> import gedi2py as gd
>>> gd.tl.gedi(adata, batch_key="sample", n_latent=10)
>>> gd.tl.pca(adata, n_components=20)
>>> adata.obsm["X_gedi_pca"]