Compare four clusterings of the same 7,299 human peripheral blood mononuclear cells (PBMCs) from a healthy donor, measured for RNA and 14 surface proteins with CITE-seq (10x Genomics dataset tenx_8K_pbmc_citeseq). One clustering comes from RNA alone, one from the antibody-derived tags (ADTs) alone, and one from each of two joint graphs of the two assays, built by weighted nearest neighbors (WNN) and shared nearest neighbors (SNN). RNA and protein agree moderately, with an adjusted Rand index (ARI) of 0.58. Each joint clustering agrees with either assay at 0.69 to 0.74, and WNN and SNN agree with each other at 0.82.
The disagreements lie within lineages. Protein separates PD-1+ TIGIT+ memory CD4 T cells and CD25-high regulatory T cells that RNA groups with the other memory CD4 T cells, and RNA separates a subset of NK cells that protein does not. WNN keeps both kinds of split, and the cells of those clusters lean, on average, on the assay that separates them, with mean ADT weights of 0.72 and 0.68 for the PD-1+ TIGIT+ and regulatory T cells and 0.28 for the NK subset. SNN, which applies one rule to both assays, keeps the regulatory T cells apart but merges most cells of the other two populations into larger clusters: 57% of the PD-1+ TIGIT+ T cells into the memory CD4 T-cell cluster and 82% of the NK subset into the main NK cluster.
This page reopens the four runs saved in the prepared store. The CITE-seq tutorial introduces them, explains the modality weights and FeatureRef, and shows the calls that build such runs.
Open the four saved runs¶
# Import CyteArc, and pandas and Matplotlib for the comparison tables and figures.
from itertools import combinations
import matplotlib.pyplot as plt
import pandas as pd
import cytearc
from cytearc.plotting import FeatureRef
# Keep routine logs and progress bars out of the page.
cytearc.configure_output(level="WARNING", progress=False)
# Download the prepared CITE-seq store with its saved runs, and open it.
dataset = cytearc.datasets.connect("cytearc_docs").download_dataset(
"tenx_8K_pbmc_citeseq",
destination="cytearc_datasets",
zarr=True,
)
ds = cytearc.DataStore(f"{dataset}/data.zarr", default_assay="RNA", nthreads=4)
# Reopen the RNA, ADT, WNN and SNN runs by the labels they were saved under.
runs = {name: ds.pipeline.open(label=name.lower()) for name in ("RNA", "ADT", "WNN", "SNN")}
# Collect each run's cluster for every cell, matched by cell barcode.
clusters = pd.DataFrame(
{
name: run.cells.to_pandas_dataframe(["ids", "clusters"]).set_index("ids")["clusters"]
for name, run in runs.items()
}
)
# Read the Leiden resolution that each run recorded for its clusters.
resolution = {
name: run.report()["run"]["config"]["stages"]["leiden"]["partitions"][0]
for name, run in runs.items()
}
# Count the cells and clusters of each run, beside its Leiden resolution.
pd.DataFrame(
{"cells": clusters.count(), "clusters": clusters.nunique(), "Leiden resolution": resolution}
)| cells | clusters | Leiden resolution | |
|---|---|---|---|
| RNA | 7299 | 19 | 1.00 |
| ADT | 7299 | 18 | 1.00 |
| WNN | 7299 | 21 | 1.75 |
| SNN | 7299 | 19 | 1.75 |
Started: 2026-11-23T23:31:07.403804Z | Wall time: 9.510 s
All four runs analyze the same 7,299 cells. WNN finds 21 clusters, RNA and SNN 19 each, and ADT 18. The joint runs were clustered at a finer Leiden resolution than the single-assay runs, 1.75 against 1.0, so the cluster counts compare directly only between RNA and ADT, and between WNN and SNN. ds.pipeline.open(label=...) reopens a saved pipeline run by its label. The run’s cell view, run.cells, holds the values that the run saved for each cell, such as its cluster, and run.report() holds the settings that the run recorded. Indexing a run by an output name, as in run["clusters"] or run["umap"], returns an ArtifactRef to that saved result, which the comparison and plotting functions below take.
Measure how closely the clusterings agree¶
The adjusted Rand index (ARI) counts the pairs of cells that both clusterings place in the same cluster or both place in different clusters, corrected so that chance agreement scores about 0 and identical clusterings score 1. Normalized mutual information (NMI) measures from 0 to 1 how much one clustering tells about the other, without the correction for chance. Neither score depends on how the clusters are numbered. ds.clusters.compute_concordance computes both for two saved clusterings made on the same frozen cell selection, the recorded set of cells that a run analyzed. The four runs share one: the ADT run took its cells from the RNA run, and both joint runs combine those two runs:
# Score the agreement of each pair of clusterings with ARI and NMI.
concordance = []
for first, second in combinations(runs, 2):
pair = (runs[first]["clusters"], runs[second]["clusters"])
concordance.append(
{
"comparison": f"{first} vs {second}",
"ARI": ds.clusters.compute_concordance(*pair, metric="ari"),
"NMI": ds.clusters.compute_concordance(*pair, metric="nmi"),
}
)
pd.DataFrame(concordance).round(2)| comparison | ARI | NMI | |
|---|---|---|---|
| 0 | RNA vs ADT | 0.58 | 0.68 |
| 1 | RNA vs WNN | 0.71 | 0.80 |
| 2 | RNA vs SNN | 0.69 | 0.79 |
| 3 | ADT vs WNN | 0.72 | 0.79 |
| 4 | ADT vs SNN | 0.74 | 0.80 |
| 5 | WNN vs SNN | 0.82 | 0.87 |
Started: 2026-11-23T23:31:16.915040Z | Wall time: 0.374 s
RNA and protein agree least (ARI 0.58, NMI 0.68), and WNN and SNN most (ARI 0.82, NMI 0.87). Each joint clustering agrees better with either assay than the two assays agree with each other, so both joint graphs draw on RNA and protein. The scores say how much the clusterings differ but not where, so the next sections find the populations that the clusterings split differently.
See where RNA and protein split cells differently¶
Color each assay’s UMAP layout by the other assay’s clusters. A cluster that both assays find keeps one color on the other layout, and a population that only one assay splits shows mixed colors:
# Color each run's UMAP by the other run's clusters, so a split cluster shows as mixed colors.
def plot_cross_colored(first, second):
figure, axes = plt.subplots(1, 2, figsize=(9, 4))
for axis, layout, colors in ((axes[0], first, second), (axes[1], second, first)):
ds.plots.embedding(
layout=runs[layout]["umap"],
color_by=runs[colors]["clusters"],
legend_loc="on_data",
show_titles=False,
target=axis,
show=False,
)
axis.set_title(f"{layout} layout, {colors} clusters")
figure.tight_layout()
# Compare the RNA and ADT clusterings.
plot_cross_colored("RNA", "ADT")
Started: 2026-11-23T23:31:17.290471Z | Wall time: 0.363 s
Most clusters of one assay fall on a single island of the other assay’s layout, such as cluster 1 in both. Five populations differ, and the protein profiles in the next section identify them. On the ADT layout, RNA divides three islands: the NK cells into its clusters 4 and 13, the B cells into its clusters 10 and 12, and the memory CD4 T cells on the right into its clusters 2 and 9. RNA clusters 3, 5, 11 and 19 also interleave across the largest island, the CD14 monocytes. On the RNA layout, ADT clusters 2 and 5 interleave across the same monocytes, ADT clusters 4, 9 and 12 divide the memory CD4 T cells in the center, and ADT clusters 7 and 13 mix among the CD8 T cells left of the center.
Name the WNN clusters and the assay each one leans on¶
WNN gives every cell an RNA weight and an ADT weight that sum to 1. The CITE-seq tutorial explains how WNN sets the weights and shows that many cells put nearly all of their weight on one assay, so a cluster’s mean weight says more than any one cell’s. Draw each WNN cluster’s mean protein levels, z-scored per antibody across clusters so that each antibody’s highest clusters stand out, above the cluster’s mean ADT weight:
# Order the antibodies: T-cell lineage and state markers, then NK-cell, myeloid and B-cell markers.
panel = [
FeatureRef(marker, assay="ADT", by="id", label=marker)
for marker in (
"CD3", "CD4", "CD8a", "CD45RA", "CD45RO", "CD127", "CD25", "PD-1", "TIGIT",
"CD56", "CD16", "CD14", "CD15", "CD19",
)
]
# Average the ADT weight of the cells in each WNN cluster, matched by cell barcode.
weights = runs["WNN"].cells.to_pandas_dataframe(["ids", "weight_ADT"]).set_index("ids")
mean_adt_weight = weights["weight_ADT"].groupby(clusters["WNN"]).mean()
# Draw each WNN cluster's z-scored protein profile above its mean ADT weight, in one cluster order.
figure, (marker_axis, weight_axis) = plt.subplots(
2, 1, figsize=(9, 7.5), height_ratios=[3, 1], layout="constrained"
)
ds.plots.matrixplot(
features=panel,
groups=runs["WNN"]["clusters"],
standardize="feature",
group_order=mean_adt_weight.index.tolist(),
target=marker_axis,
show=False,
)
positions = range(len(mean_adt_weight))
weight_axis.bar(positions, mean_adt_weight.to_numpy(), color="0.45")
weight_axis.axhline(0.5, color="0.2", linestyle="--", linewidth=0.8)
weight_axis.set_xticks(positions, mean_adt_weight.index.astype(str))
weight_axis.set(
xlim=marker_axis.get_xlim(), ylim=(0, 1), xlabel="WNN cluster", ylabel="Mean ADT weight"
)
# Label the clusters once, under the bars.
marker_axis.set_xlabel("")
marker_axis.tick_params(labelbottom=False)
Started: 2026-11-23T23:31:17.654584Z | Wall time: 0.235 s
The protein profiles name the main WNN populations:
CD4 T cells (CD3 and CD4): naive in cluster 1 (CD45RA and CD127), memory in cluster 4 (CD45RO in place of CD45RA), PD-1+ TIGIT+ memory in cluster 10, and CD25-high with low CD127, the regulatory T-cell phenotype, in cluster 11.
CD8 T cells (CD3 and CD8a): naive in cluster 8, memory in clusters 7 and 9, and in cluster 13 a group with less CD8a and intermediate CD45RA and CD45RO.
NK cells (CD56 and CD16) in clusters 5 and 14.
B cells (CD19) in cluster 6.
CD14 monocytes in clusters 2 and 3, and CD16 monocytes in cluster 16.
Cluster 12 carries T-cell proteins (CD3, CD4) and myeloid proteins (CD14, CD16, CD15) together, the pattern of doublets or of cells that bind antibodies nonspecifically. The small clusters 18 and 21 pair the B-cell marker CD19 with the NK-cell marker CD56 or the monocyte marker CD14 in the same way.
Cluster 19, 32 cells with the panel’s highest CD15 alongside high CD14 and CD16, leans most on protein, with a mean ADT weight of 0.91. Among the T cells, the states that the panel measures directly lean most on protein: clusters 10 (PD-1 and TIGIT) and 11 (CD25), at 0.72 and 0.68. NK cluster 14 and the small clusters 15, 16 and 20 lean on RNA, at 0.28 to 0.37.
Trace each WNN cluster to the RNA, ADT and SNN clusters¶
For each WNN cluster, the table gives its size, its mean ADT weight, and the RNA, ADT and SNN clusters that hold the largest share of its cells. A share near 100% means that clustering keeps the WNN cluster’s cells together, and a cluster number that recurs down a column means that clustering merges those WNN clusters:
# Name the cluster that holds the largest share of a group of cells, with that share.
def largest_share(labels):
shares = labels.value_counts(normalize=True)
return f"{shares.index[0]} ({shares.iloc[0]:.0%})"
# Trace each WNN cluster: its size, mean ADT weight, and largest RNA, ADT and SNN clusters.
trace = clusters.groupby("WNN")[["RNA", "ADT", "SNN"]].agg(largest_share)
trace.insert(0, "cells", clusters["WNN"].value_counts())
trace.insert(1, "mean ADT weight", mean_adt_weight.round(2))
trace| cells | mean ADT weight | RNA | ADT | SNN | |
|---|---|---|---|---|---|
| WNN | |||||
| 1 | 1084 | 0.60 | 1 (98%) | 1 (97%) | 1 (96%) |
| 2 | 871 | 0.47 | 5 (65%) | 2 (52%) | 3 (87%) |
| 3 | 792 | 0.53 | 3 (84%) | 2 (75%) | 5 (85%) |
| 4 | 763 | 0.53 | 2 (58%) | 4 (92%) | 2 (97%) |
| 5 | 723 | 0.69 | 4 (98%) | 3 (99%) | 4 (100%) |
| 6 | 530 | 0.47 | 10 (62%) | 6 (96%) | 6 (100%) |
| 7 | 429 | 0.62 | 6 (94%) | 7 (79%) | 7 (96%) |
| 8 | 396 | 0.63 | 8 (95%) | 8 (94%) | 8 (93%) |
| 9 | 319 | 0.58 | 7 (97%) | 10 (87%) | 9 (94%) |
| 10 | 312 | 0.72 | 2 (75%) | 9 (89%) | 2 (57%) |
| 11 | 215 | 0.68 | 2 (82%) | 12 (88%) | 10 (99%) |
| 12 | 204 | 0.53 | 15 (51%) | 11 (53%) | 12 (63%) |
| 13 | 185 | 0.56 | 14 (76%) | 7 (39%) | 11 (96%) |
| 14 | 153 | 0.28 | 13 (95%) | 3 (80%) | 4 (82%) |
| 15 | 87 | 0.37 | 11 (78%) | 5 (74%) | 13 (92%) |
| 16 | 82 | 0.37 | 16 (96%) | 15 (80%) | 15 (96%) |
| 17 | 49 | 0.49 | 7 (71%) | 14 (92%) | 16 (100%) |
| 18 | 40 | 0.46 | 17 (100%) | 16 (85%) | 18 (100%) |
| 19 | 32 | 0.91 | 3 (47%) | 11 (88%) | 19 (84%) |
| 20 | 25 | 0.29 | 18 (96%) | 13 (88%) | 13 (100%) |
| 21 | 8 | 0.61 | 15 (100%) | 6 (100%) | 12 (100%) |
Started: 2026-11-23T23:31:17.890883Z | Wall time: 0.012 s
The table shows three kinds of disagreement:
Protein splits that RNA lacks. RNA cluster 2 holds most cells of WNN clusters 4, 10 and 11 (58%, 75% and 82%), while ADT gives each its own cluster (4, 9 and 12, each holding 88% to 92%). WNN keeps the protein split.
RNA splits that protein lacks. ADT cluster 3 holds both NK clusters, 99% of cluster 5 and 80% of cluster 14, while RNA separates them as its clusters 4 and 13. RNA cluster 14 likewise holds 76% of the CD8 T cells of WNN cluster 13, while protein spreads them over several clusters, with the largest share, 39%, in ADT cluster 7 among the memory CD8 T cells of WNN cluster 7. WNN keeps both RNA splits. RNA also divides the B cells, so RNA cluster 10 holds only 62% of WNN cluster 6, but WNN keeps them together as protein does, with 96% in ADT cluster 6.
Different splits of one population. Both assays split the CD14 monocytes in two, along different lines. RNA clusters 5 and 3 each hold most of one WNN monocyte cluster (65% and 84%), while ADT clusters 2 and 5 interleave across both, with ADT cluster 2 holding most of each (52% and 75%). WNN follows RNA there. RNA also divides the memory CD4 T cells along a line that protein does not draw, into its clusters 2 and 9 on the right-hand island of the ADT layout, which is why RNA cluster 2 holds only 58% of WNN cluster 4. WNN follows protein there.
Compare WNN with SNN¶
SNN builds each cell’s joint neighbors from its neighbors in both assays. It ranks every candidate neighbor by the edge weight plus the fraction of neighbors that the two cells share, applies the same rule to each assay, and keeps the highest-ranked ones. WNN instead weights each assay per cell. The prepared SNN run integrates the same RNA and ADT runs with ds.pipeline.multimodal([runs["RNA"], runs["ADT"]], method="snn") and the WNN run’s other settings. Color each method’s layout by the other method’s clusters, as for RNA and ADT above:
# Compare the WNN and SNN clusterings as RNA and ADT were compared above.
plot_cross_colored("WNN", "SNN")
Started: 2026-11-23T23:31:17.904403Z | Wall time: 0.325 s
SNN keeps the cells of most WNN clusters together: for 15 of the 21, one SNN cluster holds 90% or more of the cells, as the SNN column of the trace table shows. The methods differ most on two WNN clusters that each rest on one assay. On the SNN layout, WNN cluster 10, which protein separates, sits inside the island of WNN cluster 4, and WNN cluster 14, which RNA separates, forms the lower edge of the island of WNN cluster 5. Count how SNN divides the cells of these two WNN clusters:
# Show the SNN clusters that take more than 5% of WNN cluster 10 or 14, as shares of each WNN cluster.
split = pd.crosstab(clusters["WNN"], clusters["SNN"], normalize="index").loc[[10, 14]]
split.loc[:, split.max() > 0.05].map("{:.0%}".format)| SNN | 2 | 4 | 10 | 13 | 14 |
|---|---|---|---|---|---|
| WNN | |||||
| 10 | 57% | 0% | 13% | 0% | 29% |
| 14 | 0% | 82% | 0% | 16% | 0% |
Started: 2026-11-23T23:31:18.230850Z | Wall time: 0.010 s
SNN divides the PD-1+ TIGIT+ memory CD4 T cells of WNN cluster 10: it places 57% in its cluster 2, together with the memory CD4 T cells of WNN cluster 4, and keeps 29% apart as its cluster 14, the small group between SNN clusters 11 and 2 on the WNN layout. SNN places 82% of the NK subset of WNN cluster 14 in its NK cluster 4, together with the NK cells of WNN cluster 5, and the small WNN clusters 15 and 20, which lean on RNA, both fall into SNN cluster 13. Two populations that one assay separates stay apart in both methods: the regulatory T cells of WNN cluster 11, with 99% in SNN cluster 10, and the CD8 T cells of WNN cluster 13, with 96% in SNN cluster 11.
Choose an integration¶
Start with WNN, the default method of
ds.pipeline.multimodal. On this dataset WNN keeps both the PD-1+ TIGIT+ T cells and the NK subset as clusters of their own, while SNN merges most cells of each into a larger cluster.Build SNN from the same runs with
method="snn"as a check. A WNN cluster that SNN merges into a neighbor, as it does with most of WNN clusters 10 and 14, rests mostly on one assay. Confirm such a cluster with that assay’s markers, such as PD-1 and TIGIT protein for WNN cluster 10.Before naming a cluster that carries the proteins of several lineages at once, such as WNN clusters 12, 18 and 21, check the cluster for doublets, as Quality control and doublet detection shows, and for nonspecific antibody binding. SNN keeps each of these clusters together as well, with 63% to 100% of its cells in one SNN cluster, so changing the method does not remove such cells.
The chosen run already holds the joint UMAP and clusters. Its joint graph, run["integrated_graph"], goes to any later step that takes a graph, such as ds.clusters.leiden to recluster at another resolution. Both methods combine assays measured in the same cells and do not correct batch effects, which the Harmony batch correction tutorial covers. The integration API reference describes both algorithms and their inputs.