-
Notifications
You must be signed in to change notification settings - Fork 0
/
BatchFlowTypeDataPrep.R
94 lines (69 loc) · 2.96 KB
/
BatchFlowTypeDataPrep.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env Rscript
require(docopt)
require(methods)
"
Usage:
BatchFlowTypeDataPrep.R (-h | --help | --version)
BatchFlowTypeDataPrep.R DIR
Description: This script creates serialized Rdata files for the purposes of running FlowType in a batched manner
Options:
--version Show the current version.
Arguments:
DIR Provide directory for cytools.args.Rdata to be found, automatically generated by invoking cyttools.R
" -> doc
args <- docopt(doc)
ARGS_DIR <- args$DIR
cat("\nLoading arguments from", ARGS_DIR, "\n")
load(paste(ARGS_DIR, "cyttools.args.Rdata", sep = ""))
RESULTS_DIR <- args$OUT
source("cyttoolsFunctions.R")
dir <- args$DIR # grabs directory from initial cyttools call
file <- list.files(dir ,pattern='.fcs$', full=TRUE) # captures all FCS files in the directory
targets <- read.delim(args$PANEL)
colsToCheck <- c("Ignore", "TransformCofactor", "Lineage", "Functional", "NRS")
if(checkDesignCols(targets, colsToCheck)){
missingCols <- colsToCheck[which(colsToCheck %in% colnames(targets) == F)]
cat("\n\nERROR: PANEL file does not include required columns.
\n\nMissing Columns:", missingCols,
"\n\nPlease run cyttools.R --makePanelBlank and cyttools.R --computeNRS to generate compatible panel file.\n\nStopping cyttools.R\n\n")
q()
}
lineage_markers <- targets$name[targets$Lineage == 1]
functional_markers <- targets$name[targets$Functional == 1]
if(args$transform == T){
flowSet.trans <- read.flowSet.transVS(targets, file)
}else{
flowSet.trans <- read.flowSet(file)
}
# order the markers using NRS, dropping markers set to "1" in Ignore column of panel design
lineage_markers_ord <- targets$name
lineage_markers_ord <- lineage_markers_ord[lineage_markers_ord %in% targets$name[which(targets$Ignore == 0)]]
lineage_markers_ord <- lineage_markers_ord[order(targets$NRS[which(targets$name %in% lineage_markers_ord)], decreasing = T)]
PartitionsPerMarker <- 2
MaxMarkersPerPop <- length(lineage_markers_ord)
MemLimit <- 16
MemUse <- 0
NumMarkers <- 1
while(MemLimit > MemUse){
NumMarkers <- NumMarkers + 1
MemUse <- calcMemUse(calcNumPops(PartitionsPerMarker, NumMarkers),
NumMarkers,
NumMarkers,
max(fsApply(flowSet.trans, nrow)),
NumMarkers,
max(PartitionsPerMarker))/10^9
}
NumMarkers <- NumMarkers - 1
lineage_markers_ord <- lineage_markers_ord[1:NumMarkers]
colsToUse <- which(targets$name %in% lineage_markers_ord == T)
dir.create(paste(RESULTS_DIR, "BatchFlowTypeDataPrepWorkspaces/", sep = ""), showWarnings = F, recursive = T)
for ( i in 1:length(flowSet.trans)){
batchWorkspaceFile <- paste(RESULTS_DIR, "BatchFlowTypeDataPrepWorkspaces/BatchFlowTypeDataPrepWorkspace_", i, ".Rdata", sep = "")
ffb <- flowSet.trans[[i]]
parameters(ffb)$desc <- targets$desc
ffb <- ffb[,colsToUse]
save(ffb, file = batchWorkspaceFile)
}
# workspaceFile <- paste(RESULTS_DIR, "FlowTypeWorkspace.Rdata", sep = "")
#
# save.image(file = workspaceFile)