Mercurial > repos > eschen42 > w4mclassfilter
annotate w4mclassfilter_wrapper.R @ 5:ae791fe4fbe9 draft
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit a2d17eac4a1343a34cf2908d9ab31b3202a21f64
author | eschen42 |
---|---|
date | Thu, 07 Sep 2017 17:32:09 -0400 |
parents | 0c312f3a4a17 |
children | f1eabb5973b1 |
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 | |
85 sampleclassNames <- as.character(argVc["sampleclassNames"]) | |
5
ae791fe4fbe9
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit a2d17eac4a1343a34cf2908d9ab31b3202a21f64
eschen42
parents:
1
diff
changeset
|
86 wildcards <- as.logical(argVc["wildcards"]) |
0 | 87 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
|
88 if (wildcards) { |
ae791fe4fbe9
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit a2d17eac4a1343a34cf2908d9ab31b3202a21f64
eschen42
parents:
1
diff
changeset
|
89 sampleclassNames <- gsub("[.]", "[.]", sampleclassNames) |
ae791fe4fbe9
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit a2d17eac4a1343a34cf2908d9ab31b3202a21f64
eschen42
parents:
1
diff
changeset
|
90 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
|
91 } |
0 | 92 inclusive <- as.logical(argVc["inclusive"]) |
93 classnameColumn <- as.character(argVc["classnameColumn"]) | |
94 samplenameColumn <- as.character(argVc["samplenameColumn"]) | |
95 | |
96 ##------------------------------ | |
97 ## Computation | |
98 ##------------------------------ | |
99 | |
100 result <- w4m_filter_by_sample_class( | |
101 dataMatrix_in = dataMatrix_in | |
102 , sampleMetadata_in = sampleMetadata_in | |
103 , variableMetadata_in = variableMetadata_in | |
104 , dataMatrix_out = dataMatrix_out | |
105 , sampleMetadata_out = sampleMetadata_out | |
106 , variableMetadata_out = variableMetadata_out | |
107 , classes = sampleclassNames | |
108 , include = inclusive | |
109 , class_column = classnameColumn | |
110 , samplename_column = samplenameColumn | |
111 , failure_action = my_print | |
112 ) | |
113 | |
114 my_print("\nResult of '", modNamC, "' Galaxy module call to 'w4mclassfilter::w4m_filter_by_sample_class' R function: ", | |
115 as.character(result), "\n", sep = "") | |
116 | |
117 ##-------- | |
118 ## Closing | |
119 ##-------- | |
120 | |
121 my_print("\nEnd of '", modNamC, "' Galaxy module call: ", | |
122 as.character(Sys.time()), "\n", sep = "") | |
123 | |
124 #sink() | |
125 | |
126 if (!file.exists(dataMatrix_out)) { | |
127 print(sprintf("ERROR %s::w4m_filter_by_sample_class - file '%s' was not created", modNamC, dataMatrix_out)) | |
128 }# else { print(sprintf("INFO %s::w4m_filter_by_sample_class - file '%s' was exists", modNamC, dataMatrix_out)) } | |
129 | |
130 if (!file.exists(variableMetadata_out)) { | |
131 print(sprintf("ERROR %s::w4m_filter_by_sample_class - file '%s' was not created", modNamC, variableMetadata_out)) | |
132 } # else { print(sprintf("INFO %s::w4m_filter_by_sample_class - file '%s' was exists", modNamC, variableMetadata_out)) } | |
133 | |
134 if (!file.exists(sampleMetadata_out)) { | |
135 print(sprintf("ERROR %s::w4m_filter_by_sample_class - file '%s' was not created", modNamC, sampleMetadata_out)) | |
136 } # else { print(sprintf("INFO %s::w4m_filter_by_sample_class - file '%s' was exists", modNamC, sampleMetadata_out)) } | |
137 | |
138 if( !result ) { | |
139 stop(sprintf("ERROR %s::w4m_filter_by_sample_class - method failed", modNamC)) | |
140 } | |
141 | |
142 rm(list = ls()) |