Mercurial > repos > eschen42 > w4mclassfilter
annotate w4mclassfilter_wrapper.R @ 13:b24ca78a425b draft
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 32cf96ed6c39a93eb9c6cf00494b128bd3c3febe
author | eschen42 |
---|---|
date | Mon, 03 Sep 2018 22:28:03 -0400 |
parents | 518cc205f289 |
children |
rev | line source |
---|---|
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 | |
12
518cc205f289
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit aaa20ca94614124d11723bb906dee91636144d05
eschen42
parents:
6
diff
changeset
|
85 transformation <- as.character(argVc["transformation"]) |
6
f1eabb5973b1
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 08a878ac05ac0c05eafac27b9ebaadb88ae21eb7
eschen42
parents:
5
diff
changeset
|
86 wildcards <- as.logical(argVc["wildcards"]) |
0 | 87 sampleclassNames <- as.character(argVc["sampleclassNames"]) |
88 sampleclassNames <- strsplit(x = sampleclassNames, split = ",", fixed = TRUE)[[1]] | |
5
ae791fe4fbe9
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit a2d17eac4a1343a34cf2908d9ab31b3202a21f64
eschen42
parents:
1
diff
changeset
|
89 if (wildcards) { |
ae791fe4fbe9
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit a2d17eac4a1343a34cf2908d9ab31b3202a21f64
eschen42
parents:
1
diff
changeset
|
90 sampleclassNames <- gsub("[.]", "[.]", sampleclassNames) |
ae791fe4fbe9
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit a2d17eac4a1343a34cf2908d9ab31b3202a21f64
eschen42
parents:
1
diff
changeset
|
91 sampleclassNames <- utils::glob2rx(sampleclassNames, trim.tail = FALSE) |
ae791fe4fbe9
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit a2d17eac4a1343a34cf2908d9ab31b3202a21f64
eschen42
parents:
1
diff
changeset
|
92 } |
0 | 93 inclusive <- as.logical(argVc["inclusive"]) |
94 classnameColumn <- as.character(argVc["classnameColumn"]) | |
95 samplenameColumn <- as.character(argVc["samplenameColumn"]) | |
96 | |
6
f1eabb5973b1
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 08a878ac05ac0c05eafac27b9ebaadb88ae21eb7
eschen42
parents:
5
diff
changeset
|
97 variable_range_filter <- as.character(argVc["variable_range_filter"]) |
f1eabb5973b1
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 08a878ac05ac0c05eafac27b9ebaadb88ae21eb7
eschen42
parents:
5
diff
changeset
|
98 variable_range_filter <- strsplit(x = variable_range_filter, split = ",", fixed = TRUE)[[1]] |
f1eabb5973b1
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 08a878ac05ac0c05eafac27b9ebaadb88ae21eb7
eschen42
parents:
5
diff
changeset
|
99 |
12
518cc205f289
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit aaa20ca94614124d11723bb906dee91636144d05
eschen42
parents:
6
diff
changeset
|
100 ## ----------------------------- |
518cc205f289
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit aaa20ca94614124d11723bb906dee91636144d05
eschen42
parents:
6
diff
changeset
|
101 ## Transformation and imputation |
518cc205f289
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit aaa20ca94614124d11723bb906dee91636144d05
eschen42
parents:
6
diff
changeset
|
102 ## ----------------------------- |
518cc205f289
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit aaa20ca94614124d11723bb906dee91636144d05
eschen42
parents:
6
diff
changeset
|
103 my_w4m_filter_imputation <- if (transformation == "log10") { |
518cc205f289
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit aaa20ca94614124d11723bb906dee91636144d05
eschen42
parents:
6
diff
changeset
|
104 function(m) { |
13
b24ca78a425b
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 32cf96ed6c39a93eb9c6cf00494b128bd3c3febe
eschen42
parents:
12
diff
changeset
|
105 if (!is.matrix(m)) |
b24ca78a425b
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 32cf96ed6c39a93eb9c6cf00494b128bd3c3febe
eschen42
parents:
12
diff
changeset
|
106 stop("Cannot impute and transform data - the supplied data is not in matrix form") |
b24ca78a425b
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 32cf96ed6c39a93eb9c6cf00494b128bd3c3febe
eschen42
parents:
12
diff
changeset
|
107 if (nrow(m) == 0) |
b24ca78a425b
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 32cf96ed6c39a93eb9c6cf00494b128bd3c3febe
eschen42
parents:
12
diff
changeset
|
108 stop("Cannot impute and transform data - data matrix has no rows") |
b24ca78a425b
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 32cf96ed6c39a93eb9c6cf00494b128bd3c3febe
eschen42
parents:
12
diff
changeset
|
109 if (ncol(m) == 0) |
b24ca78a425b
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 32cf96ed6c39a93eb9c6cf00494b128bd3c3febe
eschen42
parents:
12
diff
changeset
|
110 stop("Cannot impute and transform data - data matrix has no columns") |
12
518cc205f289
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit aaa20ca94614124d11723bb906dee91636144d05
eschen42
parents:
6
diff
changeset
|
111 suppressWarnings( |
518cc205f289
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit aaa20ca94614124d11723bb906dee91636144d05
eschen42
parents:
6
diff
changeset
|
112 # suppress warnings here since non-positive values will produce NaN's that will be fixed in the next step |
518cc205f289
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit aaa20ca94614124d11723bb906dee91636144d05
eschen42
parents:
6
diff
changeset
|
113 m <- log10(m) |
518cc205f289
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit aaa20ca94614124d11723bb906dee91636144d05
eschen42
parents:
6
diff
changeset
|
114 ) |
13
b24ca78a425b
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 32cf96ed6c39a93eb9c6cf00494b128bd3c3febe
eschen42
parents:
12
diff
changeset
|
115 return ( w4m_filter_imputation(m) ) |
b24ca78a425b
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 32cf96ed6c39a93eb9c6cf00494b128bd3c3febe
eschen42
parents:
12
diff
changeset
|
116 } |
b24ca78a425b
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 32cf96ed6c39a93eb9c6cf00494b128bd3c3febe
eschen42
parents:
12
diff
changeset
|
117 } else if (transformation == "log2") { |
b24ca78a425b
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 32cf96ed6c39a93eb9c6cf00494b128bd3c3febe
eschen42
parents:
12
diff
changeset
|
118 function(m) { |
b24ca78a425b
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 32cf96ed6c39a93eb9c6cf00494b128bd3c3febe
eschen42
parents:
12
diff
changeset
|
119 if (!is.matrix(m)) |
b24ca78a425b
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 32cf96ed6c39a93eb9c6cf00494b128bd3c3febe
eschen42
parents:
12
diff
changeset
|
120 stop("Cannot impute and transform data - the supplied data is not in matrix form") |
b24ca78a425b
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 32cf96ed6c39a93eb9c6cf00494b128bd3c3febe
eschen42
parents:
12
diff
changeset
|
121 if (nrow(m) == 0) |
b24ca78a425b
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 32cf96ed6c39a93eb9c6cf00494b128bd3c3febe
eschen42
parents:
12
diff
changeset
|
122 stop("Cannot impute and transform data - data matrix has no rows") |
b24ca78a425b
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 32cf96ed6c39a93eb9c6cf00494b128bd3c3febe
eschen42
parents:
12
diff
changeset
|
123 if (ncol(m) == 0) |
b24ca78a425b
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 32cf96ed6c39a93eb9c6cf00494b128bd3c3febe
eschen42
parents:
12
diff
changeset
|
124 stop("Cannot impute and transform data - data matrix has no columns") |
b24ca78a425b
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 32cf96ed6c39a93eb9c6cf00494b128bd3c3febe
eschen42
parents:
12
diff
changeset
|
125 suppressWarnings( |
b24ca78a425b
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 32cf96ed6c39a93eb9c6cf00494b128bd3c3febe
eschen42
parents:
12
diff
changeset
|
126 # suppress warnings here since non-positive values will produce NaN's that will be fixed in the next step |
b24ca78a425b
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 32cf96ed6c39a93eb9c6cf00494b128bd3c3febe
eschen42
parents:
12
diff
changeset
|
127 m <- log2(m) |
b24ca78a425b
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 32cf96ed6c39a93eb9c6cf00494b128bd3c3febe
eschen42
parents:
12
diff
changeset
|
128 ) |
b24ca78a425b
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 32cf96ed6c39a93eb9c6cf00494b128bd3c3febe
eschen42
parents:
12
diff
changeset
|
129 return ( w4m_filter_imputation(m) ) |
12
518cc205f289
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit aaa20ca94614124d11723bb906dee91636144d05
eschen42
parents:
6
diff
changeset
|
130 } |
518cc205f289
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit aaa20ca94614124d11723bb906dee91636144d05
eschen42
parents:
6
diff
changeset
|
131 } else { |
518cc205f289
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit aaa20ca94614124d11723bb906dee91636144d05
eschen42
parents:
6
diff
changeset
|
132 # use the method from the w4mclassfilter class |
518cc205f289
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit aaa20ca94614124d11723bb906dee91636144d05
eschen42
parents:
6
diff
changeset
|
133 w4m_filter_imputation |
518cc205f289
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit aaa20ca94614124d11723bb906dee91636144d05
eschen42
parents:
6
diff
changeset
|
134 } |
518cc205f289
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit aaa20ca94614124d11723bb906dee91636144d05
eschen42
parents:
6
diff
changeset
|
135 |
0 | 136 ##------------------------------ |
137 ## Computation | |
138 ##------------------------------ | |
139 | |
140 result <- w4m_filter_by_sample_class( | |
6
f1eabb5973b1
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 08a878ac05ac0c05eafac27b9ebaadb88ae21eb7
eschen42
parents:
5
diff
changeset
|
141 dataMatrix_in = dataMatrix_in |
f1eabb5973b1
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 08a878ac05ac0c05eafac27b9ebaadb88ae21eb7
eschen42
parents:
5
diff
changeset
|
142 , sampleMetadata_in = sampleMetadata_in |
f1eabb5973b1
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 08a878ac05ac0c05eafac27b9ebaadb88ae21eb7
eschen42
parents:
5
diff
changeset
|
143 , variableMetadata_in = variableMetadata_in |
f1eabb5973b1
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 08a878ac05ac0c05eafac27b9ebaadb88ae21eb7
eschen42
parents:
5
diff
changeset
|
144 , dataMatrix_out = dataMatrix_out |
f1eabb5973b1
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 08a878ac05ac0c05eafac27b9ebaadb88ae21eb7
eschen42
parents:
5
diff
changeset
|
145 , sampleMetadata_out = sampleMetadata_out |
f1eabb5973b1
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 08a878ac05ac0c05eafac27b9ebaadb88ae21eb7
eschen42
parents:
5
diff
changeset
|
146 , variableMetadata_out = variableMetadata_out |
f1eabb5973b1
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 08a878ac05ac0c05eafac27b9ebaadb88ae21eb7
eschen42
parents:
5
diff
changeset
|
147 , classes = sampleclassNames |
f1eabb5973b1
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 08a878ac05ac0c05eafac27b9ebaadb88ae21eb7
eschen42
parents:
5
diff
changeset
|
148 , include = inclusive |
f1eabb5973b1
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 08a878ac05ac0c05eafac27b9ebaadb88ae21eb7
eschen42
parents:
5
diff
changeset
|
149 , class_column = classnameColumn |
f1eabb5973b1
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 08a878ac05ac0c05eafac27b9ebaadb88ae21eb7
eschen42
parents:
5
diff
changeset
|
150 , samplename_column = samplenameColumn |
f1eabb5973b1
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 08a878ac05ac0c05eafac27b9ebaadb88ae21eb7
eschen42
parents:
5
diff
changeset
|
151 , variable_range_filter = variable_range_filter |
f1eabb5973b1
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 08a878ac05ac0c05eafac27b9ebaadb88ae21eb7
eschen42
parents:
5
diff
changeset
|
152 , failure_action = my_print |
12
518cc205f289
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit aaa20ca94614124d11723bb906dee91636144d05
eschen42
parents:
6
diff
changeset
|
153 , data_imputation = my_w4m_filter_imputation |
0 | 154 ) |
155 | |
156 my_print("\nResult of '", modNamC, "' Galaxy module call to 'w4mclassfilter::w4m_filter_by_sample_class' R function: ", | |
157 as.character(result), "\n", sep = "") | |
158 | |
159 ##-------- | |
160 ## Closing | |
161 ##-------- | |
162 | |
163 my_print("\nEnd of '", modNamC, "' Galaxy module call: ", | |
164 as.character(Sys.time()), "\n", sep = "") | |
165 | |
166 #sink() | |
167 | |
168 if (!file.exists(dataMatrix_out)) { | |
169 print(sprintf("ERROR %s::w4m_filter_by_sample_class - file '%s' was not created", modNamC, dataMatrix_out)) | |
170 }# else { print(sprintf("INFO %s::w4m_filter_by_sample_class - file '%s' was exists", modNamC, dataMatrix_out)) } | |
171 | |
172 if (!file.exists(variableMetadata_out)) { | |
173 print(sprintf("ERROR %s::w4m_filter_by_sample_class - file '%s' was not created", modNamC, variableMetadata_out)) | |
174 } # else { print(sprintf("INFO %s::w4m_filter_by_sample_class - file '%s' was exists", modNamC, variableMetadata_out)) } | |
175 | |
176 if (!file.exists(sampleMetadata_out)) { | |
177 print(sprintf("ERROR %s::w4m_filter_by_sample_class - file '%s' was not created", modNamC, sampleMetadata_out)) | |
178 } # else { print(sprintf("INFO %s::w4m_filter_by_sample_class - file '%s' was exists", modNamC, sampleMetadata_out)) } | |
179 | |
180 if( !result ) { | |
181 stop(sprintf("ERROR %s::w4m_filter_by_sample_class - method failed", modNamC)) | |
182 } | |
183 | |
184 rm(list = ls()) |