This vignette demonstrates how the gatingML files exported from Cytobank can be imported into R as a GatingSet object.
library(flowWorkspace)
library(CytoML)
fcsFiles <- list.files(pattern = "CytoTrol", system.file("extdata", package = "flowWorkspaceData"), full.names = TRUE)
xmlfile <- system.file("extdata/cytotrol_tcell_cytobank.xml", package = "CytoML")
cytobank2GatingSet
The entire parsing work can be done with single convevient function cytobank2GatingSet
:
gs <- cytobank2GatingSet(xmlfile, fcsFiles)
Or you can divide the parsing into several steps to have more controls.
g <- read.gatingML.cytobank(xmlfile)
class(g)
## [1] "graphGML"
## attr(,"package")
## [1] "CytoML"
g
## --- Gating hieararchy parsed from GatingML:
## with 12 populations defined
graphGML stores the gating hierarchy, which can be inspected by various accessors.
getNodes(g)
## GateSet_722318 GateSet_722319 GateSet_722320 GateSet_722321 GateSet_722322
## "CD4" "CD8" "Q4" "Q3" "singlets"
## GateSet_722323 GateSet_722324 GateSet_722325 GateSet_722326 GateSet_722327
## "not debris" "Q1" "Q2" "CD8_Q2" "CD3"
## GateSet_722328 GateSet_722329
## "CD38 range" "HLA range"
getParent(g, "GateSet_722318")
## [1] "GateSet_722327"
getChildren(g, "GateSet_722318")
## [1] "GateSet_722320" "GateSet_722321" "GateSet_722324" "GateSet_722325"
And the population tree can be plotted
plot(g)
The node with dotted border means the tailored
gates(or sample-specific gates) are defined for that population.
fs <- read.ncdfFlowSet(fcsFiles)
gs <- GatingSet(fs)
GatingSet
gs <- compensate(gs, g)
## Extract the transformation from graphGML
trans <- getTransformations(g)
trans
## $`B710-A`
## Transformer: asinhtGml2
##
## $`G560-A`
## Transformer: asinhtGml2
##
## $`G780-A`
## Transformer: asinhtGml2
##
## $`R660-A`
## Transformer: asinhtGml2
##
## $`R780-A`
## Transformer: asinhtGml2
##
## $`V450-A`
## Transformer: asinhtGml2
##
## $`V545-A`
## Transformer: asinhtGml2
##
## attr(,"class")
## [1] "transformerList" "list"
## Transform the `GatingSet`
gs <- transform(gs, trans)
require(ggcyto)
ggcyto(gs, aes(x = CD4), subset = "root") + geom_density()
ggcyto(gs, aes(x = CD4, y = CD8), subset = "root") + geom_hex()
gating(g, gs)
## Plot the gates
autoplot(gs[[1]])