Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Clustering and cluster evidence

Clustering groups cells that share neighbours on the graph. For this RNA example, those neighbourhoods reflect similarity in expression. A cluster can represent a cell type, a temporary state, or technical variation. Marker evidence and stability checks help distinguish these possibilities.

Leiden seeks groups with stronger connections within groups than expected from its graph model. The resolution controls the scale at which it forms those groups. Lower resolutions tend to produce broader groups, while higher resolutions tend to split them into smaller groups. A coarse partition can hide a rare population, and a fine partition can divide a homogeneous population. Paris instead builds a hierarchy of nested merges, which you can cut adaptively or at a fixed cluster count.

We will inspect a saved Leiden clustering, vary its resolution on the same graph, and compare it with Paris. Keeping the graph and layout fixed helps us see what the clustering choice changes.

Open the existing graph

Started: 2026-10-11T18:54:42.533318Z | Wall time: 6.376 s

Open the downloaded store and its saved analysis.

DataStore has 3948 (5025) cells with 1 assays: RNA Cell metadata: 'I', 'ids', 'names', 'RNA_G2M_score', 'RNA_S_score', 'RNA_UMAP1', 'RNA_UMAP2', 'RNA_cell_cycle_phase', 'RNA_clusters', 'RNA_doublet_score', 'RNA_leiden_cluster', 'RNA_nCounts', 'RNA_nFeatures', 'RNA_paris_cluster', 'RNA_percentMito', 'RNA_percentRibo' RNA assay has 33538 features and following metadata: 'I', 'ids', 'names', 'dropOuts', 'feature_type', 'genome', 'nCells'

Started: 2026-10-11T18:54:48.913886Z | Wall time: 5.375 s

The store carries an analysis saved as docs_default. Inspect its selected clusters first:

PBMC UMAP colored by the ten clusters in the prepared Leiden analysis at resolution 0.5.

Started: 2026-10-11T18:54:54.291342Z | Wall time: 0.663 s

This prepared example used Leiden resolution 0.5. The standalone method defaults to 1.0, and the standard pipeline can compare several resolutions. Cluster numbers are labels, not cell types. We use the same graph and UMAP below so only the clustering changes.

Sweep Leiden resolution

0.30.50.8
1713716261
228239455
32391237239
41305506692
5319318533
6340487289
759114929
8142256299
925625256
101515152
1100237
1200447
130025
140019
150015

Started: 2026-10-11T18:54:54.957414Z | Wall time: 0.871 s

The same PBMC UMAP colored by Leiden partitions at resolutions 0.3, 0.5, and 0.8. Higher resolution divides the cells into more groups.

Started: 2026-10-11T18:54:55.830923Z | Wall time: 1.889 s

Higher resolution usually produces more and smaller groups, but the partitions need not be nested. Investigate a split when it tracks a technical covariate, has weak marker evidence, or disappears under a modest parameter change. A rare or transitional population may need more evidence than a well-separated abundant group.

The adjusted Rand index (ARI) compares partitions without requiring the cluster numbers to match. A value of one means the partitions agree. It does not tell us which partition is better:

0.3 vs 0.5 0.901072 0.3 vs 0.8 0.601228 0.5 vs 0.8 0.637740 Name: ARI, dtype: float64

Started: 2026-10-11T18:54:57.723880Z | Wall time: 0.137 s

Inspect membership strength

Membership strength measures how strongly a cell connects to its assigned cluster: it is the fraction of the cell’s graph neighbours that carry the cell’s own cluster label. A value of 1 means that every neighbour shares the cell’s cluster. A cell whose neighbours sit mostly in other clusters scores low, even when those neighbours all share one other label. We use resolution 0.5 for this walkthrough.

PBMC UMAP colored by cluster membership strength from zero to one. Most cluster interiors score near one, while weaker membership appears along several boundaries.

Started: 2026-10-11T18:54:57.864494Z | Wall time: 0.565 s

Cluster connectivity diagram positioned on the PBMC UMAP. The strongest visible connection joins clusters 4 and 6; most other clusters have little visible connectivity.

Started: 2026-10-11T18:54:58.432255Z | Wall time: 0.218 s

Low values throughout one cluster suggest a weak boundary: many of its cells have most of their neighbours in other clusters. A narrow band of low values between otherwise coherent groups may represent continuous biology.

Review marker evidence

Marker search compares each cluster with the remaining cells. Pass the cluster result and the feature selection explicitly so the marker table refers to the partition being reviewed. We inspect the largest and smallest clusters here to check whether both have coherent marker support.

largest cluster 3 smallest cluster 10 dtype: int64

Started: 2026-10-11T18:54:58.653365Z | Wall time: 28.302 s

Markers for the largest cluster:

feature_namescoreaucp_valuep_value_adjusted
0ADTRP0.634910.609618.904351e-1091.563529e-106
1FHIT0.527210.775316.583497e-2837.359911e-280
2TSHZ20.510590.637251.791195e-1183.618861e-116
3TCEA30.498290.591011.003840e-769.931209e-75
4CHRM3-AS20.466900.662081.355024e-1433.724983e-141
5CMTM80.444710.617285.567626e-836.438863e-81
6EPHX20.433060.662306.887493e-1371.776867e-134
7MAN1C10.430580.622192.195228e-842.686991e-82
8NOG0.418630.617795.428576e-1171.090201e-114
9MAL0.403560.772923.336964e-2422.432937e-239

Started: 2026-10-11T18:55:26.958312Z | Wall time: 0.014 s

Markers for the smallest cluster:

feature_namescoreaucp_valuep_value_adjusted
0TPM20.836480.964777.923809e-682.438062e-65
1SERPINF10.829720.996851.200639e-1236.711172e-121
2MAP1A0.813520.960352.330331e-1091.070611e-106
3LILRA40.811410.999762.403755e-2152.303346e-212
4IL3RA0.805181.000009.536887e-1707.269275e-167
5SMPD30.795840.997752.867716e-2102.671596e-207
6DNASE1L30.792890.998686.656585e-1935.874962e-190
7GAS60.783360.998883.028428e-2715.078371e-268
8DERL30.779440.964401.351287e-1308.092761e-128
9FCER1A0.765530.826746.683680e-631.949194e-60

Started: 2026-10-11T18:55:26.975547Z | Wall time: 0.013 s

The p-values are cell-level one-versus-rest marker tests with within-group adjustment. They are not replicate-aware differential expression. A defensible partition combines marker evidence, graph support, technical covariates, replicate coverage, and the study question.

Pipeline cluster selection

The full pipeline can compare several Leiden resolutions for you. It uses a silhouette score, which compares a cell’s distances within its assigned group with distances to the nearest other group. Each candidate is scored on the same deterministic sample of at most 10,000 cells, using the graph’s PCA or Harmony coordinates or, with pca_dims=0, its normalized values. This keeps the comparison consistent across candidates. Paris can still run as clustering_run["paris"], but it is not an automatic winner. The cluster_selection artifact saves the scores, sampling policy, reasons a candidate was invalid, tie order, and selected key:

# Keep the saved cluster-selection diagnostics.
decision_ref = clustering_run["cluster_selection"]

# Keep the clustering chosen by the pipeline.
selected_cluster_ref = clustering_run["clusters"]

This automatic choice is a reproducible baseline, not proof that the selected resolution is best for every biological question. Retain alternative refs when the decision needs domain-specific evidence.

Optional: compare Paris cuts

Paris offers another way to divide the same graph. clusters.paris builds a hierarchy of nested merges and returns a cluster_cut reference. Load the result explicitly to inspect the hierarchy diagnostics alongside the labels.

labelsizepersistencedecision_marginforced
01741288.8527970.092988False
12228140.1444970.532383False
231343424.2734410.112503False
3429161.108293NaNFalse
4554098.711327NaNFalse
56143107.2959760.661475False
6726751.969021NaNFalse
78351146.3635760.292982False
8915NaNNaNTrue
9102919.4274830.656056False

Started: 2026-10-11T18:55:26.990881Z | Wall time: 2.756 s

Paris clustering hierarchy with numbered groups at the leaves and nodes showing successive branches. This clustering tree does not establish a developmental lineage.

Started: 2026-10-11T18:55:29.750250Z | Wall time: 1.038 s

Persistence combines group size with the range of hierarchy merge scales over which a branch survives. It is not elapsed biological time, and larger groups can have higher scores because of their size. The decision margin measures the preference for retaining the branch rather than splitting it, divided by the group size. A forced group satisfies a structural constraint and is not, by itself, strong biological evidence. Neither the hierarchy nor its cut establishes a developmental lineage.

auto vs fixed ARI 1.000000 Leiden vs Paris ARI 0.882001 dtype: float64

Started: 2026-10-11T18:55:30.792793Z | Wall time: 0.270 s

Check what a cluster means

  • Separate marker discovery from donor-level inference. Cell-level marker tests help describe the groups you found. Cells from the same donor are not independent biological replicates, so small marker p-values do not establish a reproducible difference between conditions. Use Pseudobulk and differential expression (DE) primer for replicate-aware comparisons.

  • Look for continuous transitions. Development and cell-cycle progression can cross the discrete boundaries imposed by clustering. Inspect membership strength and cluster connectivity before treating transitional cells as a distinct terminal type.

  • Check technical explanations for splits. Compare groups against sequencing depth, mitochondrial fraction, and batch or donor metadata. Automatic selection and a high resolution do not establish biological meaning. A Paris group marked forced also needs independent marker and stability evidence.