Clustering
Gating names the populations before it finds them. You decide there are T cells, then draw a gate for them. Clustering does the reverse: it groups events by the shape of their marker profile and lets the populations emerge from the data. FlowSOM is the standard tool, a self-organizing map that compresses the events into a grid of nodes and then meta-clusters the nodes into populations.
Why clustering and not gating
Section titled “Why clustering and not gating”Gating is interpretable and slow. You draw one gate at a time, and a 40-marker panel has hundreds of biaxial plots. Clustering is fast and unsupervised, and it finds populations a gate sequence would miss, because it does not commit to an order. The cost is that the clusters are not named until you annotate them, by looking at the median marker intensity in each cluster and calling it a cell type.
FlowSOM on the Bodenmiller panel
Section titled “FlowSOM on the Bodenmiller panel”The Bodenmiller BCR-XL data ships in HDCytoData on the raw scale. The example
arcsinh-transforms the surface markers, the channels whose names start with CD, and
asks FlowSOM for eight metaclusters.
library(flowCore)library(FlowSOM)library(HDCytoData)
fs <- Bodenmiller_BCR_XL_flowSet()markers <- grep("^CD", colnames(fs[[1]]), value = TRUE)
# Keep the untransformed events before transforming, because the Python tab# below applies its own transform and must not be handed transformed values.raw <- do.call(rbind, lapply(seq_len(length(fs)), function(i) { exprs(fs[[i]])[, markers, drop = FALSE]}))
# Arcsinh-transform the surface CD markers (cofactor 5).asinh_trans <- arcsinhTransform(a = 0, b = 1 / 5, c = 0)fs <- transform(fs, transformList(markers, tfun = asinh_trans))markers
set.seed(1)fom <- FlowSOM(fs, colsToUse = markers, nClus = 8, seed = 1)
# The number of metaclusters FlowSOM settled on.length(unique(fom$metaclustering))
# Hand the untransformed events to the Python tab, so both engines cluster the# same cells and each applies its own transform. 20000 of the 172791 events,# sampled with a seed, keeps the page quick.dir.create("outputs", showWarnings = FALSE, recursive = TRUE)set.seed(1)keep <- sort(sample(nrow(raw), 20000))write.csv(raw[keep, ], "outputs/cluster_events.csv", row.names = FALSE)nrow(raw)[1] "CD3(110:114)Dd" "CD45(In115)Dd" "CD4(Nd145)Dd" "CD20(Sm147)Dd"[5] "CD33(Nd148)Dd" "CD123(Eu151)Dd" "CD14(Gd160)Dd" "CD7(Yb176)Dd"[1] 8[1] 172791FlowSOM() builds the self-organizing map, assigns every event to a node, and
meta-clusters the nodes into the requested number of populations. The
metaclustering vector holds one label per SOM node. The number of distinct labels is
the number of populations the algorithm found.
Cluster medians
Section titled “Cluster medians”A cluster is identified by its median marker intensity. The table below is the annotation step: you read the medians and call each cluster a cell type.
# The SOM codebook: one row per node, one column per marker. FlowSOM 2.x# returns a flat object, so the map sits at the top level.node_codes <- fom$map$codesdim(node_codes)
# Median intensity per metacluster, across the surface markers.meta <- fom$metaclusteringcluster_medians <- t(sapply(sort(unique(meta)), function(g) { apply(node_codes[meta == g, , drop = FALSE], 2, median)}))round(cluster_medians, 2)[1] 100 8 CD3(110:114)Dd CD45(In115)Dd CD4(Nd145)Dd CD20(Sm147)Dd CD33(Nd148)Dd[1,] 3.50 5.41 3.63 0.17 0.09[2,] 1.40 5.29 2.24 0.85 0.50[3,] 1.28 5.14 0.08 0.11 0.03[4,] 1.87 5.36 0.60 0.23 1.40[5,] 2.11 5.32 0.18 0.13 0.04[6,] -0.10 2.21 0.16 0.16 0.07[7,] 0.99 3.62 0.62 0.39 0.34[8,] 0.23 5.02 0.25 4.23 0.59 CD123(Eu151)Dd CD14(Gd160)Dd CD7(Yb176)Dd[1,] -0.08 0.06 2.79[2,] 0.23 0.43 0.11[3,] -0.08 0.18 3.79[4,] 2.25 1.39 0.49[5,] -0.08 0.11 0.25[6,] 0.13 0.40 0.23[7,] 4.25 0.76 0.57[8,] 0.06 0.36 0.28Cluster 1 is high on CD3, CD4 and CD7, which is a CD4 T cell. Cluster 8 is the only one high on CD20, so it is the B cell cluster, and the BCR-XL stimulation in this dataset acts on those cells. Cluster 4 carries CD33, CD123 and CD14 together, which is myeloid. Cluster 6 sits low on everything including CD45, so it is debris rather than a cell type. The medians are the evidence; the names are the interpretation you write beside them.
A UMAP projection
Section titled “A UMAP projection”FlowSOM’s nodes live in a high-dimensional marker space. A UMAP projection drops them into two dimensions so you can see how the clusters relate, which ones sit close because they share markers and which ones sit apart.
library(uwot)
set.seed(1)node_umap <- umap(node_codes, n_neighbors = 8, min_dist = 0.1, seed = 1)head(node_umap) [,1] [,2][1,] -4.597413 -0.51866809[2,] -5.577594 0.09192019[3,] -4.634599 -0.66788874[4,] -5.161691 -0.42374516[5,] -4.714157 0.03685798[6,] -3.756753 -0.53402088library(ggplot2)
dir.create("outputs", showWarnings = FALSE, recursive = TRUE)
umap_df <- data.frame( umap1 = node_umap[, 1], umap2 = node_umap[, 2], metacluster = factor(meta))
umap_plot <- ggplot(umap_df, aes(x = umap1, y = umap2, color = metacluster)) + geom_point(size = 2.5, alpha = 0.9) + labs( title = "The 100 SOM nodes, coloured by metacluster", x = "UMAP 1", y = "UMAP 2" ) + theme_minimal()
ggsave("outputs/cyto-umap-nodes.png", plot = umap_plot, width = 6, height = 5, dpi = 110, bg = "white")
Four of the eight metaclusters sit in their own region, which is what you hope to see. Metaclusters 4 and 5 do not. They interleave through the middle of the projection, and a few of the metacluster 5 nodes sit inside metacluster 1 on the far left.
That is the honest part of the picture. The boundary between two populations is a gradient, the metaclustering step had to cut it somewhere, and the cut it made does not correspond to a gap in the data. A table of medians would have shown eight tidy rows and hidden this completely.
The projection is of the SOM nodes, not the raw events, so it is fast even on a large file. Each point is a node, coloured by its metacluster. The clustering page and the gating page are two answers to the same question, and a real study uses both: gating for the populations you already know, clustering for the ones you do not.
The same clustering in Python
Section titled “The same clustering in Python”R is where the cytometry stack lives, but it is not the only place FlowSOM exists.
pytometry puts a cytometry layer on top of AnnData and scanpy: it reads FCS, carries
the cytometry transforms, and implements the FlowSOM algorithm against the original Van
Gassen paper.
Both tabs below cluster the same 20000 events, exported by the R tab above on the raw scale, so each engine applies its own transform to identical input.
# Population sizes as a percentage of events. The two engines clustered a# different number of events, so percentages are what compare.r_events <- FlowSOM::GetMetaclusters(fom)round(100 * prop.table(table(r_events)), 1)r_events 1 2 3 4 5 6 7 832.1 5.5 27.9 5.9 19.5 2.2 1.2 5.6import anndata as adimport numpy as npimport pandas as pdimport pytometry as pmfrom sklearn.cluster import AgglomerativeClustering
events = pd.read_csv("outputs/cluster_events.csv")adata = ad.AnnData(events.values.astype("float32"))adata.var_names = list(events.columns)print(adata.shape)
# pytometry carries the cytometry transform, the same arcsinh with cofactor 5# that the R tab applies through flowCore.pm.tl.normalize_arcsinh(adata, cofactor=5)x = np.asarray(adata.X)
# The self-organising map, seeded, then the metaclustering as a separate step.# pm.tl.flowsom_clustering does both in one call and this page does not use it,# for the reason below.som = pm.tl.som_clustering(x, som_dim=(10, 10), seed=1)codes = som.get_weights().reshape(-1, x.shape[1])node = np.array([np.ravel_multi_index(som.winner(row), (10, 10)) for row in x])
# Eight metaclusters, the number the R tab was given, so the two compare.meta = AgglomerativeClustering(n_clusters=8).fit_predict(codes)adata.obs["cluster"] = pd.Categorical(meta[node])
sizes = adata.obs["cluster"].value_counts().sort_index()print(len(sizes))print((100 * sizes / sizes.sum()).round(1).to_string())(20000, 8)8cluster0 24.81 8.62 9.43 15.64 7.75 9.16 12.87 12.0Both tabs are told to make eight metaclusters, so the comparison is of the partitions rather than of the counts.
Why this page does not call flowsom_clustering
Section titled “Why this page does not call flowsom_clustering”pytometry offers pm.tl.flowsom_clustering, which does the map and the metaclustering in
one call and picks the number of clusters for you by consensus resampling. This page used it
first, and the output gate caught the problem: the same script returned six clusters on one
run and eight on the next, with entirely different sizes.
The cause is in consensusclustering, which resamples with
np.random.default_rng(None). That draws entropy from the operating system and ignores
np.random.seed, Python’s random.seed, and the seed argument
flowsom_clustering accepts, which reaches the map and not the resampler. Setting
min_clusters equal to max_clusters does not avoid it either; sklearn rejects that
because it leaves both n_clusters and distance_threshold unset.
So the page takes the two steps separately. pm.tl.som_clustering accepts a seed and is
deterministic, and the metaclustering runs as a plain agglomerative fit with the number of
clusters named. Three separate container runs return identical cluster sizes.
None of that makes the one-call function wrong for exploratory work. It makes it unusable on a page that promises the numbers beside the code came from the code.
# What each Python cluster is, read the same way as the R medians above.frame = pd.DataFrame(adata.X, columns=list(adata.var_names))frame["cluster"] = adata.obs["cluster"].to_numpy()print(frame.groupby("cluster").median().round(2).to_string()) CD3(110:114)Dd CD45(In115)Dd CD4(Nd145)Dd CD20(Sm147)Dd CD33(Nd148)Dd CD123(Eu151)Dd CD14(Gd160)Dd CD7(Yb176)Ddcluster0 3.33 5.26 3.60 -0.01 -0.06 -0.10 -0.03 3.251 3.06 5.37 -0.07 -0.04 -0.06 -0.08 -0.04 4.032 0.35 5.25 1.19 2.99 0.57 -0.02 0.22 -0.063 0.08 4.99 -0.07 -0.05 -0.07 -0.10 0.11 3.684 1.91 5.40 0.10 -0.04 0.87 1.24 1.65 0.375 0.01 4.61 -0.01 0.03 0.01 -0.05 -0.01 -0.036 3.29 5.42 3.00 0.01 -0.06 -0.10 -0.03 0.437 3.06 5.38 -0.05 -0.06 -0.09 -0.11 -0.04 1.88The Python projection
Section titled “The Python projection”The R tab projects the 100 SOM nodes. scanpy projects the events themselves, which is the
usual workflow on the Python side and shows something the node projection cannot: how many
cells sit between two populations rather than how many nodes do.
A projection coloured by cluster_0 and cluster_1 tells a reader nothing. The
cell identification page scores clusters
against a table of marker rules in R, and the same rules apply here.
import matplotlibmatplotlib.use("Agg")import scanpy as sc
# The same expectations the R rule table carries, keyed on the bare marker.rules = { "CD4 T cells": {"CD3": "pos", "CD4": "pos", "CD20": "neg"}, "CD4 negative T": {"CD3": "pos", "CD4": "neg", "CD7": "pos"}, "B cells": {"CD20": "pos", "CD3": "neg"}, "Monocytes": {"CD14": "pos", "CD33": "pos", "CD3": "neg"}, "Dendritic cells": {"CD123": "high", "CD14": "neg", "CD3": "neg"}, "NK cells": {"CD7": "pos", "CD3": "neg", "CD20": "neg"}, "Debris": {"CD45": "neg", "CD3": "neg", "CD20": "neg"},}
# The channel names carry the metal tag, so key them on the part before the# bracket. Splitting on "(" keeps CD3 and CD33 apart, which a prefix match# would not.by_marker = {c.split("(")[0]: c for c in adata.var_names}
medians = frame.groupby("cluster").median()scaled = (medians - medians.min()) / (medians.max() - medians.min())
def score_cluster(row, expectations): """Score one cluster against one cell type's expectations.
Args: row: The cluster's scaled median for every marker. expectations: Marker name to "pos", "neg" or "high".
Returns: The weighted mean score, so a rule naming more markers is not rewarded for it. """ total, weight = 0.0, 0.0 for marker, expectation in expectations.items(): value = row[by_marker[marker]] if expectation == "pos": total += value weight += 1 elif expectation == "high": total += 2 * value weight += 2 else: total += 1 - value weight += 1 return total / weight
scores = pd.DataFrame( {name: scaled.apply(score_cluster, axis=1, expectations=rule) for name, rule in rules.items()})labels = scores.idxmax(axis=1)margins = scores.apply( lambda r: r.nlargest(2).iloc[0] - r.nlargest(2).iloc[1], axis=1)
annotation = pd.DataFrame({"cell_type": labels, "margin": margins.round(3)})print(annotation.to_string())
adata.obs["cell_type"] = adata.obs["cluster"].map(labels).astype("category")
sc.settings.figdir = "outputs"sc.pp.neighbors(adata, n_neighbors=15)sc.tl.umap(adata)sc.pl.umap(adata, color="cell_type", show=False, save="_pytometry.png")print(adata.obsm["X_umap"].shape) cell_type margincluster0 CD4 T cells 0.3911 CD4 negative T 0.2822 B cells 0.3703 NK cells 0.1294 Monocytes 0.2025 Debris 0.3316 CD4 T cells 0.5097 CD4 negative T 0.155(20000, 2)
Names instead of numbers is the whole difference. Eight clusters carry six labels, because two of them are CD4 T cells and two are CD4 negative T cells, which is what a panel with no CD8 marker can resolve. The B cells sit as a separate island, and the T cell populations meet along a populated boundary rather than a gap, which is what forced the metaclustering step to cut somewhere.
The margins are worth reading against the picture rather than on their own. The largest, 0.509, belongs to a CD4 T cell cluster, and the smallest, 0.129, belongs to the NK cells at the lower right. That NK label is correct: CD3 0.08 with CD7 3.68 and no CD20 is an NK cell. A small margin means two rules scored similarly, not that the winner is wrong.
The label that is wrong
Section titled “The label that is wrong”One label is wrong, and it is not the one with the smallest margin. The cluster in the
upper right is called debris on a margin of 0.331, and its CD45 median is 4.61, which is
high. It only scores as negative because the scaling runs each marker from the lowest
cluster to the highest, so neg means “the lowest of the eight clusters here” rather than
“below the positive population”.
That is the flaw in scoring against scaled medians, and it bites hardest when the rule table names a population the data does not contain. This subsample holds no real debris, so the debris rule went to whichever cluster sat lowest and produced a confident looking margin while doing it. The margin measures how far the best rule beat the second best, not whether the best rule was right at all.
A rule table needs its neg expectations anchored to a control or to a fixed threshold
before those labels stand on their own. Read the medians beside them until they are.
The same clustering in Seurat
Section titled “The same clustering in Seurat”Seumetry is to Seurat what pytometry is to scanpy. It stores the events in a Seurat
object, the container Seurat uses for single-cell RNA-seq, so Seurat’s scaling, PCA,
neighbour graph and Louvain clustering run on cytometry data as they are. It starts from FCS
files in a folder and a table that names each file, not from a flowSet in memory. The fence
below therefore writes the 16 Bodenmiller samples to disk on the raw scale and lets Seumetry
read them back.
library(Seumetry)
# Seumetry reads FCS files from a folder and a table that names each file, so# write the 16 samples out on the raw scale first.fs_raw <- Bodenmiller_BCR_XL_flowSet()fcs_dir <- "outputs/fcs"dir.create(fcs_dir, showWarnings = FALSE, recursive = TRUE)for (file_name in sampleNames(fs_raw)) { write.FCS(fs_raw[[file_name]], file.path(fcs_dir, file_name))}
# One row per file. The file name carries the patient and the condition.sample_id <- gsub("^PBMC8_30min_|\\.fcs$", "", sampleNames(fs_raw))metadata <- data.frame( file_name = sampleNames(fs_raw), sample_id = sample_id, patient = sub("_.*$", "", sample_id), condition = sub("^.*_", "", sample_id))fcs_fs <- create_flowset(fcs_dir, metadata)
# read.flowSet makes the channel names syntactic, so CD3(110:114)Dd becomes# CD3.110.114.Dd. The panel maps each surface channel to a bare antigen name.surface <- grep("^CD", colnames(fcs_fs), value = TRUE)panel <- data.frame( fcs_colname = surface, antigen = sub("\\..*$", "", surface), arcsinh_cofactor = 5)seu <- create_seurat(fcs_fs, panel, metadata)
# Each cell is named after its sample, so the 20000 events the other engines# clustered can be picked out by name.n_events <- as.vector(fsApply(fs_raw, nrow))pooled_names <- paste0(rep(sample_id, n_events), "_", sequence(n_events) - 1)seu <- subset(seu, cells = pooled_names[keep])raw_counts <- as.matrix(LayerData(seu, assay = "fcs", layer = "counts"))identical(unname(t(raw_counts[, pooled_names[keep]])), unname(raw[keep, ]))
seu <- transform_data(seu, "arcsinh")seu[1] TRUEAn object of class Seurat39 features across 20000 samples within 2 assaysActive assay: fcs (8 features, 0 variable features) 2 layers present: counts, data 1 other assay present: unusedread.flowSet turns each channel name into a syntactic R name, so the panel has to use
CD3.110.114.Dd rather than the name the instrument wrote. create_seurat then names every
cell after its sample, from patient1_BCR-XL_0 upwards, and those names select the 20000
events that the first R fence sampled. The TRUE says the raw values inside the Seurat
object are exactly the values the other two engines were given. The counts layer keeps
them, and transform_data writes the arcsinh values, with the cofactor of 5 from the panel,
to the data layer.
An outlier score before clustering
Section titled “An outlier score before clustering”Seumetry’s quality control scores every event with an isolation forest from isotree. The
score reflects how few random splits it takes to isolate the event, so an event far from
the rest scores high.
seu <- detect_outliers(seu, score_threshold = 0.7)sum(seu$outlier)round(max(seu$outlier_score), 3)sum(seu$outlier_score > 0.6)[1] 0[1] 0.656[1] 8No event passes the default threshold of 0.7. The highest of the 20000 scores is 0.656, and a threshold of 0.6 flags only 8 events, 0.04 percent of the file, so the page removes nothing and the three engines keep identical input. The vignette describes the forest on ungated flow data, where it mainly removes events near the axes, doublets and debris.
The score only measures how isolated an event is. A group of 465 events that share one low CD45 profile is not isolated, and the Louvain section below finds exactly such a group. Read the outlier flag as a check for stray events, not as a debris gate.
FlowSOM through Seumetry
Section titled “FlowSOM through Seumetry”# Seumetry hands the Seurat object to FlowSOM as a flowFrame. FlowSOM gets the# seed itself, for the reason in the next section.ff <- convert_seurat(seu, to = "FF")fom_seurat <- FlowSOM(ff, colsToUse = panel$antigen, nClus = 8, seed = 1)seu$metacluster <- GetMetaclusters(fom_seurat)round(100 * prop.table(table(seu$metacluster)), 1)round(t(median_expression(seu, group_by = "metacluster")), 2) 1 2 3 4 5 6 7 819.1 9.3 6.2 4.8 24.6 4.1 23.4 8.5 CD3 CD45 CD4 CD20 CD33 CD123 CD14 CD71 0.26 4.99 -0.05 -0.04 -0.06 -0.10 0.06 3.782 0.11 5.02 0.14 -0.01 0.00 -0.06 0.11 -0.043 0.11 5.09 0.01 3.80 0.34 -0.05 -0.01 -0.044 1.28 5.14 0.39 -0.03 0.57 2.75 1.07 0.205 3.05 5.37 -0.02 -0.05 -0.08 -0.10 -0.03 2.286 1.62 5.39 1.44 0.47 2.07 0.01 1.63 -0.047 3.45 5.30 3.67 -0.01 -0.06 -0.10 -0.03 3.188 3.33 5.43 3.45 0.17 -0.06 -0.08 -0.04 0.23convert_seurat turns the arcsinh layer into a flowFrame whose channels carry the antigen
names, and FlowSOM() then runs as it does in the first R fence, with eight metaclusters and
seed = 1. median_expression takes the median over the events of each metacluster, as the
Python medians do, and not over the SOM nodes as the R medians do.
Metacluster 7 is the CD4 T cell profile, at CD3 3.45, CD4 3.67 and CD7 3.18. Metacluster 8 holds CD4 T cells that are low on CD7, at 0.23, and the two together make 31.9 percent of the events, against 32.1 percent for R’s metacluster 1 on all 172791. Metacluster 3 is the B cells at CD20 3.80.
This run has no low CD45 metacluster. Every median sits at CD45 4.99 or above, while the R run kept 2.2 percent of its events in metacluster 6 at CD45 2.21. The Louvain section shows where those events went.
Why this page does not call run_FlowSOM
Section titled “Why this page does not call run_FlowSOM”Seumetry has its own run_FlowSOM(), which builds the map and the metaclustering from the
Seurat object in one call. In version 0.2.2 it calls
metaClustering_consensus(fSOM$map$codes, k = metaclusters) with no seed. FlowSOM 2.20.0
passes seed = NULL on to ConsensusClusterPlus 1.76.0, and ConsensusClusterPlus replaces a
missing seed with as.numeric(Sys.time()). Two container runs of the same script, each with
set.seed(1) just before the call, put different numbers of events into the same
metaclusters. The extra arguments of run_FlowSOM() go to BuildSOM() and never reach the
metaclustering, so no argument fixes it.
The clock seed reaches further than the metaclusters. ConsensusClusterPlus calls set.seed()
on the whole session, so every random step after run_FlowSOM() in the same script changes
from run to run as well. The function also stores the metacluster as a factor with one level
per SOM node, and table() on it lists 100 levels, 92 of them empty, for eight
metaclusters.
The fix is the one the pytometry section uses. Take the two steps apart, and give the seed to the step that needs it.
Louvain in Seurat
Section titled “Louvain in Seurat”FlowSOM is the cytometry engine. Louvain on a shared nearest neighbour graph is the Seurat one, and it is the reason to put the events in a Seurat object in the first place.
seu <- ScaleData(seu, features = rownames(seu), verbose = FALSE)seu <- RunPCA(seu, features = rownames(seu), npcs = 8, approx = FALSE, verbose = FALSE)seu <- FindNeighbors(seu, dims = 1:8, verbose = FALSE)seu <- FindClusters(seu, resolution = 0.5, verbose = FALSE)nlevels(seu$seurat_clusters)
# Size and median profile of each Louvain cluster, in cluster order.louvain <- seu$seurat_clusterslouvain_medians <- t(median_expression(seu, group_by = "seurat_clusters"))cbind(pct = round(100 * as.vector(prop.table(table(louvain))), 1), round(louvain_medians[levels(louvain), ], 2))
# Where FlowSOM put the events of the low CD45 Louvain cluster.table(seu$metacluster[louvain == "13"])[1] 14 pct CD3 CD45 CD4 CD20 CD33 CD123 CD14 CD70 12.3 3.41 5.27 3.34 -0.07 -0.10 -0.13 -0.08 3.001 9.5 1.56 5.34 0.97 0.21 1.81 0.30 0.98 -0.012 9.3 1.65 5.21 -0.06 -0.05 -0.07 -0.11 1.45 3.363 8.9 2.87 5.32 -0.09 -0.08 -0.10 -0.13 -0.08 3.254 8.4 1.42 5.16 -0.01 -0.05 -0.06 1.94 0.12 1.005 7.9 3.39 5.29 3.55 -0.01 -0.07 -0.12 1.41 2.766 7.1 3.21 5.27 2.70 1.65 -0.01 -0.11 -0.08 3.137 7.0 -0.17 4.98 -0.06 -0.04 -0.09 -0.12 -0.07 3.688 7.0 1.35 5.42 0.02 -0.01 -0.07 -0.11 -0.02 -0.049 6.4 0.10 5.07 0.02 3.77 0.34 -0.06 0.01 -0.0410 5.2 2.90 5.28 1.56 -0.02 1.32 -0.12 -0.05 3.4511 5.2 3.32 5.43 3.07 0.06 -0.08 -0.12 -0.08 0.0912 3.3 3.49 5.30 3.66 -0.05 -0.08 1.64 -0.01 2.7913 2.3 -0.25 2.29 -0.03 -0.04 -0.06 -0.10 -0.02 0.33
1 2 3 4 5 6 7 8 96 359 0 0 4 2 4 0Louvain takes no cluster count. The resolution sets how finely the neighbour graph is cut, and the vignette’s 0.5 cuts these 20000 events into 14 clusters. Cluster 13 is the low CD45 group, 2.3 percent of the events at CD45 2.29, next to R’s 2.2 percent at 2.21. On the same events, FlowSOM put 359 of those 465 into metacluster 2, the CD45 positive events that are negative for every lineage marker, and 96 into metacluster 1, the NK cells.
Three Louvain clusters pair a CD4 T cell profile with a marker from another lineage. Cluster 6 carries CD20 at 1.65, cluster 5 carries CD14 at 1.41, and cluster 12 carries CD123 at 1.64. A T cell profile with a second lineage marker is what a doublet looks like, so check a cluster like these on a biaxial plot before you give it a name. The isolation forest above flagged none of their events.
Reading the three results
Section titled “Reading the three results”The marker profiles are the thing to compare, not the labels, and on the same arcsinh scale
they line up. Python’s cluster_0 sits at CD3 3.33, CD4 3.60 and CD7 3.25, which is R’s
metacluster 1 at 3.50, 3.63 and 2.79. Seumetry’s metacluster 7 sits at 3.45, 3.67 and 3.18,
and Louvain’s cluster 0 at 3.41, 3.34 and 3.00. Four clusterings in three engines found the
same CD4 T cell population and gave it four different names.
The numbering carries no meaning across the engines, and neither does the count on its own.
Louvain’s 14 clusters and FlowSOM’s eight come from a resolution of 0.5 and an nClus of 8,
and a person chose both. What transfers is the profile.
Scientific references
Section titled “Scientific references”Van Gassen and colleagues, 2015 describe FlowSOM, which uses self-organizing maps to visualize and interpret cytometry data.
Weber and Soneson, 2019 describe HDCytoData, a collection of high-dimensional cytometry benchmark datasets in Bioconductor formats.
The flowCore package by Ellis and colleagues supplies the basic data structures for flow cytometry in R.
The uwot package by Melville implements UMAP dimensionality reduction in R.
Büttner and colleagues, 2022 describe Pytometry for flow and mass cytometry analytics in Python in a preprint.
Wolf, Angerer, and Theis, 2018 describe Scanpy, the Python toolkit for large-scale single-cell expression analysis.
Borggrewe and colleagues, 2026 describe Seumetry, an R toolkit that runs flow and mass cytometry analysis inside Seurat.
Hao and colleagues, 2023 describe the Seurat methods for integrative, multimodal, and scalable single-cell analysis.
Further reading
Section titled “Further reading”The FlowSOM documentation describes map construction, the requested metacluster count, and seed arguments. Consult the FlowSOM and GetMetaclusters references before you compare node labels with event labels. The HDCytoData documentation describes the paired samples and markers behind the shared input to both implementations.
The Seumetry tutorial runs the full workflow on spectral flow data, from the panel table to compensation, aggregate removal and the differential abundance and expression tests that this page leaves out. Its aggregate step looks for antibody aggregates, the diagonal streaks between two correlated channels, which is a different artefact from the doublet-like Louvain clusters above.