library(flowWorkspace)
## As part of improvements to flowWorkspace, some behavior of
## GatingSet objects has changed. For details, please read the section
## titled "The cytoframe and cytoset classes" in the package vignette:
## 
##   vignette("flowWorkspace-Introduction", "flowWorkspace")
gs <- load_gs("~/mylib/R-devel-build/library/flowWorkspaceData/extdata/gs_bcell_auto/")
gs <- gs_clone(gs)
library(parallel)

GatingSet does not work with clusters due to the non-exportable external pointer

cl <- makeCluster(2, outfile = "")
clusterExport(cl, "gs")
clusterApply(cl, sampleNames(gs), function(sn){
  suppressPackageStartupMessages(library(flowWorkspace))
  head(gh_pop_get_stats(gs[[sn]], path = "auto"))
  })
## Error in checkForRemoteErrors(val): 2 nodes produced errors; first error: external pointer is not valid

construct new gs object that has on-disk pb file

gsc <- gscluster(gs)
gsc
## A GatingSet with 2 samples
## archive dir:  /tmp/RtmpPoKFSb/file54bd4f91e809

Immutable operations

access tree structures (stats)

gs_clusterApply(cl, gsc, function(gh){
                head(gh_pop_get_stats(gh, path = "auto"))
              }, mutable = F)
## [[1]]
##          pop count
## 1:      root 81638
## 2: nonDebris 80711
## 3:     lymph 52927
## 4:      Live 51652
## 5:      CD20 11093
## 6:      CD19 11126
## 
## [[2]]
##          pop  count
## 1:      root 148214
## 2: nonDebris 146594
## 3:     lymph  96241
## 4:      Live  94218
## 5:      CD20  20888
## 6:      CD19  20938

access events data

gs_clusterApply(cl, gsc, function(gh){
   summary(exprs(gh_pop_get_data(gh, "lymph"))[, 4:5])
}, mutable = F)
## [[1]]
##       CD3             CD19       
##  Min.   :-6583   Min.   :-390.8  
##  1st Qu.:  707   1st Qu.: 758.6  
##  Median : 2228   Median :1003.0  
##  Mean   : 1730   Mean   :1210.6  
##  3rd Qu.: 2421   3rd Qu.:1331.8  
##  Max.   : 3144   Max.   :4047.1  
## 
## [[2]]
##       CD3               CD19       
##  Min.   : -11.48   Min.   :-562.1  
##  1st Qu.: 707.45   1st Qu.: 754.4  
##  Median :2230.78   Median : 998.0  
##  Mean   :1734.21   Mean   :1211.5  
##  3rd Qu.:2421.18   3rd Qu.:1337.5  
##  Max.   :3054.37   Max.   :3559.7

Mutable operations

change tree structures

gs_clusterApply(cl, gsc, function(gh){
                gh_pop_remove(gh, "Live")
                gh_get_pop_paths(gh)
              }, mutable = T)
## [[1]]
## [1] "root"                      "/boundary/nonDebris"      
## [3] "/boundary/nonDebris/lymph"
## 
## [[2]]
## [1] "root"                      "/boundary/nonDebris"      
## [3] "/boundary/nonDebris/lymph"

Changes are propagated to the original gsc

gs_get_pop_paths(gsc)
## [1] "root"                      "/boundary/nonDebris"      
## [3] "/boundary/nonDebris/lymph"