| Title: | Interactive Cluster Selector for Cytometry Data |
|---|---|
| Description: | CySA provides an interactive Shiny-based tool for analyzing flow and mass cytometry data. It supports self-organizing map (SOM) based clustering, dimension reduction (t-SNE, UMAP, PCA), and statistical comparison of cell populations across sample groups. Users can select cell clusters interactively via 2D scatter plots, dendrograms, or SOM node grids, and explore marker expression patterns across the selected populations. |
| Authors: | Bernd Jagla [aut, cre] (ORCID: <https://orcid.org/0000-0002-7696-0484>) |
| Maintainer: | Bernd Jagla <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.99.28 |
| Built: | 2026-09-29 07:52:29 UTC |
| Source: | https://github.com/bioc/CySA |
Creates an interactive Shiny dashboard for selecting and visualizing clusters from a SingleCellExperiment object.
clusterSelector( sce, sce_subsampled, outputList = list(), colTree = NULL, dList, dend, dendTable, clusterPatientTable, somCodesName = "SOM_codes", nPlots = 6, somRasterData, somRasterObj, fsom = NULL, env = environment(), verbose = FALSE )clusterSelector( sce, sce_subsampled, outputList = list(), colTree = NULL, dList, dend, dendTable, clusterPatientTable, somCodesName = "SOM_codes", nPlots = 6, somRasterData, somRasterObj, fsom = NULL, env = environment(), verbose = FALSE )
sce |
A |
sce_subsampled |
A subsampled |
outputList |
A named list of cluster groupings. |
colTree |
Optional collapsible tree object. |
dList |
List of marker pairs for 2D plots. |
dend |
Dendrogram object. |
dendTable |
Data frame for dendrogram navigation. |
clusterPatientTable |
Table of sample by cluster counts. |
somCodesName |
Name of the SOM codes metadata slot. |
nPlots |
Number of 2D SOM plots to display. |
somRasterData |
Data frame for SOM raster visualization. |
somRasterObj |
Raster object for SOM visualization. If |
fsom |
Optional |
env |
Environment used to store mutable state (legacy argument). |
verbose |
Logical indicating whether to show detailed runtime messages. |
A shinyApp object. Launch the app with
shiny::runApp(app).
sce <- CySA_example_sce() prepped <- prepClusterSelectorData(sce, total_cells_to_sample = 100) som_codes <- S4Vectors::metadata(sce)$SOM_codes dend <- stats::as.dendrogram(stats::hclust(stats::dist(som_codes))) dendTable <- data.frame( id = seq_len(nrow(som_codes)), label = rownames(som_codes), stringsAsFactors = FALSE ) clusterPatientTable <- table( sample_id = sce$sample_id, cluster_id = sce$cluster_id ) markers <- S4Vectors::metadata(sce)$map$colsUsed somRasterData <- data.frame( x = rep(seq_len(5), length.out = nrow(som_codes)), y = rep(seq_len(2), each = nrow(som_codes) / 2), id = seq_len(nrow(som_codes)) ) for (m in markers) { somRasterData[[m]] <- seq_len(nrow(som_codes)) / nrow(som_codes) } arr <- array( data = seq_len(10 * 10 * length(markers)), dim = c(10, 10, length(markers)) ) somRasterObj <- raster::brick(arr) names(somRasterObj) <- markers app <- clusterSelector( sce = prepped$sce, sce_subsampled = prepped$sce_subsampled, dList = prepped$dList, dend = dend, dendTable = dendTable, clusterPatientTable = clusterPatientTable, somRasterData = somRasterData, somRasterObj = somRasterObj ) if (interactive()) { shiny::runApp(app) }sce <- CySA_example_sce() prepped <- prepClusterSelectorData(sce, total_cells_to_sample = 100) som_codes <- S4Vectors::metadata(sce)$SOM_codes dend <- stats::as.dendrogram(stats::hclust(stats::dist(som_codes))) dendTable <- data.frame( id = seq_len(nrow(som_codes)), label = rownames(som_codes), stringsAsFactors = FALSE ) clusterPatientTable <- table( sample_id = sce$sample_id, cluster_id = sce$cluster_id ) markers <- S4Vectors::metadata(sce)$map$colsUsed somRasterData <- data.frame( x = rep(seq_len(5), length.out = nrow(som_codes)), y = rep(seq_len(2), each = nrow(som_codes) / 2), id = seq_len(nrow(som_codes)) ) for (m in markers) { somRasterData[[m]] <- seq_len(nrow(som_codes)) / nrow(som_codes) } arr <- array( data = seq_len(10 * 10 * length(markers)), dim = c(10, 10, length(markers)) ) somRasterObj <- raster::brick(arr) names(somRasterObj) <- markers app <- clusterSelector( sce = prepped$sce, sce_subsampled = prepped$sce_subsampled, dList = prepped$dList, dend = dend, dendTable = dendTable, clusterPatientTable = clusterPatientTable, somRasterData = somRasterData, somRasterObj = somRasterObj ) if (interactive()) { shiny::runApp(app) }
Returns the default 20-color palette used by CySA for cluster visualizations.
CySA_default_cluster_cols()CySA_default_cluster_cols()
A character vector of hex colors.
CySA_default_cluster_cols()CySA_default_cluster_cols()
Creates a small, deterministic SingleCellExperiment object that
contains the metadata and column data expected by CySA functions.
CySA_example_sce(n_cells = 1000, n_nodes = 50, n_markers = 12)CySA_example_sce(n_cells = 1000, n_nodes = 50, n_markers = 12)
n_cells |
Number of cells (columns). |
n_nodes |
Number of SOM nodes. |
n_markers |
Number of markers (rows). |
A SingleCellExperiment with
SOM_codes, SOM_stats, sample_id, and
cluster_id.
sce <- CySA_example_sce() head(S4Vectors::metadata(sce)$SOM_codes)sce <- CySA_example_sce() head(S4Vectors::metadata(sce)$SOM_codes)
Generates a 2-D scatter / density / colored point plot for a
SingleCellExperiment.
plotCytoScatter( x, chs, gate = NULL, color_by = NULL, facet_by = NULL, bins = 100, assay = "exprs", label = c("target", "channel", "both"), zeros = FALSE, k_pal = NULL, rownms = NULL )plotCytoScatter( x, chs, gate = NULL, color_by = NULL, facet_by = NULL, bins = 100, assay = "exprs", label = c("target", "channel", "both"), zeros = FALSE, k_pal = NULL, rownms = NULL )
x |
A |
chs |
Character vector of one or two markers/channels to plot. More than two channels will be melted and faceted. |
gate |
Currently unused. |
color_by |
Optional column name used to color points. |
facet_by |
Optional column name used for faceting. |
bins |
Number of bins for the 2-D histogram (default 100). |
assay |
Assay name to use (default |
label |
Axis label style: |
zeros |
Logical: if |
k_pal |
Color palette used when |
rownms |
Optional character vector used instead of |
A ggplot object.
sce <- CySA_example_sce() plotCytoScatter(sce, chs = c("marker1", "marker2"))sce <- CySA_example_sce() plotCytoScatter(sce, chs = c("marker1", "marker2"))
Bivariate scatter plots including visualization of (group-specific) gates, their boundaries and percentage of selected cells.
plotSOMScatter( x, chs, metaSlot = "SOM_codes", pointSize = "n", color_by = "n", bins = 100, assay = "exprs", statsSlot = "SOM_stats", label = c("target", "channel", "both"), zeros = FALSE, k_pal = NULL, xRN = NULL, xCN = NULL )plotSOMScatter( x, chs, metaSlot = "SOM_codes", pointSize = "n", color_by = "n", bins = 100, assay = "exprs", statsSlot = "SOM_stats", label = c("target", "channel", "both"), zeros = FALSE, k_pal = NULL, xRN = NULL, xCN = NULL )
x |
|
chs |
character vector specifying which channels to plot. |
metaSlot |
name of the metadata slot containing SOM codes. |
pointSize |
column in SOM stats used to size points. |
color_by |
column to color points by. |
bins |
number of bins when coloring by density. |
assay |
name of the assay to use. |
statsSlot |
name of the metadata slot containing SOM stats. |
label |
how axis labels should be constructed. |
zeros |
logical specifying whether to include 0 values. |
k_pal |
optional cluster color palette. |
xRN |
optional row names. |
xCN |
optional channel names. |
a ggplot object.
sce <- CySA_example_sce() plotSOMScatter(sce, chs = c("marker1", "marker2"))sce <- CySA_example_sce() plotSOMScatter(sce, chs = c("marker1", "marker2"))
Wrapper that takes a post-SOM SingleCellExperiment, builds all
supporting data structures required by clusterSelector, and
saves a sce.shiny.RData bundle compatible with the original
prepCytoApp output.
prepClusterSelector( currentRoot, sce = NULL, useColTree = FALSE, somCodesName = "SOM_codes", clusterColName = "cluster_id", total_cells_to_sample = 1e+05, dList = NULL, assay = "exprs", verbose = TRUE, force = FALSE, outputList = NULL, seed = 123, subsampledSCEFile = NULL )prepClusterSelector( currentRoot, sce = NULL, useColTree = FALSE, somCodesName = "SOM_codes", clusterColName = "cluster_id", total_cells_to_sample = 1e+05, dList = NULL, assay = "exprs", verbose = TRUE, force = FALSE, outputList = NULL, seed = 123, subsampledSCEFile = NULL )
currentRoot |
Character string specifying the project root directory.
Output files are written to |
sce |
A |
useColTree |
Logical indicating whether to create a collapsible tree. |
somCodesName |
Name of the SOM codes metadata slot. |
clusterColName |
Column name containing cluster IDs. |
total_cells_to_sample |
Number of cells to subsample for the Shiny app. |
dList |
Optional list of marker pairs for 2D plots. |
assay |
Name of the assay to use. |
verbose |
Logical indicating whether to print progress messages. |
force |
Logical indicating whether to force recomputation. |
outputList |
Optional output list to include in the saved bundle. |
seed |
Random seed for subsampling. |
subsampledSCEFile |
Optional path to a previously subsampled SCE object
(for example |
The function performs the following steps:
Subsample the SCE using prepClusterSelectorData(), or reuse a
previously subsampled SCE file if subsampledSCEFile is provided.
Update cluster_id to a factor with all SOM clusters as levels.
Build the cluster-by-patient table.
Recompute missing SOM code means.
Build SOM summary stats and cluster-level stats.
Build SOM raster data.
Build hierarchical clustering dendrogram and table.
Save sce.shiny.RData.
The path currentRoot.
Subsamples a SingleCellExperiment object and builds the inputs
required by clusterSelector.
prepClusterSelectorData( sce, somFile = NULL, dList = NULL, total_cells_to_sample = 1e+05, somCodesName = "SOM_codes", assay = "exprs", seed = 123 )prepClusterSelectorData( sce, somFile = NULL, dList = NULL, total_cells_to_sample = 1e+05, somCodesName = "SOM_codes", assay = "exprs", seed = 123 )
sce |
A |
somFile |
Path to the SOM object. Used to cache/restore the subsampled version. |
dList |
Optional list of marker pairs for 2D plots. If |
total_cells_to_sample |
Number of cells to subsample in total. |
somCodesName |
Name of the SOM codes metadata slot. |
assay |
Name of the assay to use. |
seed |
Random seed for reproducibility. |
A list with sce, sce_subsampled, and dList.
sce <- CySA_example_sce(n_cells = 200, n_nodes = 10) prepped <- prepClusterSelectorData(sce, total_cells_to_sample = 100) names(prepped) sce <- CySA_example_sce() # prepClusterSelector(sce, ...)sce <- CySA_example_sce(n_cells = 200, n_nodes = 10) prepped <- prepClusterSelectorData(sce, total_cells_to_sample = 100) names(prepped) sce <- CySA_example_sce() # prepClusterSelector(sce, ...)