### R code from vignette source 'vignettes/flowCore/inst/doc/HowTo-flowCore.Rnw' ################################################### ### code chunk number 1: loadPackage ################################################### library(flowCore) ################################################### ### code chunk number 2: ReadFiles ################################################### file.name <- system.file("extdata","0877408774.B08", package="flowCore") x <- read.FCS(file.name, transformation=FALSE) summary(x) ################################################### ### code chunk number 3: SearchKeywords ################################################### keyword(x,c("$P1E", "$P2E", "$P3E", "$P4E")) ################################################### ### code chunk number 4: PrintSummary ################################################### summary(read.FCS(file.name)) ################################################### ### code chunk number 5: PrintSummary2 ################################################### summary(read.FCS(file.name,transformation="scale")) ################################################### ### code chunk number 6: ReadFiles2 ################################################### read.FCS(file.name,alter.names=TRUE) ################################################### ### code chunk number 7: RedFiles3 ################################################### x <- read.FCS(file.name, column.pattern="-H") x ################################################### ### code chunk number 8: RedFiles3 ################################################### lines <- sample(100:500, 50) y <- read.FCS(file.name, which.lines = lines) y ################################################### ### code chunk number 9: Plot1 ################################################### library(flowViz) plot(x) ################################################### ### code chunk number 10: Plot2 ################################################### plot(x,c("FL1-H", "FL2-H")) ################################################### ### code chunk number 11: plot3 ################################################### plot(x, "FL1-H", breaks=256) ################################################### ### code chunk number 12: Frames ################################################### frames <- lapply(dir(system.file("extdata", "compdata", "data", package="flowCore"), full.names=TRUE), read.FCS) as(frames, "flowSet") ################################################### ### code chunk number 13: Frames ################################################### names(frames) <- sapply(frames, keyword, "SAMPLE ID") fs <- as(frames, "flowSet") fs ################################################### ### code chunk number 14: metaData ################################################### phenoData(fs)$Filename <- fsApply(fs,keyword, "$FIL") pData(phenoData(fs)) ################################################### ### code chunk number 15: ReadFlowSet ################################################### read.flowSet(path = system.file("extdata", "compdata", "data", package="flowCore")) ################################################### ### code chunk number 16: ReadFowSet2 ################################################### fs <- read.flowSet(path=system.file("extdata", "compdata", "data", package="flowCore"), name.keyword="SAMPLE ID", phenoData=list(name="SAMPLE ID", Filename="$FIL")) fs pData(phenoData(fs)) ################################################### ### code chunk number 17: fsApply1 ################################################### fsApply(fs, each_col, median) ################################################### ### code chunk number 18: fsApply2 ################################################### fsApply(fs,function(x) apply(x, 2, median), use.exprs=TRUE) ################################################### ### code chunk number 19: Transfo1 ################################################### plot(transform(fs[[1]], `FL1-H`=log(`FL1-H`), `FL2-H`=log(`FL2-H`)), c("FL1-H","FL2-H")) ################################################### ### code chunk number 20: Transfo2 ################################################### plot(transform(fs[[1]], log.FL1.H=log(`FL1-H`), log.FL2.H=log(`FL2-H`)), c("log.FL1.H", "log.FL2.H")) ################################################### ### code chunk number 21: Transfo3 ################################################### aTrans <- truncateTransform("truncate at 1", a=1) aTrans ################################################### ### code chunk number 22: Transfo4 ################################################### transform(fs,`FL1-H`=aTrans(`FL1-H`)) ################################################### ### code chunk number 23: rectGate ################################################### rectGate <- rectangleGate(filterId="Fluorescence Region", "FL1-H"=c(0, 12), "FL2-H"=c(0, 12)) ################################################### ### code chunk number 24: HowTo-flowCore.Rnw:584-586 ################################################### result = filter(fs[[1]],rectGate) result ################################################### ### code chunk number 25: Summary3 ################################################### summary(result) summary(result)$n summary(result)$true summary(result)$p ################################################### ### code chunk number 26: SummarFilter ################################################### summary(filter(fs[[1]], kmeansFilter("FSC-H"=c("Low", "Medium", "High"), filterId="myKMeans"))) ################################################### ### code chunk number 27: HowTo-flowCore.Rnw:613-614 ################################################### filter(fs,rectGate) ################################################### ### code chunk number 28: Norm2Filter ################################################### morphGate <- norm2Filter("FSC-H", "SSC-H", filterId="MorphologyGate", scale=2) smaller <- Subset(fs, morphGate) fs[[1]] smaller[[1]] ################################################### ### code chunk number 29: Split ################################################### split(smaller[[1]], kmeansFilter("FSC-H"=c("Low","Medium","High"), filterId="myKMeans")) ################################################### ### code chunk number 30: Split2 ################################################### split(smaller, kmeansFilter("FSC-H"=c("Low", "Medium", "High"), filterId="myKMeans")) ################################################### ### code chunk number 31: CombineFilter ################################################### rectGate & morphGate rectGate | morphGate !morphGate ################################################### ### code chunk number 32: Summary5 ################################################### summary(filter(smaller[[1]],rectGate %&% morphGate)) ################################################### ### code chunk number 33: Transfo5 ################################################### tFilter <- transform("FL1-H"=log,"FL2-H"=log) tFilter ################################################### ### code chunk number 34: TectGate3 ################################################### rect2 <- rectangleGate(filterId="Another Rect", "FL1-H"=c(1,2), "FL2-H"=c(2,3)) %on% tFilter rect2 ################################################### ### code chunk number 35: Plot6 ################################################### plot(tFilter %on% smaller[[1]],c("FL1-H","FL2-H")) ################################################### ### code chunk number 36: FilterSet1 ################################################### fset1 = filterSet( rectangleGate(filterId="Fluorescence Region","FL1-H"=c(50,100), "FL2-H"=c(50,100)), norm2Filter("FSC-H","SSC-H",filterId="Morphology Gate", scale=2), ~ `Fluorescence Region` & `Morphology Gate`, ~ `Fluorescence Region` | `Morphology Gate`, Debris ~ ! `Morphology Gate`, ~ `Fluorescence Region` %&% `Morphology Gate` ) fset1 ################################################### ### code chunk number 37: FilterSet2 ################################################### f = filter(fs,fset1) f ################################################### ### code chunk number 38: FilterSet3 ################################################### split(fs[[1]], fset1, flowSet=TRUE) ################################################### ### code chunk number 39: FilterSet4 ################################################### split(fs[[1]],fset1,drop=TRUE,flowSet=TRUE) ################################################### ### code chunk number 40: createWorkFlow ################################################### data(GvHD) wf <- workFlow(GvHD[1:5], name="myWorkflow") wf ################################################### ### code chunk number 41: views ################################################### views(wf) ################################################### ### code chunk number 42: addItems ################################################### tf <- transformList(colnames(GvHD[[1]])[3:6], asinh, transformationId="asinh") add(wf, tf) wf views(wf) ################################################### ### code chunk number 43: itemName ################################################### add(wf, tf, name="another asinh transform") wf ################################################### ### code chunk number 44: addGate ################################################### rg <- rectangleGate("FSC-H"=c(200,400), "SSC-H"=c(250, 400), filterId="rectangle") add(wf, rg, parent="asinh") wf ################################################### ### code chunk number 45: addQuadGate ################################################### qg <- quadGate("FL1-H"=2, "FL2-H"=4) add(wf,qg,parent="rectangle+") wf ################################################### ### code chunk number 46: plotwf (eval = FALSE) ################################################### ## plot(wf) ################################################### ### code chunk number 47: plotwfdo ################################################### if(suppressWarnings(require(Rgraphviz))){ plot(wf) }else{ plot(1,1, type="n", axes=FALSE, ann=FALSE) text(1,1,"Need to install Rgraphviz") } ################################################### ### code chunk number 48: getView ################################################### wf[["rectangle+"]] wf$asinh ################################################### ### code chunk number 49: getAction ################################################### wf[["action_rectangle"]] ################################################### ### code chunk number 50: getData ################################################### Data(wf[["rectangle-"]]) ################################################### ### code chunk number 51: summaries ################################################### summary(wf[["action_rectangle"]]) summary(wf[["CD15 FITC+CD45 PE+"]]) ################################################### ### code chunk number 52: plotViews ################################################### densityplot(wf[["base view"]]) xyplot(`FL1-H` ~ `FL2-H`, wf[["CD15 FITC+CD45 PE+"]]) ################################################### ### code chunk number 53: undo ################################################### undo(wf) wf ################################################### ### code chunk number 54: RmView ################################################### Rm('rectangle-', wf) ################################################### ### code chunk number 55: RmAction ################################################### Rm('asinh', wf)