This vignette demonstrates how the gatingML files exported from Cytobank can be imported into R as a GatingSet object.

library(flowWorkspace)
library(CytoML)
acs <- system.file("extdata/cytobank_experiment.acs", package = "CytoML")

Create cytobank_experiment object from the ACS bundle exported from Cytobank

ce <- open_cytobank_experiment(acs)
ce
## cytobank Experiment:  tcell 
## gatingML File:  /tmp/Rtmpk3wn87/file16dd3a800f913/experiments/3637/cytobank_gate_ml2_v41.xml 
##     panel samples
## 1 Panel 1       1

cytobank_experiment is a wrapper around the ACS file, which can be inspected by various accessors.

sampleNames(ce)
## [1] "CytoTrol_CytoTrol_1.fcs"
ce_get_panels(ce)
## # A tibble: 1 × 2
##   panel   samples
##   <chr>     <int>
## 1 Panel 1       1
ce_get_compensations(ce)
## $`CytoTrol_CytoTrol_1.fcs - spill string`
##             B710-A      R660-A      R780-A      V450-A     V545-A      G560-A
## B710-A 1.00000e+00 3.14389e-02 0.190966000 0.003057570 0.00204723 3.44241e-04
## R660-A 5.53798e-03 1.00000e+00 0.176812000 0.000000000 0.00000000 0.00000e+00
## R780-A 9.95863e-05 9.84766e-03 1.000000000 0.000000000 0.00000000 0.00000e+00
## V450-A 0.00000e+00 8.90985e-05 0.000000000 1.000000000 0.45119500 1.08275e-04
## V545-A 2.47709e-03 5.23516e-04 0.000000000 0.037961500 1.00000000 6.36181e-05
## G560-A 1.17224e-01 1.64272e-03 0.000332153 0.000000000 0.00000000 1.00000e+00
## G780-A 1.42052e-02 4.56896e-04 0.175402000 0.000089025 0.00000000 4.09687e-02
##            G780-A
## B710-A 0.07193380
## R660-A 0.00661890
## R780-A 0.03539970
## V450-A 0.00000000
## V545-A 0.00000000
## G560-A 0.00921936
## G780-A 1.00000000
## 
## $`CytoTrol_CytoTrol_1.fcs - spill string`
##             B710-A      R660-A      R780-A      V450-A     V545-A      G560-A
## B710-A 1.00000e+00 3.14389e-02 0.190966000 0.003057570 0.00204723 3.44241e-04
## R660-A 5.53798e-03 1.00000e+00 0.176812000 0.000000000 0.00000000 0.00000e+00
## R780-A 9.95863e-05 9.84766e-03 1.000000000 0.000000000 0.00000000 0.00000e+00
## V450-A 0.00000e+00 8.90985e-05 0.000000000 1.000000000 0.45119500 1.08275e-04
## V545-A 2.47709e-03 5.23516e-04 0.000000000 0.037961500 1.00000000 6.36181e-05
## G560-A 1.17224e-01 1.64272e-03 0.000332153 0.000000000 0.00000000 1.00000e+00
## G780-A 1.42052e-02 4.56896e-04 0.175402000 0.000089025 0.00000000 4.09687e-02
##            G780-A
## B710-A 0.07193380
## R660-A 0.00661890
## R780-A 0.03539970
## V450-A 0.00000000
## V545-A 0.00000000
## G560-A 0.00921936
## G780-A 1.00000000
## 
## $`CytoTrol_CytoTrol_1.fcs - spill string`
##             B710-A      R660-A      R780-A      V450-A     V545-A      G560-A
## B710-A 1.00000e+00 3.14389e-02 0.190966000 0.003057570 0.00204723 3.44241e-04
## R660-A 5.53798e-03 1.00000e+00 0.176812000 0.000000000 0.00000000 0.00000e+00
## R780-A 9.95863e-05 9.84766e-03 1.000000000 0.000000000 0.00000000 0.00000e+00
## V450-A 0.00000e+00 8.90985e-05 0.000000000 1.000000000 0.45119500 1.08275e-04
## V545-A 2.47709e-03 5.23516e-04 0.000000000 0.037961500 1.00000000 6.36181e-05
## G560-A 1.17224e-01 1.64272e-03 0.000332153 0.000000000 0.00000000 1.00000e+00
## G780-A 1.42052e-02 4.56896e-04 0.175402000 0.000089025 0.00000000 4.09687e-02
##            G780-A
## B710-A 0.07193380
## R660-A 0.00661890
## R780-A 0.03539970
## V450-A 0.00000000
## V545-A 0.00000000
## G560-A 0.00921936
## G780-A 1.00000000
ce_get_samples(ce)
## # A tibble: 1 × 2
##   panel   sample                 
##   <chr>   <chr>                  
## 1 Panel 1 CytoTrol_CytoTrol_1.fcs
ce_get_channels(ce)
##  [1] "FSC-A"  "FSC-H"  "FSC-W"  "SSC-A"  "B710-A" "R660-A" "R780-A" "V450-A"
##  [9] "V545-A" "G560-A" "G780-A" "Time"
ce_get_markers(ce)
## $CytoTrol_CytoTrol_1.fcs
##  [1] "FSC-A"        "FSC-H"        "FSC-W"        "SSC-A"        "CD4"         
##  [6] "CD38 APC"     "CD8 APCH7"    "CD3"          "HLA-DR V500"  "CCR7 PE"     
## [11] "CD45RA PECy7" "Time"
pData(ce)
##                                            name Conditions Individuals
## CytoTrol_CytoTrol_1.fcs CytoTrol_CytoTrol_1.fcs condition1       ptid1

Then import cytobank_experiment into GatingSet

gs <- cytobank_to_gatingset(ce)

By default, the first panel (i.e. panel_id = 1) will be imported. Change panel_id argument to select different panel (if there are more than one , which can be inspected by ce_get_panels )

Alternatively, the import can be done by gatingML and fcs files that are downloaded separately form Cytobank without ACS.

xmlfile <- ce$gatingML
fcsFiles <- list.files(ce$fcsdir, full.names = TRUE)
gs <- cytobank_to_gatingset(xmlfile, fcsFiles)

However, it doesn’t have the information from yaml file (part of ACS). E.g. sample tags (i.e. pData) and customized markernames. So it is recommended to import ACS.

Inspect the results

library(ggcyto)
## Plot the gates
autoplot(gs[[1]])