Automated unitary gating of CyCIF markers
This vignette walks through a complete Randkluft analysis using the bundled example dataset (exemplar-001--unmicst_cell.csv), from file upload through gate estimation, visual inspection, manual refinement, phenotyping, and export.
Randkluft is built around a single core idea: in marker distributions from multiplexed imaging, true-positive cells form a small right-skewed tail attached to a large symmetric background population. The algorithm isolates this tail by iteratively trimming the upper bound of the distribution until the remaining sub-distribution reaches zero skewness — the point at which only the background remains. The trim boundary at that moment is the gate.
shiny::runApp("app.R")https://irscope.shinyapps.io/Randkluft/
Navigate to the Randkluft tab to begin.
Randkluft expects a cell-by-marker CSV file. Each row represents one cell, and columns contain:
imageid— sample or patient identifierX_centroid,Y_centroid— spatial coordinates- One column per marker (e.g.
CD3,CD20,SOX10,ELANE)
imageid,X_centroid,Y_centroid,CD3,CD20,SOX10,ELANE,...
LSP11350,312.4,185.2,4.1,3.8,12.7,5.1,...
LSP11350,314.1,188.0,3.9,4.2,8.4,4.8,...
...
Marker values may be raw fluorescence intensities or pre-log-transformed values. Randkluft automatically log-transforms raw data (values > 20) on upload.
DNA / Hoechst / DAPI channels are detected by column name pattern and masked automatically.
- Open the Upload file tab in the sidebar.
- Click Browse and select
exemplar-001--unmicst_cell.csv. - Alternatively, click the here link to download this file from within the app.
- Wait for the notification "File Ready for Use" to appear in the bottom-right corner.
The app will:
- Detect the sample identifier column (
imageid) - Log-transform intensities if needed
- Auto-populate the marker checklist and patient selector
- Navigate to the Randkluft sub-tab inside the sidebar (Essential section).
- All detected markers are pre-selected. Deselect any markers you do not wish to gate.
- All patients are pre-selected. Deselect specific patients if needed.
- Click the Randkluft button.
A progress bar labelled "Randkluft in Action…" tracks completion. When finished, a confirmation dialog reads "Randkluft Found".
For each marker × patient pair:
- Remove top and bottom 1% outliers.
- Compute the skewness of the full distribution.
- If skewness < 0 (negatively skewed), fall back to a two-component Gaussian Mixture Model gate.
- Otherwise, perform binary search on the upper bound
bof the distribution, shrinking it untilskewness(data[data < b]) ≈ 0(tolerance α = 0.01, maximum 100 iterations). - The converged
bis returned as the gate.
Enable the Show gates toggle to activate histogram rendering.
Each view shows a 4-panel layout:
| Panel | Content |
|---|---|
| Top-left | Marker histogram with the estimated gate (red line) |
| Top-right | Digital representation — spatial map coloured by marker intensity |
| Bottom-left | Positive cells — red/grey spatial overlay based on gate |
| Bottom-right | Positive density — kernel density contour of gate-positive cells |
Use the Next/Previous Patient and Next/Previous Marker buttons to page through all combinations.
If the automated gate is unsatisfactory for a particular marker:
- With the histogram visible, type a new threshold into the Type Gate Value field.
- Click Update Gate.
- The histogram and all four panels update immediately with the new gate.
- The revised gate is saved into the gate table, and is reflected in all downloads.
Navigate to the Bivariate sub-tab. Select X and Y markers and a patient. A scatter plot appears showing:
- Per-cell density (colour-coded)
- Vertical and horizontal gate lines
- Quadrant proportions annotated in red (+/+), green (+/−), blue (−/+), and black (−/−)
Below the scatter plot, per-marker spatial overlays show the gate-positive cells for each axis separately.
Update either gate using the Enter Gate fields and Update Gates button.
The Trivariate sub-tab provides an interactive 3-D scatter plot for three simultaneous markers.
Navigate to Extra → Phenotyping.
Upload a two-column CSV defining cell types and their marker criteria:
phenotype,markers
"CD4+ T cells","CD3+, CD4+, CD45+"
"Cytotoxic T cells","CD3+, CD8+, CD45+"
"B cells","CD20+, CD45+"
"Macrophages","CD68+, CD45+"
An example file (phenotype_table_help.csv) is provided. Click here inside the app to download it.
Alternatively, use the checkbox interface:
- Check the markers that define a phenotype.
- Toggle the switch beside each marker to
+(positive) or−(negative). - Enable Any positive if at least one positive marker is sufficient (OR logic instead of AND).
- Type a phenotype name.
- Click Add phenotype definition.
Repeat for each cell type.
Click Phenotype my data. The app assigns phenotypes to every cell, annotates the original data table with a phenotype column, and displays:
- A summary table of phenotype definitions
- A stacked bar chart of phenotype proportions
- A Partition Diversity Estimate (MLE) summarising compositional diversity
- Download Phenotyped Data — the original CSV with a
phenotypecolumn appended. - Download Workflow — the phenotype definition table for reproducibility.
Click Download Gate Estimates to download a CSV table:
Patient,Marker,Gate
LSP11350,CD3,8.12
LSP11350,CD20,7.84
...
- Download Current Plot — downloads a PDF of the four-panel view currently displayed (histogram + spatial panels).
- Download All Plots — downloads a multi-page PDF with one four-panel page per marker × patient combination.
Note: "Show gates" must be toggled ON and plots must be visible before "Download Current Plot" is available.
The bundled file exemplar-001--unmicst_cell.csv contains a subset of the MCMICRO exemplar dataset (CyCIF, Harvard Medical School). It has a single patient (Patient1) and 27 marker channels.
Suggested workflow:
1. Upload exemplar-001--unmicst_cell.csv
2. Click Randkluft with all markers selected
3. Toggle Show gates ON
4. Page through markers using Next Marker
5. Identify any gate that looks misplaced (e.g. DNA channels if not masked)
6. Adjust manually using Type Gate Value
7. Download Gate Estimates CSV
8. Upload phenotype_table_help.csv in the Phenotyping tab
9. Click Phenotype my data
10. Download Phenotyped Data
| Symptom | Likely cause | Solution |
|---|---|---|
| Proportions or cell counts are zero | Marker is negatively skewed — no positive tail | Inspect manually and set gate by hand |
| "Disconnected from server" on upload | File does not match expected format | Check that imageid, X_centroid, Y_centroid columns exist |
| Slow upload or gating | File has many unused columns | Remove spatial or DNA columns before upload |
| Download Current Plot produces no file | Show gates not yet activated | Toggle Show gates ON and wait for plots to render |
| Gates look identical across markers | All markers already log-transformed and near zero | Confirm data is correctly formatted |
sessionInfo()
# R version 4.4.x or later recommended
# Key packages: shiny, ggplot2, gridExtra, dplyr, moments, multimode, mclustAmiryousefi A. et al. Randkluft: automated unitary gating of CyCIF markers. Bioinformatics (under review).
Contact: ali_amiryousefi@hms.harvard.edu