library(openCyto)
## Loading required package: flowWorkspace
## Loading required package: flowCore
## Loading required package: ncdfFlow
## Loading required package: RcppArmadillo
## Loading required package: BH
library(ggcyto)
## Loading required package: ggplot2

Prepare the data for openCyto gating

data("GvHD")
fs <- GvHD[1:2]
gs <- GatingSet(fs)
## ..done!
gh <- gs[[1]]
trans <- estimateLogicle(gh, markernames(gh))
gs <- transform(gs, trans)

Build csv gating template incrementally

dt <- add_pop(gs, alias = "cd15+"
          , dims = "cd15"
          , parent = "root"
          , gating_method = "mindensity"
          , gating_args = "")
## ...
## done
autoplot(gs, "cd15+", y = "FSC-H")
## Warning: Removed 24 rows containing missing values (geom_hex).

Grab the subpopulation to draw the gate with CytoGate

library(CytoGate)
## Loading required package: flowDensity
## Warning: replacing previous import 'flowCore::plot' by 'graphics::plot'
## when loading 'flowDensity'
## Loading required package: DescTools
fs <- getData(gs, "cd15+")
fr <- as(fs, "flowFrame")#collapse samples into single flowFrame
fr <- Subset(fr, sampleFilter(size = 1e3))#random subsample data as needed
gateobj <- DrawGate(fr, channels = c("FSC-H", "SSC-H"), gate_type = "ellipse")
## Select at 4 points to define limits of the ellipsoidGate.
gateobj

## A list of 1 filters applied to a flowFrame.

write the dummy gating method that simply returns the given gate through argument ‘gate’

gate_manual <- function(fr, pp_res, channels, gate){
  
  return(gate)
}
registerPlugins(gate_manual, "gate_manual")
## Registered gate_manual
## [1] TRUE

continue to build csv template by passing the gate to the dummy gating method

row <- add_pop(gs, alias = "L"
              , dims = "FSC-H,SSC-H"
              , parent = "cd15+"
              , gating_method = "gate_manual"
              , gating_args = list(gate = gateobj)
              )
## ...
## done
autoplot(gs, "L") + ggcyto_par_set(limits = "data")
## Warning: Removed 25 rows containing missing values (geom_hex).

dt <- rbind(dt, row)

save the template

csvfile <- tempfile()
write.csv(dt, file = csvfile)

load it back to apply to the other samples

gt <- gatingTemplate(csvfile)
## Adding population:cd15+
## Adding population:L
plot(gt)
## Warning in brewer.pal(nMethods, name = "Dark2"): minimal value for n is 3, returning requested palette with 3 different levels

fs <- GvHD[1:4]
gs <- GatingSet(fs)
## .
## ...done!
gh <- gs[[1]]
trans <- estimateLogicle(gh, markernames(gh))
gs <- transform(gs, trans)

gating(gt, gs)
## Gating for 'cd15+'
## done.
## Gating for 'L'
## done.
## finished.
autoplot(gs, "L")
## Warning: Removed 64 rows containing missing values (geom_hex).