library(flowStats)
#' load data set
gs <- load_gs(file.path(dataPath,"autoGating12"))
gs <- gs[1:4]
plot(gs)

getNodes(gs[[1]], showHidden = T, path = "auto")
## [1] "root" "s1" "s2" "live" "lymph"
## [6] "cd3" "Bcell" "IgDgate" "cd27gate" "SM"
## [11] "UM" "N+T" "DN" "MTG+" "MTG-"
## [16] "T1T2" "T3" "naiveGate" "naive"
#' cd27 marker is not aligned based on cd27gate plot
plotGate(gs, "cd27gate", type = "densityplot", stack = T)

#' normalize it within GatingSet
gs_norm <- normalize(gs
, target = "M+T panel_903997-25.fcs"
, populations = "cd27gate"
, dims = "<Violet A 610/20-A>"
, minCountThreshold = 100
, nPeaks = list('cd27gate' = 2)
, chunksize = 10
, bwFac = 2
)
##
Estimating landmarks for channel <Violet A 610/20-A> ...
## Registering curves for parameter <Violet A 610/20-A> ...
#' results
plotGate(gs_norm, "cd27gate", type = "densityplot", stack = T)

#' normalize the underline flow data directly by flowStats:::warpSetNCDF
#' get the parent data of cd27gate
fs <- getData(gs,"Bcell")
#' run the warpSet
warped_fs <- flowStats:::warpSetNCDF(x = fs
, stains = "<Violet A 610/20-A>"
, peakNr = 2
, target = "M+T panel_903997-25.fcs"
, chunksize = 10
, bwFac = 2
, isNew = TRUE #Set false will write the data in place(i.e. overite the original data)
)
##
Estimating landmarks for channel <Violet A 610/20-A> ...
## Registering curves for parameter <Violet A 610/20-A> ...
#' results
grid.arrange(
densityplot(~`cd27`, fs)
,densityplot(~`cd27`, warped_fs)
)
