0
|
1 #!/usr/bin/env Rscript
|
|
2
|
|
3 library(batch) ## parseCommandArgs
|
|
4
|
|
5 ########
|
|
6 # MAIN #
|
|
7 ########
|
|
8
|
|
9 argVc <- unlist(parseCommandArgs(evaluate=FALSE))
|
|
10
|
|
11 ##------------------------------
|
|
12 ## Initializing
|
|
13 ##------------------------------
|
|
14
|
|
15 ## options
|
|
16 ##--------
|
|
17
|
|
18 strAsFacL <- options()$stringsAsFactors
|
|
19 options(stringsAsFactors = FALSE)
|
|
20
|
|
21 ## libraries
|
|
22 ##----------
|
|
23
|
|
24 suppressMessages(library(w4mclassfilter))
|
|
25
|
|
26 if(packageVersion("w4mclassfilter") < "0.98.0")
|
|
27 stop("Please use 'w4mclassfilter' versions of 0.98.0 and above")
|
|
28
|
|
29 ## constants
|
|
30 ##----------
|
|
31
|
|
32 modNamC <- "w4mclassfilter" ## module name
|
|
33
|
|
34 topEnvC <- environment()
|
|
35 flgC <- "\n"
|
|
36
|
|
37 ## functions
|
|
38 ##----------
|
|
39
|
|
40 flgF <- function(tesC,
|
|
41 envC = topEnvC,
|
|
42 txtC = NA) { ## management of warning and error messages
|
|
43
|
|
44 tesL <- eval(parse(text = tesC), envir = envC)
|
|
45
|
|
46 if(!tesL) {
|
|
47
|
|
48 #sink(NULL)
|
|
49 stpTxtC <- ifelse(is.na(txtC),
|
|
50 paste0(tesC, " is FALSE"),
|
|
51 txtC)
|
|
52
|
|
53 stop(stpTxtC,
|
|
54 call. = FALSE)
|
|
55
|
|
56 }
|
|
57
|
|
58 } ## flgF
|
|
59
|
|
60
|
|
61 ## log file
|
|
62 ##---------
|
|
63
|
|
64 my_print <- function(x, ...) { cat(c(x, ...))}
|
|
65
|
|
66 my_print("\nStart of the '", modNamC, "' Galaxy module call: ",
|
|
67 format(Sys.time(), "%a %d %b %Y %X"), "\n", sep="")
|
|
68
|
|
69 ## arguments
|
|
70 ##----------
|
|
71
|
|
72 # files
|
|
73
|
|
74 dataMatrix_in <- as.character(argVc["dataMatrix_in"])
|
|
75 dataMatrix_out <- as.character(argVc["dataMatrix_out"])
|
|
76
|
|
77 sampleMetadata_in <- as.character(argVc["sampleMetadata_in"])
|
|
78 sampleMetadata_out <- as.character(argVc["sampleMetadata_out"])
|
|
79
|
|
80 variableMetadata_in <- as.character(argVc["variableMetadata_in"])
|
|
81 variableMetadata_out <- as.character(argVc["variableMetadata_out"])
|
|
82
|
|
83 # other parameters
|
|
84
|
|
85 sampleclassNames <- as.character(argVc["sampleclassNames"])
|
|
86 # if (sampleclassNames == "NONE_SPECIFIED") {
|
|
87 # sampleclassNames <- as.character(c())
|
|
88 #
|
|
89 # } else {
|
|
90 # sampleclassNames <- strsplit(x = sampleclassNames, split = ",", fixed = TRUE)[[1]]
|
|
91 # }
|
|
92 sampleclassNames <- strsplit(x = sampleclassNames, split = ",", fixed = TRUE)[[1]]
|
|
93 inclusive <- as.logical(argVc["inclusive"])
|
|
94 # print(sprintf("inclusive = '%s'", as.character(inclusive)))
|
|
95 classnameColumn <- as.character(argVc["classnameColumn"])
|
|
96 samplenameColumn <- as.character(argVc["samplenameColumn"])
|
|
97
|
|
98 ##------------------------------
|
|
99 ## Computation
|
|
100 ##------------------------------
|
|
101
|
|
102 result <- w4m_filter_by_sample_class(
|
|
103 dataMatrix_in = dataMatrix_in
|
|
104 , sampleMetadata_in = sampleMetadata_in
|
|
105 , variableMetadata_in = variableMetadata_in
|
|
106 , dataMatrix_out = dataMatrix_out
|
|
107 , sampleMetadata_out = sampleMetadata_out
|
|
108 , variableMetadata_out = variableMetadata_out
|
|
109 , classes = sampleclassNames
|
|
110 , include = inclusive
|
|
111 , class_column = classnameColumn
|
|
112 , samplename_column = samplenameColumn
|
|
113 , failure_action = my_print
|
|
114 )
|
|
115
|
|
116 my_print("\nResult of '", modNamC, "' Galaxy module call to 'w4mclassfilter::w4m_filter_by_sample_class' R function: ",
|
|
117 as.character(result), "\n", sep = "")
|
|
118
|
|
119 ##--------
|
|
120 ## Closing
|
|
121 ##--------
|
|
122
|
|
123 my_print("\nEnd of '", modNamC, "' Galaxy module call: ",
|
|
124 as.character(Sys.time()), "\n", sep = "")
|
|
125
|
|
126 #sink()
|
|
127
|
|
128 if (!file.exists(dataMatrix_out)) {
|
|
129 print(sprintf("ERROR %s::w4m_filter_by_sample_class - file '%s' was not created", modNamC, dataMatrix_out))
|
|
130 }# else { print(sprintf("INFO %s::w4m_filter_by_sample_class - file '%s' was exists", modNamC, dataMatrix_out)) }
|
|
131
|
|
132 if (!file.exists(variableMetadata_out)) {
|
|
133 print(sprintf("ERROR %s::w4m_filter_by_sample_class - file '%s' was not created", modNamC, variableMetadata_out))
|
|
134 } # else { print(sprintf("INFO %s::w4m_filter_by_sample_class - file '%s' was exists", modNamC, variableMetadata_out)) }
|
|
135
|
|
136 if (!file.exists(sampleMetadata_out)) {
|
|
137 print(sprintf("ERROR %s::w4m_filter_by_sample_class - file '%s' was not created", modNamC, sampleMetadata_out))
|
|
138 } # else { print(sprintf("INFO %s::w4m_filter_by_sample_class - file '%s' was exists", modNamC, sampleMetadata_out)) }
|
|
139
|
|
140 if( !result ) {
|
|
141 stop(sprintf("ERROR %s::w4m_filter_by_sample_class - method failed", modNamC))
|
|
142 }
|
|
143
|
|
144 rm(list = ls())
|