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.

Compare clusterings and check the clusters

Cluster 3,948 human peripheral blood mononuclear cells (PBMCs) from one healthy donor, the 10x Genomics 5k PBMC dataset, with Leiden at three resolutions and with the hierarchical method Paris, then check the clusters against the neighbor graph and their marker genes. Every partition divides the same graph, saved with one RNA analysis, so the partitions differ only in the clustering.

Leiden finds 11 clusters at resolution 0.3, 12 at 0.5 and 17 at 0.8: the lowest resolution merges the two NK clusters, and the highest splits five clusters in two, among them three of the four T-cell clusters. At 0.5, 87% of the cells have all of their nearest neighbors in their own cluster, and most of the 37 cells with the majority of their neighbors elsewhere lie in T-cell clusters 3 and 4, the pair of clusters that the graph joins most strongly. The T-cell clusters thus divide one continuous region of the graph. The ten highest-scoring markers of the largest, cluster 1, reach AUCs of at most 0.78, whereas five genes mark all 12 platelets at an AUC of 1.000.

Paris divides the same graph into 14 groups that agree with Leiden at an adjusted Rand index of 0.77. Its hierarchy first separates the 15 pDC-like cells, which no edge joins to the other cells, then the monocytes and platelets from the lymphocytes.

Open the saved graph

Started: 2026-11-23T23:00:09.788326Z | Wall time: 6.790 s

ds.pipeline.open(label="rna") reopens the saved run of the RNA recipe, ds.pipeline.rna. Indexing the run by an output name returns an artifact reference, a handle to one saved result: connectivity_map is the weighted neighbor graph, and umap is the two-dimensional layout of the cells. A clustering call takes the graph’s reference and saves its labels as a new artifact, which a repeated call with the same arguments reuses instead of recomputing.

Nearest neighbors per cell: 11
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-11-23T23:00:16.579564Z | Wall time: 0.807 s

The run analyzed the 3,948 of the store’s 5,025 cells that passed quality control, built the graph from each cell’s 11 nearest neighbors, and clustered the graph with Leiden at resolution 0.5. Each Leiden partition records its graph and resolution, so ds.artifacts.find("clusters", graph=graph, method="leiden", resolution=0.5) finds the run’s partition, and clustering_run["clusters"] returns the same reference, the partition that the run selected. Draw the selected clusters:

UMAP of the 3,948 PBMCs colored by the 12 saved Leiden clusters at resolution 0.5, with each cluster's number printed on its cells. T-cell clusters 1, 3, 4 and 8 form a connected mass on the left, with NK cluster 5 below it and the small NK cluster 9 beside the lower end of cluster 3. B-cell clusters 6 and 7 sit at the top, CD14 monocyte cluster 2 forms a separate island on the right with CD16 monocyte cluster 10 at its tip, and pDC-like cluster 11 and platelet cluster 12 sit apart near the top right.

Started: 2026-11-23T23:00:17.387834Z | Wall time: 0.181 s

The PBMC analysis names these 12 clusters from their marker genes: clusters 1, 3, 4 and 8 hold T cells, cluster 2 CD14 monocytes, clusters 5 and 9 NK cells, clusters 6 and 7 B cells, cluster 10 CD16 monocytes, cluster 11 pDC-like cells and cluster 12 platelets.

Compare Leiden resolutions

Leiden maximizes modularity: it divides a graph into clusters with more edge weight inside them than expected by chance, given each cell’s total edge weight (Leiden method). The resolution weighs that expectation, so a higher resolution gives more, smaller clusters; clusters.leiden uses 1.0 by default. Partition the same graph at 0.3 and at 0.8, and count the cells in each cluster:

resolution0.30.50.8
cluster
113031217646
2704704509
3612528447
4321474408
5319283301
6256256296
7239239287
8142166257
92529242
101525234
111215153
1201267
130030
140025
150019
160015
170012

Started: 2026-11-23T23:00:17.569988Z | Wall time: 0.257 s

Resolution 0.3 gives 11 clusters, 0.5 gives 12 and 0.8 gives 17. Leiden numbers the clusters of each partition by decreasing size, so a row of the table pairs clusters of equal rank, which need not hold the same cells. clusters.relabel_by_overlap matches the clusters of one partition to those of a reference partition. It names each cluster after the reference cluster that holds the most of its cells and adds a letter, a for the cluster that holds the largest share of that reference cluster and b for the next, so 1a and 1b are two parts of cluster 1, and the only cluster named after cluster 10 is 10a. A reference cluster that gives its name to no cluster is added after a hyphen to the name of the cluster that holds the most of its cells, as in 5-9a. Name the 0.3 and 0.8 clusters after the 0.5 clusters, and draw the three partitions side by side:

Three UMAPs of the same PBMCs colored by Leiden partitions at resolutions 0.3, 0.5 and 0.8, with each cluster's name printed on its cells; the 0.3 and 0.8 clusters are named after the 0.5 cluster that holds the most of their cells. At 0.3 the NK clusters merge into 5-9a and cluster 4a reaches into the upper part of cluster 3. At 0.8 clusters 1, 2, 3, 4 and 6 each split into an a and a b part, with 6b a small group between 6a and 7a, while every other cluster keeps a single part, such as 10a, 11a and 12a.

Started: 2026-11-23T23:00:17.828245Z | Wall time: 0.330 s

At 0.3, NK clusters 5 and 9 merge into 5-9a, and 4a, the counterpart of T-cell cluster 4, takes in the upper part of cluster 3, so the two partitions do not nest. At 0.8, five clusters split in two: T-cell clusters 1, 3 and 4, the CD14 monocytes of cluster 2 and the B cells of cluster 6. The three smallest clusters, 10, 11 and 12, keep their 25, 15 and 12 cells at every resolution.

The adjusted Rand index (ARI) measures how often two partitions agree on whether a pair of cells belongs together, so it needs no matched labels: 1 means identical partitions, and 0 the agreement expected by chance.

0.3 vs 0.5 0.871655 0.3 vs 0.8 0.583116 0.5 vs 0.8 0.639142 Name: ARI, dtype: float64

Started: 2026-11-23T23:00:18.159409Z | Wall time: 0.180 s

Resolutions 0.3 and 0.5 agree at an ARI of 0.87. Resolution 0.8 agrees less with either, at 0.64 with 0.5 and 0.58 with 0.3: its splits divide the largest clusters, which hold most of the pairs of cells that the index counts.

Find where clusters meet in the graph

Membership strength is the share of a cell’s nearest neighbors in the graph that belong to the cell’s own cluster: 1 when all 11 neighbors share its cluster, and below 0.5 when most of them belong to other clusters. Low values mark the cells where clusters meet. The rest of the page examines the saved partition at resolution 0.5:

PBMC UMAP colored by membership strength at Leiden resolution 0.5, on a scale from 0 (purple) to 1 (yellow) labeled at the top: the share of each cell's 11 nearest neighbors in its own cluster. Almost every cell is yellow; 87% have every neighbor in their own cluster. The cells with low strength, teal to dark blue, line the boundaries of T-cell cluster 4 with clusters 1 and 3 and the junction of clusters 1, 4 and 8, with smaller groups where T-cell cluster 3 meets NK clusters 5 and 9, where the two B-cell clusters meet and where monocyte cluster 2 meets cluster 10.
Cells with every neighbor in their own cluster: 87.0%
Cells with fewer than half of their neighbors in it: 37 (0.9%)
cellsmean_strengthbelow_0.5
cluster
112170.9803
27040.9980
35280.94713
44740.91514
52830.9880
62560.9881
72390.9832
81660.9234
9290.9310
10250.9530
11151.0000
12120.9850

Started: 2026-11-23T23:00:18.340291Z | Wall time: 0.130 s

Membership strength is 1 for 87% of the cells. Only 37 cells, 0.9%, are weakly placed, with fewer than half of their neighbors in their own cluster, and T-cell clusters 3 and 4 hold 13 and 14 of them. In the UMAP, the cells with low strength line the boundaries of cluster 4 with clusters 1 and 3, the junction of clusters 1, 4 and 8, and the junctions of cluster 3 with NK clusters 5 and 9. Clusters 4 and 8 have the lowest mean strengths, 0.915 and 0.923, followed by NK cluster 9 at 0.931, while all 15 pDC-like cells of cluster 11 have every neighbor in their cluster.

Cluster connectivity measures how strongly the graph joins two clusters. clusters.connectivity sums the edge weight between the cells of each pair of clusters, and its normalized weight divides that sum by the geometric mean of the two clusters’ total edge weights, so two clusters joined by 1% of their edge weight score about 0.01. plots.cluster_connectivity draws each pair as an edge between the clusters’ median UMAP positions, wider for a stronger link. Both calls here leave out the pairs below a normalized weight of 0.005:

Cluster connectivity at Leiden resolution 0.5 drawn over the PBMC UMAP: cells faintly colored by cluster, a numbered node at each cluster's median position, and gray edges whose width grows with the normalized weight, for the nine pairs of clusters at or above 0.005. The widest edges join T-cell clusters 3 and 4 and clusters 1 and 4, a medium edge joins 1 and 8, and thin edges join 6 and 7, 5 and 9, 2 and 10, 4 and 8, and cluster 3 to clusters 5 and 9. Nodes 11 and 12 have no edge.
sourcetargetrawWeightnormalizedWeight
034152.27910.0349
114174.01050.0255
21868.32780.0171
36725.53580.0119
4598.94970.0117
53531.12880.0093
621010.13130.0089
7396.31260.0060
84813.17770.0054

Started: 2026-11-23T23:00:18.471338Z | Wall time: 0.124 s

The three strongest links join T-cell clusters, 3 with 4 at a normalized weight of 0.0349, 1 with 4 at 0.0255 and 1 with 8 at 0.0171, at the boundaries that the weakly placed cells line. Four of the other six links also stay within a lineage, joining the B-cell clusters 6 and 7, the NK clusters 5 and 9, the monocyte clusters 2 and 10, and T-cell clusters 4 and 8. The remaining two join T-cell cluster 3 to the NK clusters 5 and 9; the PBMC analysis shows that cluster 3 expresses NKG7, part of the cytotoxic program that T cells share with NK cells. Neither the pDC-like cells of cluster 11 nor the platelets of cluster 12 reach the threshold with any cluster. The T-cell clusters, joined through cluster 3 to the NK cells, therefore divide one continuous region of the graph, with boundaries that move with the resolution, while the B cells, the monocytes, the pDC-like cells and the platelets have no link to another lineage at this threshold.

Review the marker evidence

The graph shows where clusters meet, and marker genes show what sets each cluster apart. markers.search tests each gene of the run’s feature universe, all 33,538 genes of the assay, as a marker of each cluster against the rest of the cells, and saves the statistics as a marker table. Compare the largest cluster, one of the four T-cell clusters, with the smallest, the platelets:

clustercells
largest11217
smallest1212

Started: 2026-11-23T23:00:18.596705Z | Wall time: 0.712 s

markers.load returns a cluster’s markers sorted by score, a specificity from 0 to 1 that cell type annotation defines with the other columns. Its default filters, written out above, keep the genes detected in at least 20% of the cluster’s cells, with an AUC of at least 0.6 and an adjusted p-value of at most 0.05. The AUC is the probability that a cell of the cluster ranks above a cell of the rest in the gene’s expression, ties counting one half, and frac_exp and frac_exp_rest are the fractions of cells with counts of the gene inside and outside the cluster. The ten highest-scoring markers of cluster 1 that pass these filters:

feature_namescoreaucfrac_expfrac_exp_rest
0ADTRP0.5520.6090.2410.025
1TSHZ20.4540.6360.3250.054
2CHRM3-AS20.4410.6610.3800.064
3FHIT0.4330.7770.6240.100
4EPHX20.4220.6630.3910.075
5CMTM80.4050.6160.3020.076
6LRRN30.3960.7350.5330.067
7NOG0.3830.6160.2580.027
8MAL0.3770.7690.6740.164
9GSTM30.3590.6040.2780.075

Started: 2026-11-23T23:00:19.310030Z | Wall time: 0.004 s

These genes separate cluster 1 only in part. Each is detected in 24% to 67% of the cluster’s cells, and in 2.5% to 16% of the other cells. A cluster cell without counts of a gene cannot rank above the many cells of the rest that also have none, so a gene detected in few of the cluster’s cells cannot reach a high AUC: the highest here is 0.78, and the lowest, 0.60, sits at the filter’s floor of 0.6. The two highest AUCs, FHIT at 0.78 and MAL at 0.77, belong to the genes detected in the most cells of the cluster, 62% and 67%. No T-cell gene such as CD3D or IL7R makes the list: cluster 1 shares those genes with T-cell clusters 3, 4 and 8, as the PBMC analysis shows, and the score favors genes expressed mainly in one cluster. The ten highest-scoring markers of cluster 12 that pass the filters:

feature_namescoreaucfrac_expfrac_exp_rest
0F13A10.8201.0001.0000.061
1ACRBP0.8070.9580.9170.014
2PTGS10.8071.0001.0000.035
3CD90.7991.0001.0000.033
4PRKAR2B0.7981.0001.0000.011
5AP003068.20.7970.9580.9170.016
6HIST1H3H0.7940.9570.9170.020
7CLU0.7881.0001.0000.011
8HIST1H2BJ0.7830.8720.7500.026
9DMTN0.7810.9560.9170.051

Started: 2026-11-23T23:00:19.314772Z | Wall time: 0.004 s

Five genes, F13A1, PTGS1, CD9, PRKAR2B and CLU, are detected in all 12 cells of cluster 12 and in 1.1% to 6.1% of the other cells, and reach AUCs of 1.000. Platelets differ from every other cell type in the sample, so their genes mark every platelet and few other cells, whereas the markers of cluster 1 go undetected in a third to three quarters of its cells.

Compare with a Paris hierarchy

Paris builds a hierarchy over the same graph. Starting from single cells, it repeatedly merges the two groups that share the most edge weight relative to the product of their total edge weights, until each connected part of the graph is one group. clusters.paris cuts the hierarchy into clusters, by default adaptively, at its own height in each branch, or with n_clusters at one height into that many groups.

The adaptive cut scores each group by its persistence: the group’s size times the drop in 1/(1 + d) from the merge that forms the group to the merge that joins it into a larger group. Here d is the merge distance, the product of the two merging groups’ total weights divided by their shared weight and by the graph’s total weight, so the large distances near the root add little to persistence. The cut keeps a group whole when the group’s persistence beats the summed persistence of its best split, and the decision margin is that excess divided by the group’s size. A split must also raise modularity, computed here on the unweighted graph at resolution 1, and leave no part smaller than 12 cells, one more than the 11 neighbors per cell. forced marks a connected part of the graph that has no allowed split, which the cut keeps whole. clusters.load_paris returns the labels with a diagnostic for each group, and the table adds the Leiden 0.5 cluster that holds most of each group’s cells and the share of the group in it:

14 groups of at least 12 cells
sizepersistencedecision_marginforcedleiden_clusterleiden_share
label
136477.7150.069False21.000
2337101.8520.178False21.000
3228139.8160.531False71.000
41340385.1140.076False10.881
528757.863NaNFalse50.986
642460.828NaNFalse30.939
7143111.0300.688False80.972
812556.5630.365False31.000
926451.631NaNFalse60.958
10352145.9420.253False40.923
112821.416NaNFalse100.893
1215NaNNaNTrue111.000
131211.855NaNFalse121.000
142919.3260.653False91.000

Started: 2026-11-23T23:00:19.319445Z | Wall time: 0.847 s

Paris hierarchy above the 14 adaptive groups of the PBMC graph, drawn as a tree from a gray root at the top, with the groups as numbered leaves sized by cell count and small black dots at the merges between them. The root joins group 12, the pDC-like cells, to the rest of the graph, which splits into a branch of the monocyte and platelet groups 13, 11, 1 and 2 and a lymphocyte branch that divides into the T-cell groups 7, 4, 10, 8 and 6 on one side and the NK groups 14 and 5 with the B-cell groups 3 and 9 on the other. Group 4, with 1,340 cells, is by far the largest leaf.

Started: 2026-11-23T23:00:20.167112Z | Wall time: 0.182 s

The adaptive cut finds 14 groups of at least 12 cells. Group 12 is forced and has no persistence: its 15 cells, Leiden’s pDC-like cluster 11, form a connected part of the graph on their own, too small to split into two groups of at least 12 cells. Every other group has at least 88% of its cells in one Leiden cluster. Paris splits the CD14 monocytes of Leiden cluster 2 into groups 1 and 2 and T-cell cluster 3 into groups 6 and 8, and gives each other Leiden cluster one main group. Paris and Leiden draw the T-cell boundaries differently: group 4 holds 1,340 cells against the 1,217 of Leiden cluster 1, and group 10, whose cells come mostly from Leiden cluster 4, holds 352 cells against that cluster’s 474. Groups 1 and 4 have the smallest decision margins, 0.069 and 0.076, so they are the closest calls between keeping a group whole and splitting it; they hold CD14 monocytes and most of T-cell cluster 1, both of which Leiden also splits at resolution 0.8. The groups without a margin were kept whole by a rule rather than by their scores: a split would have left a part smaller than 12 cells or would not have raised modularity.

The tree draws the hierarchy from its root at the top, with each group sized by its cell count. The root joins the pDC-like component, group 12, to the rest of the graph, which splits first into the monocytes and platelets, groups 1, 2, 11 and 13, and the lymphocytes. The lymphocytes split into the T cells, groups 4, 6, 7, 8 and 10, and a branch that joins the NK cells, groups 5 and 14, to the B cells, groups 3 and 9, although the connectivity table above links the NK clusters only to T-cell cluster 3. Paris divides the weight that two groups share by the product of their total weights, so a link to the large T-cell groups counts for less than one to the smaller B-cell branch: links between NK and B-cell clusters, each too weak to reach that table, outrank the links of the NK clusters to T-cell cluster 3. The order of the merges between lineages therefore depends on the groups’ sizes as well as their shared weight, and the connectivity table is the better guide to which populations the graph joins.

Paris adaptive vs Paris fixed 0.827808 Leiden 0.5 vs Paris adaptive 0.774565 Name: ARI, dtype: float64

Started: 2026-11-23T23:00:20.350569Z | Wall time: 0.073 s

Cutting the hierarchy at one height into the same number of groups agrees with the adaptive cut at an ARI of 0.83: a single height cannot suit branches that separate at different scales. Leiden at resolution 0.5 and the adaptive Paris cut agree at 0.77, and the table above shows where they part, in the CD14 monocytes and at the boundaries of the T-cell clusters.

Choose clusters in the RNA recipe

ds.pipeline.rna clusters its graph with Leiden at four resolutions by default and returns the partition with the best silhouette as the run’s clusters output. The silhouette compares each cell’s distance to its own cluster with its distance to the nearest other cluster, in the coordinates that built the graph, so it favors few, well-separated clusters. leiden={"partitions": [...]} sets the candidates, and leiden={"selected": ...} keeps the named resolution without scoring. Paris runs only when asked, with paris=True or paris={"n_clusters": ...}, and the selection never chooses a Paris cut; automatic cluster selection describes how the cells are sampled and the candidates scored. The run’s cluster_selection output records each candidate’s silhouette and the one selected:

Leiden settings: {'partitions': [0.5], 'selected': None}
Selected: 0.5
0.5 0.35302 Name: silhouette, dtype: float64

Started: 2026-11-23T23:00:20.424742Z | Wall time: 0.011 s

The saved run listed one candidate, leiden={"partitions": [0.5]}, so its selection had nothing to compare and recorded one silhouette, 0.35, on a scale from -1 to 1 where 0 means that a cell is as close to the nearest other cluster as to its own. The silhouette is a mean over cells, so it scores a whole partition and cannot tell whether a given boundary, such as one between the T-cell clusters above, divides two populations; membership strength, connectivity and markers check each boundary. A cluster that differs from nearby clusters only in counts, detected genes or mitochondrial share is more likely technical than biological; quality control covers these measures.

Cell type annotation names the clusters of this partition from marker evidence, and the neighbor graph page shows how the number of neighbors changes the graph that every clustering here divides.