library(openCyto)
packageVersion("openCyto")
## [1] '1.20.0'
#load gs
dataDir <- system.file("extdata",package="flowWorkspaceData")
gs <- load_gs(list.files(dataDir, pattern = "gs_manual",full = TRUE))
#clear existing gates
Rm("not debris", gs)
#use add_pop convenient wrapper to build gating scheme interactively
df <- add_pop(gs, pop = "+/-+/-", parent = "root", dims = "CD4,CD8", gating_method = "mindensity")
#viz the gates, quadrants look correct
plotGate(gs[[1]], getNodes(gs)[-(1:3)])

df#it is in the compact format
##    alias    pop parent    dims gating_method gating_args
## 1:     * +/-+/-   root CD4,CD8    mindensity          NA
##    collapseDataForGating groupBy preprocessing_method preprocessing_args
## 1:                    NA      NA                   NA                 NA
#expand it and save it to csv
df <- openCyto:::.preprocess_csv(df)
## expanding pop: +/-+/-
tmp <- tempfile()
write.csv(df, tmp, row.names = F)
#now it is in the verbose format with all the refGate entries
data.table::fread(tmp)[, 1:6, with = F]
##       alias pop parent    dims gating_method         gating_args
## 1:     CD4+   +   root     CD4    mindensity                    
## 2:     CD8+   +   root     CD8    mindensity                    
## 3: CD4+CD8+  ++   root CD4,CD8       refGate root/CD4+:root/CD8+
## 4: CD4-CD8+  -+   root CD4,CD8       refGate root/CD4+:root/CD8+
## 5: CD4+CD8-  +-   root CD4,CD8       refGate root/CD4+:root/CD8+
## 6: CD4-CD8-  --   root CD4,CD8       refGate root/CD4+:root/CD8+
#load it back to gt
gt <- gatingTemplate(tmp)
#clear the quadrants
for(node in getNodes(gs)[-(1:3)])
  Rm(node, gs)
#rerun the gating for refGate
gating(gt, gs)
#quadrants still look corrent
plotGate(gs[[1]], getNodes(gs)[-(1:3)])