Unsupervised clustering and cell type identification for flow/mass cytometry. Covers FlowSOM, Phenograph, and CATALYST workflows. Use when discovering cell populations in high-dimensional cytometry data without predefined gates.
Before using code patterns, verify installed versions match. If versions differ:
R: packageVersion('<pkg>') then ?function_name to verify parameters
If code throws ImportError, AttributeError, or TypeError, introspect the installed
package and adapt the example to match the actual API rather than retrying.
Clustering and Phenotyping
"Cluster my cytometry data to find cell types" → Discover cell populations in high-dimensional flow/mass cytometry data using unsupervised clustering without predefined gates.
R: FlowSOM::FlowSOM() for self-organizing map clustering
R: CATALYST::cluster() with Phenograph or FlowSOM
FlowSOM Clustering
Goal: Cluster cytometry events into cell populations using self-organizing maps.
Approach: Build a FlowSOM grid on marker channels, then extract metacluster assignments per cell.
Goal: Quantify the relative frequency of each cell population across samples and conditions.
Approach: Cross-tabulate cluster assignments by sample ID, convert to proportions, and plot grouped by condition.
# Cluster frequencies per sample
abundances <- table(cluster_ids(sce, 'meta20'), sce$sample_id)
freq <- prop.table(abundances, margin = 2)
# Plot
plotAbundances(sce, k = 'meta20', by = 'cluster_id', group_by = 'condition')
Marker Expression Summary
Goal: Summarize and compare marker expression levels across clusters and conditions.
Approach: Plot per-cluster median expression with CATALYST's plotClusterExprs and pseudo-bulk expression faceted by cluster.
# Median expression per cluster
plotClusterExprs(sce, k = 'meta20', features = 'type')
# Expression by cluster and condition
plotPbExprs(sce, k = 'meta20', features = 'type', facet_by = 'cluster_id')
Export Results
Goal: Save clustering results and annotated SCE object for downstream analysis or sharing.
Approach: Extract cluster assignments into colData, export as CSV, and serialize the full SCE as RDS.
# Add cluster info to metadata
colData(sce)$cluster <- cluster_ids(sce, 'meta20')
# Export to CSV
results <- as.data.frame(colData(sce))
write.csv(results, 'clustering_results.csv', row.names = FALSE)
# Save SCE
saveRDS(sce, 'sce_clustered.rds')
Choosing Number of Clusters
Goal: Determine the optimal number of metaclusters for the dataset.
Approach: Compare normalized reduction stability (NRS) plots and heatmaps at different K values to find where clusters remain distinct.
# Delta area plot
plotNRS(sce, features = 'type')
# Or visual inspection of heatmap at different K
plotExprHeatmap(sce, features = 'type', by = 'cluster_id', k = 'meta10')
plotExprHeatmap(sce, features = 'type', by = 'cluster_id', k = 'meta20')
Batch Integration
Goal: Remove batch effects from cytometry data before or after clustering.
Approach: Detect batch effects by coloring UMAP by batch variable, then apply MNN correction with batchelor if needed.
# If batch effects present
library(batchelor)
sce <- runDR(sce, dr = 'UMAP', features = 'type')
# Check for batch effects
plotDR(sce, 'UMAP', color_by = 'batch')
# MNN correction if needed
sce_corrected <- fastMNN(sce, batch = sce$batch)
Related Skills
gating-analysis - Manual alternative
differential-analysis - Compare clusters between conditions
single-cell/clustering - Similar concepts for scRNA-seq