napari_prism.tl.cluster_embeddings

napari_prism.tl.cluster_embeddings#

napari_prism.tl.cluster_embeddings(adata, recipe, ks, rs, embedding_name='X_pca_harmony', n_pcs=None, random_state=0, n_iter=-1, min_size=10, log_time=True, backend='CPU')#

Perform Phenograph or Scanpy clustering on an .obsm embedding within an AnnData object.

Parameters:
  • adata (AnnData) – AnnData object.

  • recipe (Literal['phenograph', 'scanpy']) – Clustering recipe to use.

  • ks (int | list[int]) – A single or list of K values to search over.

  • rs (float | list[float]) – A single or list of R values to search over.

  • embedding_name (str (default: 'X_pca_harmony')) – The name of the embedding to use. If not found, PCA will be run on .X, based on the value of n_pcs.

  • n_pcs (Optional[int] (default: None)) – The number of principal components to use if no PCA embedding is found in .obsm.

  • random_state (int (default: 0)) – The random seed to use for all algorithms.

  • n_iter (int (default: -1)) – The maximum number of iterations to use. If -1, runs until it reaches an iteration with no improvement in quality. If running on GPU, this is enforced to be 500.

  • min_size (int (default: 10)) – The minimum size of a cluster. If a cluster has less than this number of cells, it will be assigned a label of -1.

  • log_time (bool (default: True)) – Log the time at each step of the process.

  • backend (Literal['CPU', 'GPU'] (default: 'CPU')) – The backend to use for clustering. Either ‘CPU’ or ‘GPU’.

Return type:

AnnData

Returns:

AnnData object with the clustering results stored as pd.DataFrames in adata.obsm[_labels], where the columns represent a single clustering run and graph clustering quality scores stored in adata.uns[_quality_scores].