A GatingSet object can be exported as a GatingML file or GatingML-based wsp flowJo workspace (version 10) so that they can be loaded into Cytobank or flowJo.

The GatingSet to be exported can be either parsed from Cytobank or flowJo or created by automated gating algorithms from openCtyo. Here we will demontrate the latter.

0.1 Automated gating

0.1.1 Load raw FCS files into GatingSet

library(flowWorkspace)
library(CytoML)
dataDir <- system.file("extdata",package="flowWorkspaceData")
#load raw FCS
fs <- read.ncdfFlowSet(file.path(dataDir,"CytoTrol_CytoTrol_1.fcs"))
gs <- GatingSet(fs)

0.1.2 Compensate and transform

#compensate
comp <- spillover(fs[[1]])[["SPILL"]]
chnls <- colnames(comp)
comp <- compensation(comp)
gs <- compensate(gs, comp)

#transform
trans <- flowJo_biexp_trans()
trans <- transformerList(chnls, trans)
gs <- transform(gs, trans)

Note that the compensation and transformation must be applied directly to GatingSet instead of flowSet/ncdfFlowSet so that these information will be stored in the GatingSet object and exported to gatingML eventually.

0.1.3 Load the gating template and run auto gating

library(openCyto)
#load the original template for tcell panel
tbl <- data.table::fread(system.file("extdata/gating_template/tcell.csv", package = "openCyto"))
#modify some paramters to fit the current data range
tbl[5, gating_args:= "gate_range = c(1e3, 3e3)"]
##             alias              pop    parent        dims gating_method
##  1:     nonDebris        nonDebris      root       FSC-A    mindensity
##  2:      singlets         singlets nonDebris FSC-A,FSC-H   singletGate
##  3:         lymph            lymph  singlets FSC-A,SSC-A     flowClust
##  4:           cd3              cd3     lymph         CD3    mindensity
##  5:             *     cd4-/+cd8+/-       cd3     cd4,cd8    mindensity
##  6: activated cd4        CD38+HLA+  cd4+cd8-    CD38,HLA      tailgate
##  7: activated cd8        CD38+HLA+  cd4-cd8+    CD38,HLA      tailgate
##  8:      CD45_neg          CD45RA-  cd4+cd8-      CD45RA    mindensity
##  9:     CCR7_gate            CCR7+  CD45_neg        CCR7     flowClust
## 10:             * CCR7+/-CD45RA+/-  cd4+cd8- CCR7,CD45RA       refGate
## 11:             * CCR7+/-CD45RA+/-  cd4-cd8+ CCR7,CD45RA    mindensity
##                  gating_args collapseDataForGating groupBy
##  1:                                             NA      NA
##  2:                                             NA      NA
##  3:    K=2,target=c(1e5,5e4)                    NA      NA
##  4:                                           TRUE       4
##  5: gate_range = c(1e3, 3e3)                    NA      NA
##  6:                                             NA      NA
##  7:                 tol=0.08                    NA      NA
##  8:        gate_range=c(2,3)                    NA      NA
##  9:              neg=1,pos=1                    NA      NA
## 10:       CD45_neg:CCR7_gate                    NA      NA
## 11:                                             NA      NA
##     preprocessing_method preprocessing_args
##  1:                                      NA
##  2:                                      NA
##  3:      prior_flowClust                 NA
##  4:                                      NA
##  5:                                      NA
##  6:  standardize_flowset                 NA
##  7:  standardize_flowset                 NA
##  8:                                      NA
##  9:                                      NA
## 10:                                      NA
## 11:                                      NA
tbl[c(8,11), gating_args:= "gate_range = c(2e3, 3e3)"]
##             alias              pop    parent        dims gating_method
##  1:     nonDebris        nonDebris      root       FSC-A    mindensity
##  2:      singlets         singlets nonDebris FSC-A,FSC-H   singletGate
##  3:         lymph            lymph  singlets FSC-A,SSC-A     flowClust
##  4:           cd3              cd3     lymph         CD3    mindensity
##  5:             *     cd4-/+cd8+/-       cd3     cd4,cd8    mindensity
##  6: activated cd4        CD38+HLA+  cd4+cd8-    CD38,HLA      tailgate
##  7: activated cd8        CD38+HLA+  cd4-cd8+    CD38,HLA      tailgate
##  8:      CD45_neg          CD45RA-  cd4+cd8-      CD45RA    mindensity
##  9:     CCR7_gate            CCR7+  CD45_neg        CCR7     flowClust
## 10:             * CCR7+/-CD45RA+/-  cd4+cd8- CCR7,CD45RA       refGate
## 11:             * CCR7+/-CD45RA+/-  cd4-cd8+ CCR7,CD45RA    mindensity
##                  gating_args collapseDataForGating groupBy
##  1:                                             NA      NA
##  2:                                             NA      NA
##  3:    K=2,target=c(1e5,5e4)                    NA      NA
##  4:                                           TRUE       4
##  5: gate_range = c(1e3, 3e3)                    NA      NA
##  6:                                             NA      NA
##  7:                 tol=0.08                    NA      NA
##  8: gate_range = c(2e3, 3e3)                    NA      NA
##  9:              neg=1,pos=1                    NA      NA
## 10:       CD45_neg:CCR7_gate                    NA      NA
## 11: gate_range = c(2e3, 3e3)                    NA      NA
##     preprocessing_method preprocessing_args
##  1:                                      NA
##  2:                                      NA
##  3:      prior_flowClust                 NA
##  4:                                      NA
##  5:                                      NA
##  6:  standardize_flowset                 NA
##  7:  standardize_flowset                 NA
##  8:                                      NA
##  9:                                      NA
## 10:                                      NA
## 11:                                      NA
#write the new template to disc
gtFile <- tempfile()
write.csv(tbl, file = gtFile)
##reload the new template
gt <- gatingTemplate(gtFile, autostart = 1L)
#run the gating
gating(gt, gs)
#hide the gates that are not of interest
toggle.helperGates(gt, gs)
#visualize the gates
library(ggcyto)
autoplot(gs[[1]])

0.2 Export to Cytobank

outFile <- tempfile(fileext = ".xml")
GatingSet2cytobank(gs, outFile)
## [1] "/tmp/RtmpgRo01X/file4bce732eaa47.xml"

Note that the resulted xml file is a standard GatingML2.0 file with some additional custom_info added so that it can be recognized by Cytobank. Here is the example gate plot from Cytobank after the gatingML is imported. Gates in Cytobank

0.3 Export to FlowJo

outFile <- tempfile(fileext = ".wsp")
GatingSet2flowJo(gs, outFile)
## [1] "/tmp/RtmpgRo01X/file4bce121d1f48.wsp"

The resutled wsp file is a XML-based flowJo workspace and can be loaded into flowJo(V10) along with orginal FCS files.Here is the gate plots from flowJo after it is imported. Gates in flowJo