Goal
Turn the notebook's clustering comparison into one reusable job: choose and run a clustering backend on a preprocessed single-cell AnnData. Keep this skill focused on backend selection and output contracts after PCA and, when needed, graph construction.
Quick Workflow
- Inspect whether the input already has PCA or another embedding, and whether a neighbor graph already exists.
- Choose a backend explicitly:
leiden,louvain,scICE, orGMMfor the notebook-covered paths. - Build a neighbor graph first for
leidenandlouvain. - Pass
use_repexplicitly for embedding-based methods such asGMMandscICE. - Validate which
obscolumns were added, and treat ARI or figure rendering as optional downstream reporting rather than the core contract.
Interface Summary
ov.utils.cluster(adata, method='leiden', use_rep='X_pca', random_state=1024, n_components=None, **kwargs)dispatches to a clustering backend.- Live source exposes more
methodvalues than the notebook covers:leiden,louvain,kmeans,GMM,mclust,mclust_R,schist, andscICE. leidenandlouvainforward**kwargsto scanpy clustering on the current graph.GMMandmclustuse the embedding named byuse_rep, requiren_components, and write bothmclustandgmm_cluster.scICEreturns a fitted model object and adds one or morescICE_k*columns toadata.obsthroughadd_to_adata(...).scICEruntime behavior depends onresolution_range,n_steps,n_trials, andn_boot.
Stage Selection
- Use
leidenfor the default graph-based clustering path. - Use
louvainonly when Louvain compatibility is specifically requested. - Use
GMMwhen the user wants soft-assignment-style Gaussian mixture clustering on an embedding instead of graph partitioning. - Use
scICEwhen the user wants consistency-guided cluster-count selection and is willing to pay the extra bootstrap cost. - Keep the notebook's UMAP and ARI cells optional; they are reporting on top of clustering outputs, not the reusable skill boundary.
Input Contract
- Start from an
AnnDataobject that already has PCA or another usable embedding for embedding-based methods. - Ensure a neighbor graph exists before
leidenorlouvain. - Ensure the embedding named by
use_repexists beforeGMMorscICE. - Pass
n_componentswhen usingGMMormclust.
Minimal Execution Patterns
import omicverse as ov
ov.pp.neighbors(adata, n_neighbors=15, n_pcs=50, use_rep="scaled|original|X_pca")
ov.utils.cluster(adata, method="leiden", resolution=1.0)
ov.utils.cluster(adata, method="louvain", resolution=1.0)
ov.utils.cluster(
adata,
method="GMM",
use_rep="scaled|original|X_pca",
n_components=21,
)
scice_model = ov.utils.cluster(
adata,
method="scICE",
use_rep="scaled|original|X_pca",
resolution_range=(4, 20),
n_boot=50,
n_steps=11,
)
Constraints
- Do not use this skill as a preprocessing skill; it assumes the object is already prepared enough to cluster.
- Do not leave
methodimplicit. - Do not assume the notebook's cluster counts are stable defaults for other datasets.
- Treat
scICE_k*outputs as data-dependent candidate solutions, not a fixed schema with one guaranteed suffix. - Keep smoke and acceptance commands shell-agnostic.
Validation
- Check that the intended
obscolumn was added for the chosen backend. - For
GMM, check bothmclustandgmm_cluster. - For
scICE, check that a model object was returned and that at least onescICE_k*column was added. - If comparing backends, compute metrics such as ARI only after all requested label columns exist.
- If only a bounded smoke path was run, say which backends were executed and which were source-grounded only.
Resource Map
- Use the branch selection notes when choosing a backend.
- Use the source grounding notes for current method branches and output columns.
- Use the notebook mapping notes to trace the notebook's sections into this reusable skill.
- Use the compatibility notes for dependency-sensitive or backend-sensitive paths.