chrysalis.aa
- chrysalis.aa(adata: AnnData, n_archetypes: int = 8, pca_key: Optional[str] = None, n_pcs: Optional[int] = None, max_iter: int = 200)
Run archetypal analysis on the low-dimensional embedding.
Calculates archetypes, alphas, loadings, and RSS (Residual Sum of Squares). Requires input calculated with chrysalis.pca.
- Parameters:
adata – The AnnData data matrix of shape n_obs × n_vars. Rows correspond to cells and columns to genes.
n_archetypes – Number of archetypes (tissue compartments) to be identified.
pca_key – Define alternative PCA input key from .obm, otherwise chr_X_pca is used.
n_pcs – Number of PCs (Principal Components) to be used.
max_iter – Maximum number of iterations.
- Returns:
Updates .uns with the following fields:
.uns[‘chr_aa’][‘archetypes’] – Archetypes.
.uns[‘chr_aa’][‘alphas’] – Alphas.
.uns[‘chr_aa’][‘loadings’] – Gene loadings.
.uns[‘chr_aa’][‘RSS’] – RSS reconstruvtion error.
Example usage:
>>> import chrysalis as ch >>> import scanpy as sc >>> adata = sc.datasets.visium_sge(sample_id='V1_Human_Lymph_Node') >>> sc.pp.calculate_qc_metrics(adata, inplace=True) >>> sc.pp.filter_cells(adata, min_counts=6000) >>> sc.pp.filter_genes(adata, min_cells=10) >>> ch.detect_svgs(adata) >>> sc.pp.normalize_total(adata, inplace=True) >>> sc.pp.log1p(adata) >>> ch.pca(adata) >>> ch.aa(adata, n_pcs=20, n_archetypes=8)