peach.tl.extract_archetype_weights

peach.tl.extract_archetype_weights#

peach.tl.extract_archetype_weights(adata, model=None, *, pca_key='X_pca', weights_key='cell_archetype_weights', batch_size=256, device='cpu', verbose=True)[source]#

Extract cell archetype weights from trained Deep_AA model.

This function computes the barycentric coordinates (weights) for each cell that describe how itโ€™s composed of the learned archetypes.

Parameters:
  • adata (AnnData) โ€“ Annotated data object with PCA coordinates

  • model (Deep_AA model, optional) โ€“ Trained model. If None, will look for model in adata.uns[โ€˜trained_modelโ€™]

  • pca_key (str, default: "X_pca") โ€“ Key in adata.obsm containing PCA coordinates

  • weights_key (str, default: "cell_archetype_weights") โ€“ Key to store weights in adata.obsm

  • batch_size (int, default: 256) โ€“ Batch size for processing

  • device (str, default: "cpu") โ€“ Device for computation (โ€˜cpuโ€™, โ€˜cudaโ€™, or โ€˜mpsโ€™)

  • verbose (bool, default: True) โ€“ Whether to print progress

Returns:

Cell archetype weights of shape (n_cells, n_archetypes) Also stores weights in adata.obsm[weights_key]

Return type:

np.ndarray

Examples

>>> # After training
>>> results = pc.tl.train_archetypal(adata, n_archetypes=5)
>>>
>>> # Extract weights
>>> weights = pc.tl.extract_archetype_weights(adata, results["model"])
>>>
>>> # Weights are now in adata.obsm['cell_archetype_weights']
>>> print(adata.obsm["cell_archetype_weights"].shape)