Mercurial > repos > eschen42 > w4mclassfilter
comparison w4mclassfilter_wrapper.R @ 0:bab3a658f74e draft
planemo upload commit 91805bf8e8ce26193ffc4cc2f3dca56ce4addf79
author | eschen42 |
---|---|
date | Tue, 09 May 2017 18:34:35 -0400 |
parents | |
children | 23c6d271def9 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:bab3a658f74e |
---|---|
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 information <- as.character(argVc["information"]) | |
65 | |
66 #sink(information) | |
67 | |
68 my_print <- function(x, ...) { cat(c(x, ...))} | |
69 | |
70 my_print("\nStart of the '", modNamC, "' Galaxy module call: ", | |
71 format(Sys.time(), "%a %d %b %Y %X"), "\n", sep="") | |
72 | |
73 ## arguments | |
74 ##---------- | |
75 | |
76 # files | |
77 | |
78 dataMatrix_in <- as.character(argVc["dataMatrix_in"]) | |
79 dataMatrix_out <- as.character(argVc["dataMatrix_out"]) | |
80 | |
81 sampleMetadata_in <- as.character(argVc["sampleMetadata_in"]) | |
82 sampleMetadata_out <- as.character(argVc["sampleMetadata_out"]) | |
83 | |
84 variableMetadata_in <- as.character(argVc["variableMetadata_in"]) | |
85 variableMetadata_out <- as.character(argVc["variableMetadata_out"]) | |
86 | |
87 # other parameters | |
88 | |
89 sampleclassNames <- as.character(argVc["sampleclassNames"]) | |
90 # if (sampleclassNames == "NONE_SPECIFIED") { | |
91 # sampleclassNames <- as.character(c()) | |
92 # | |
93 # } else { | |
94 # sampleclassNames <- strsplit(x = sampleclassNames, split = ",", fixed = TRUE)[[1]] | |
95 # } | |
96 sampleclassNames <- strsplit(x = sampleclassNames, split = ",", fixed = TRUE)[[1]] | |
97 inclusive <- as.logical(argVc["inclusive"]) | |
98 # print(sprintf("inclusive = '%s'", as.character(inclusive))) | |
99 classnameColumn <- as.character(argVc["classnameColumn"]) | |
100 samplenameColumn <- as.character(argVc["samplenameColumn"]) | |
101 | |
102 ##------------------------------ | |
103 ## Computation | |
104 ##------------------------------ | |
105 | |
106 result <- w4m_filter_by_sample_class( | |
107 dataMatrix_in = dataMatrix_in | |
108 , sampleMetadata_in = sampleMetadata_in | |
109 , variableMetadata_in = variableMetadata_in | |
110 , dataMatrix_out = dataMatrix_out | |
111 , sampleMetadata_out = sampleMetadata_out | |
112 , variableMetadata_out = variableMetadata_out | |
113 , classes = sampleclassNames | |
114 , include = inclusive | |
115 , class_column = classnameColumn | |
116 , samplename_column = samplenameColumn | |
117 , failure_action = my_print | |
118 ) | |
119 | |
120 my_print("\nResult of '", modNamC, "' Galaxy module call to 'w4mclassfilter::w4m_filter_by_sample_class' R function: ", | |
121 as.character(result), "\n", sep = "") | |
122 | |
123 ##-------- | |
124 ## Closing | |
125 ##-------- | |
126 | |
127 my_print("\nEnd of '", modNamC, "' Galaxy module call: ", | |
128 as.character(Sys.time()), "\n", sep = "") | |
129 | |
130 #sink() | |
131 | |
132 if (!file.exists(dataMatrix_out)) { | |
133 print(sprintf("ERROR %s::w4m_filter_by_sample_class - file '%s' was not created", modNamC, dataMatrix_out)) | |
134 }# else { print(sprintf("INFO %s::w4m_filter_by_sample_class - file '%s' was exists", modNamC, dataMatrix_out)) } | |
135 | |
136 if (!file.exists(variableMetadata_out)) { | |
137 print(sprintf("ERROR %s::w4m_filter_by_sample_class - file '%s' was not created", modNamC, variableMetadata_out)) | |
138 } # else { print(sprintf("INFO %s::w4m_filter_by_sample_class - file '%s' was exists", modNamC, variableMetadata_out)) } | |
139 | |
140 if (!file.exists(sampleMetadata_out)) { | |
141 print(sprintf("ERROR %s::w4m_filter_by_sample_class - file '%s' was not created", modNamC, sampleMetadata_out)) | |
142 } # else { print(sprintf("INFO %s::w4m_filter_by_sample_class - file '%s' was exists", modNamC, sampleMetadata_out)) } | |
143 | |
144 if( !result ) { | |
145 stop(sprintf("ERROR %s::w4m_filter_by_sample_class - method failed", modNamC)) | |
146 } | |
147 | |
148 rm(list = ls()) |