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¶
# Tabulate the partitions and their diagnostics, and lay out the figures.
from dataclasses import asdict
from itertools import combinations
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import cytearc
from cytearc.plotting import ColorScale
# Keep routine logs and progress bars out of the page.
cytearc.configure_output(level="WARNING", progress=False)
# Download the prepared PBMC store, a 61 MB archive that holds a saved RNA analysis.
dataset = cytearc.datasets.connect("cytearc_docs").download_dataset(
"tenx_5K_pbmc_rnaseq", destination="cytearc_datasets", zarr=True
)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.
# Open the store and its saved RNA run.
ds = cytearc.DataStore(f"{dataset}/data.zarr", nthreads=4)
clustering_run = ds.pipeline.open(label="rna")
# Every clustering below divides the run's neighbor graph; the figures place cells on its UMAP.
graph = clustering_run["connectivity_map"]
umap = clustering_run["umap"]
# Report how many nearest neighbors each cell keeps in the graph.
neighbors_per_cell = ds.artifacts.inspect(clustering_run["neighbors"]).parameters["k"]
print(f"Nearest neighbors per cell: {neighbors_per_cell}")
# Show the store's analyzed cells, cell fields and assay.
dsNearest 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:
# Draw the saved clusters on the UMAP, with each cluster's number on its cells.
figure, axis = plt.subplots(figsize=(5, 5))
ds.plots.embedding(
layout=umap,
color_by=clustering_run["clusters"],
legend_loc="on_data",
target=axis,
show_titles=False,
show=False,
)
axis.set_title("Saved Leiden clusters, resolution 0.5")
plt.show()
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:
# Find the run's partition at 0.5, and partition the same graph at a lower and a higher resolution.
leiden_refs = {
0.3: ds.clusters.leiden(graph, resolution=0.3),
0.5: ds.artifacts.find("clusters", graph=graph, method="leiden", resolution=0.5),
0.8: ds.clusters.leiden(graph, resolution=0.8),
}
leiden_values = {
resolution: np.asarray(ds.artifacts.load(ref)["values"][:])
for resolution, ref in leiden_refs.items()
}
# Count the cells of each cluster at each resolution.
pd.DataFrame(
{
resolution: pd.Series(values).value_counts()
for resolution, values in leiden_values.items()
}
).fillna(0).astype(int).rename_axis(index="cluster", columns="resolution")| resolution | 0.3 | 0.5 | 0.8 |
|---|---|---|---|
| cluster | |||
| 1 | 1303 | 1217 | 646 |
| 2 | 704 | 704 | 509 |
| 3 | 612 | 528 | 447 |
| 4 | 321 | 474 | 408 |
| 5 | 319 | 283 | 301 |
| 6 | 256 | 256 | 296 |
| 7 | 239 | 239 | 287 |
| 8 | 142 | 166 | 257 |
| 9 | 25 | 29 | 242 |
| 10 | 15 | 25 | 234 |
| 11 | 12 | 15 | 153 |
| 12 | 0 | 12 | 67 |
| 13 | 0 | 0 | 30 |
| 14 | 0 | 0 | 25 |
| 15 | 0 | 0 | 19 |
| 16 | 0 | 0 | 15 |
| 17 | 0 | 0 | 12 |
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:
# Name each 0.3 and 0.8 cluster after the 0.5 cluster that holds most of its cells.
nested_refs = {
0.3: ds.clusters.relabel_by_overlap(leiden_refs[0.3], leiden_refs[0.5]),
0.5: leiden_refs[0.5],
0.8: ds.clusters.relabel_by_overlap(leiden_refs[0.8], leiden_refs[0.5]),
}
# Draw the three partitions on the same UMAP, with each cluster's name on its cells.
figure, axes = plt.subplots(1, 3, figsize=(13.5, 4.6))
for axis, (resolution, ref) in zip(axes, nested_refs.items(), strict=True):
ds.plots.embedding(
layout=umap,
color_by=ref,
legend_loc="on_data",
target=axis,
show_titles=False,
show=False,
)
axis.set_title(f"Leiden resolution {resolution}")
figure.tight_layout()
plt.show()
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.
# Score the agreement of each pair of resolutions.
pd.Series(
{
f"{first} vs {second}": ds.clusters.compute_concordance(
leiden_refs[first], leiden_refs[second]
)
for first, second in combinations(leiden_refs, 2)
},
name="ARI",
)0.3 vs 0.5 0.871655
0.3 vs 0.8 0.583116
0.5 vs 0.8 0.639142
Name: ARI, dtype: float64Started: 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:
# Measure the share of each cell's nearest neighbors in its own cluster at resolution 0.5.
chosen = leiden_refs[0.5]
chosen_values = leiden_values[0.5]
membership = ds.clusters.membership_strength(chosen, graph)
# Color the UMAP by membership strength on a fixed scale from 0 to 1, and name the scale.
figure, axis = plt.subplots(figsize=(5, 5.5))
ds.plots.embedding(
layout=umap,
color_by=membership,
color_scale=ColorScale(vmin=0, vmax=1),
target=axis,
show=False,
)
figure.axes[-1].set_xlabel("Membership strength, Leiden resolution 0.5")
plt.show()
# Count the cells with every neighbor in their cluster, and those with fewer than half.
strength = pd.Series(np.asarray(ds.artifacts.load(membership)["values"][:]))
weak = strength < 0.5
print(f"Cells with every neighbor in their own cluster: {(strength == 1).mean():.1%}")
print(f"Cells with fewer than half of their neighbors in it: {weak.sum()} ({weak.mean():.1%})")
# Summarize each cluster: its cells' mean strength, and its cells with fewer than half.
pd.DataFrame(
{
"cells": strength.groupby(chosen_values).size(),
"mean_strength": strength.groupby(chosen_values).mean().round(3),
"below_0.5": weak.groupby(chosen_values).sum(),
}
).rename_axis("cluster")
Cells with every neighbor in their own cluster: 87.0%
Cells with fewer than half of their neighbors in it: 37 (0.9%)
| cells | mean_strength | below_0.5 | |
|---|---|---|---|
| cluster | |||
| 1 | 1217 | 0.980 | 3 |
| 2 | 704 | 0.998 | 0 |
| 3 | 528 | 0.947 | 13 |
| 4 | 474 | 0.915 | 14 |
| 5 | 283 | 0.988 | 0 |
| 6 | 256 | 0.988 | 1 |
| 7 | 239 | 0.983 | 2 |
| 8 | 166 | 0.923 | 4 |
| 9 | 29 | 0.931 | 0 |
| 10 | 25 | 0.953 | 0 |
| 11 | 15 | 1.000 | 0 |
| 12 | 12 | 0.985 | 0 |
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:
# Draw the graph weight between clusters as edges between their median UMAP positions.
figure, axis = plt.subplots(figsize=(5, 5))
ds.plots.cluster_connectivity(
graph=graph,
groups=chosen,
layout=umap,
show_cells=True,
minimum_edge_weight=0.005,
target=axis,
show=False,
)
axis.set_title("Cluster connectivity, Leiden resolution 0.5")
plt.show()
# List the same pairs of clusters, the most strongly joined first.
connectivity = ds.clusters.connectivity(graph, chosen, minimum_edge_weight=0.005)
connectivity.edges.sort_values(
"normalizedWeight", ascending=False, ignore_index=True
).round(4)
| source | target | rawWeight | normalizedWeight | |
|---|---|---|---|---|
| 0 | 3 | 4 | 152.2791 | 0.0349 |
| 1 | 1 | 4 | 174.0105 | 0.0255 |
| 2 | 1 | 8 | 68.3278 | 0.0171 |
| 3 | 6 | 7 | 25.5358 | 0.0119 |
| 4 | 5 | 9 | 8.9497 | 0.0117 |
| 5 | 3 | 5 | 31.1288 | 0.0093 |
| 6 | 2 | 10 | 10.1313 | 0.0089 |
| 7 | 3 | 9 | 6.3126 | 0.0060 |
| 8 | 4 | 8 | 13.1777 | 0.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:
# Rank every gene as a marker of each cluster against the rest of the cells.
markers = ds.markers.search(chosen, features=clustering_run["feature_universe"])
# Load the markers of the largest and the smallest cluster, writing out the default filters.
sizes = pd.Series(chosen_values).value_counts()
largest, smallest = sizes.index[0], sizes.index[-1]
largest_markers = ds.markers.load(
marker=markers, group_id=largest, min_frac_exp=0.2, min_auc=0.6, max_p_adj=0.05
)
smallest_markers = ds.markers.load(
marker=markers, group_id=smallest, min_frac_exp=0.2, min_auc=0.6, max_p_adj=0.05
)
pd.DataFrame(
{"cluster": [largest, smallest], "cells": [sizes[largest], sizes[smallest]]},
index=["largest", "smallest"],
)| cluster | cells | |
|---|---|---|
| largest | 1 | 1217 |
| smallest | 12 | 12 |
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:
# Show the ten highest-scoring markers, with their detection inside and outside the cluster.
marker_columns = ["feature_name", "score", "auc", "frac_exp", "frac_exp_rest"]
largest_markers[marker_columns].head(10).round(3)| feature_name | score | auc | frac_exp | frac_exp_rest | |
|---|---|---|---|---|---|
| 0 | ADTRP | 0.552 | 0.609 | 0.241 | 0.025 |
| 1 | TSHZ2 | 0.454 | 0.636 | 0.325 | 0.054 |
| 2 | CHRM3-AS2 | 0.441 | 0.661 | 0.380 | 0.064 |
| 3 | FHIT | 0.433 | 0.777 | 0.624 | 0.100 |
| 4 | EPHX2 | 0.422 | 0.663 | 0.391 | 0.075 |
| 5 | CMTM8 | 0.405 | 0.616 | 0.302 | 0.076 |
| 6 | LRRN3 | 0.396 | 0.735 | 0.533 | 0.067 |
| 7 | NOG | 0.383 | 0.616 | 0.258 | 0.027 |
| 8 | MAL | 0.377 | 0.769 | 0.674 | 0.164 |
| 9 | GSTM3 | 0.359 | 0.604 | 0.278 | 0.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:
# Show the same statistics for the smallest cluster.
smallest_markers[marker_columns].head(10).round(3)| feature_name | score | auc | frac_exp | frac_exp_rest | |
|---|---|---|---|---|---|
| 0 | F13A1 | 0.820 | 1.000 | 1.000 | 0.061 |
| 1 | ACRBP | 0.807 | 0.958 | 0.917 | 0.014 |
| 2 | PTGS1 | 0.807 | 1.000 | 1.000 | 0.035 |
| 3 | CD9 | 0.799 | 1.000 | 1.000 | 0.033 |
| 4 | PRKAR2B | 0.798 | 1.000 | 1.000 | 0.011 |
| 5 | AP003068.2 | 0.797 | 0.958 | 0.917 | 0.016 |
| 6 | HIST1H3H | 0.794 | 0.957 | 0.917 | 0.020 |
| 7 | CLU | 0.788 | 1.000 | 1.000 | 0.011 |
| 8 | HIST1H2BJ | 0.783 | 0.872 | 0.750 | 0.026 |
| 9 | DMTN | 0.781 | 0.956 | 0.917 | 0.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:
# Cut the Paris hierarchy of the same graph adaptively, each branch at its own scale.
paris_auto = ds.clusters.paris(graph)
paris_result = ds.clusters.load_paris(paris_auto)
print(f"{paris_result.n_clusters} groups of at least {paris_result.min_cluster_size} cells")
# Tabulate each group's diagnostics and the Leiden 0.5 cluster that holds most of its cells.
overlap = pd.crosstab(paris_result.labels, chosen_values)
paris_table = pd.DataFrame([asdict(item) for item in paris_result.diagnostics])
paris_table = paris_table.set_index("label")[
["size", "persistence", "decision_margin", "forced"]
]
paris_table["leiden_cluster"] = overlap.idxmax(axis=1)
paris_table["leiden_share"] = overlap.max(axis=1) / overlap.sum(axis=1)
paris_table.round(3)14 groups of at least 12 cells
| size | persistence | decision_margin | forced | leiden_cluster | leiden_share | |
|---|---|---|---|---|---|---|
| label | ||||||
| 1 | 364 | 77.715 | 0.069 | False | 2 | 1.000 |
| 2 | 337 | 101.852 | 0.178 | False | 2 | 1.000 |
| 3 | 228 | 139.816 | 0.531 | False | 7 | 1.000 |
| 4 | 1340 | 385.114 | 0.076 | False | 1 | 0.881 |
| 5 | 287 | 57.863 | NaN | False | 5 | 0.986 |
| 6 | 424 | 60.828 | NaN | False | 3 | 0.939 |
| 7 | 143 | 111.030 | 0.688 | False | 8 | 0.972 |
| 8 | 125 | 56.563 | 0.365 | False | 3 | 1.000 |
| 9 | 264 | 51.631 | NaN | False | 6 | 0.958 |
| 10 | 352 | 145.942 | 0.253 | False | 4 | 0.923 |
| 11 | 28 | 21.416 | NaN | False | 10 | 0.893 |
| 12 | 15 | NaN | NaN | True | 11 | 1.000 |
| 13 | 12 | 11.855 | NaN | False | 12 | 1.000 |
| 14 | 29 | 19.326 | 0.653 | False | 9 | 1.000 |
Started: 2026-11-23T23:00:19.319445Z | Wall time: 0.847 s
# Draw the hierarchy above the selected Paris groups.
figure, axis = plt.subplots(figsize=(6, 6))
ds.plots.cluster_tree(graph=graph, clusters=paris_auto, ax=axis, show=False)
axis.set_title(f"Paris hierarchy above the {paris_result.n_clusters} adaptive groups")
plt.show()
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.
# Cut the same hierarchy at one height into as many groups, and compare the partitions.
paris_fixed = ds.clusters.paris(graph, n_clusters=paris_result.n_clusters)
pd.Series(
{
"Paris adaptive vs Paris fixed": ds.clusters.compute_concordance(
paris_auto, paris_fixed
),
"Leiden 0.5 vs Paris adaptive": ds.clusters.compute_concordance(
chosen, paris_auto
),
},
name="ARI",
)Paris adaptive vs Paris fixed 0.827808
Leiden 0.5 vs Paris adaptive 0.774565
Name: ARI, dtype: float64Started: 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:
# Read the run's recorded Leiden settings, each candidate's silhouette and the one selected.
leiden_settings = clustering_run.report()["run"]["config"]["stages"]["leiden"]
print(f"Leiden settings: {leiden_settings}")
selection = ds.artifacts.load(clustering_run["cluster_selection"])
print(f"Selected: {selection.attrs['selectedKey']}")
pd.Series(selection["scores"][:], index=selection.attrs["candidateKeys"], name="silhouette")Leiden settings: {'partitions': [0.5], 'selected': None}
Selected: 0.5
0.5 0.35302
Name: silhouette, dtype: float64Started: 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.