| name | bio-flow-cytometry-gating-analysis |
| description | Manual and automated gating for defining cell populations in flow cytometry. Covers rectangular, polygon, and data-driven gates. Use when identifying cell populations through hierarchical gating strategies. |
| tool_type | r |
| primary_tool | flowWorkspace |
Version Compatibility
Reference examples tested with: flowCore 2.14+
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.
Gating Analysis
"Gate my flow cytometry data to identify cell populations" → Define cell populations through manual or automated gating strategies using rectangular, polygon, or data-driven gates in a hierarchical framework.
- R:
flowWorkspace::gs_add_gating_method(), openCyto::gating() for automated gating
Manual Rectangular Gates
library(flowCore)
cd4_gate <- rectangleGate(filterId = 'CD4+',
'CD4' = c(500, Inf),
'CD3' = c(200, Inf))
cd4_result <- filter(fcs, cd4_gate)
summary(cd4_result)
cd4_cells <- Subset(fcs, cd4_gate)
Polygon Gates
vertices <- matrix(c(100, 100,
1000, 100,
1000, 1000,
100, 1000),
ncol = 2, byrow = TRUE)
colnames(vertices) <- c('FSC-A', 'SSC-A')
poly_gate <- polygonGate(filterId = 'Lymphocytes', .gate = vertices)
lymph <- Subset(fcs, poly_gate)
Gating Hierarchy (flowWorkspace)
library(flowWorkspace)
gs <- GatingSet(fs)
gs_pop_add(gs, cd4_gate, parent = 'root')
cd4_cd8_gate <- rectangleGate(filterId = 'CD8+', 'CD8' = c(500, Inf))
gs_pop_add(gs, cd4_cd8_gate, parent = 'CD4+')
gs_get_pop_paths(gs)
recompute(gs)
gs_pop_get_stats(gs)
Automated Gating: flowDensity
library(flowDensity)
cd4_gate <- deGate(fcs, channel = 'CD4', use.upper = TRUE)
cd4_threshold <- cd4_gate@min
cd4_pos <- flowDensity(fcs, channels = 'CD4', position = c(TRUE))
cd4_cells <- getflowFrame(cd4_pos)
Automated Gating: openCyto
Goal: Apply a reproducible, template-driven gating strategy that automatically identifies cell populations across all samples.
Approach: Define a CSV gating template specifying parent-child hierarchy, channel combinations, and gating algorithms (flowClust, singletGate, mindensity, quadrantGate), then apply the template to a GatingSet for batch processing.
library(openCyto)
gating_template <- fread('
alias,pop,parent,dims,gating_method,gating_args
nonDebris,+,root,FSC-A,flowClust,K=2
singlets,+,nonDebris,"FSC-A,FSC-H",singletGate,
lymph,+,singlets,"FSC-A,SSC-A",flowClust,K=3
cd3,+,lymph,CD3,mindensity,
cd4,+,cd3,"CD4,CD8",quadrantGate,
')
gt <- gatingTemplate(gating_template)
gs <- GatingSet(fs)
gating(gt, gs)
Quadrant Gates
quad_gate <- quadGate(filterId = 'CD4_CD8_quad',
'CD4' = 500,
'CD8' = 500)
Boolean Gates
cd4_not_cd8 <- cd4_gate & !cd8_gate
gs_pop_add(gs,
booleanFilter(CD4+CD8- = CD4+ & !CD8+),
parent = 'lymph')
Extract Gated Populations
cd4_data <- gh_pop_get_data(gs[[1]], 'CD4+')
cd4_indices <- gh_pop_get_indices(gs[[1]], 'CD4+')
gs_pop_get_count_fast(gs)
Visualization
library(ggcyto)
autoplot(gs[[1]], 'CD4+')
autoplot(gs[[1]], c('CD4+', 'CD8+'))
autoplot(fcs, 'CD4', 'CD8') +
geom_gate(cd4_gate)
Export Gating Strategy
save_gs(gs, 'gating_set')
library(CytoML)
gatingset_to_flowjo(gs, 'analysis.wsp')
Related Skills
- compensation-transformation - Preprocess before gating
- clustering-phenotyping - Unsupervised alternative
- differential-analysis - Compare gated populations