omicverse.utils.cluster

omicverse.utils.cluster(adata, method='leiden', use_rep='X_pca', random_state=1024, n_components=None, **kwargs)[source]

Run a selected clustering backend on single-cell data.

Parameters:
  • adata (anndata.AnnData) – Annotated data matrix to be clustered.

  • method (str, default='leiden') – Clustering backend. Supported values include 'leiden', 'louvain', 'kmeans', 'GMM', 'mclust', 'mclust_R', 'schist', and 'scICE'.

  • use_rep (str, default='X_pca') – Key in adata.obsm used for embedding-based methods such as GMM, K-means, and scICE.

  • random_state (int, default=1024) – Random seed used by stochastic clustering methods.

  • n_components (int or None, default=None) – Number of clusters/components for 'kmeans', 'GMM', and 'mclust'.

  • **kwargs – Extra keyword arguments forwarded to the selected backend.

Returns:

Returns a fitted scICE model instance when method='scICE'. Other methods write labels to adata.obs and return None.

Return type:

object or None

Examples

>>> sc.pp.neighbors(adata, n_neighbors=15, n_pcs=50)
>>> cluster(adata, method='leiden', resolution=1.0)
>>> cluster(adata, method='GMM', n_components=10, use_rep='X_pca')
>>> scice_model = cluster(adata, method='scICE', use_rep='X_pca')