comparison w4mcorcov_wrapper.R @ 0:23f9fad4edfc draft

planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit bd26542b811de06c1a877337a2840a9f899c2b94
author eschen42
date Mon, 16 Oct 2017 14:56:52 -0400
parents
children 0c2ad44b6c9c
comparison
equal deleted inserted replaced
-1:000000000000 0:23f9fad4edfc
1 #!/usr/bin/env Rscript
2
3 # This script assumes that it is being executed in a current working directory containing the following files:
4 # - w4mcorcov_lib.R
5 # - w4mcorcov_input.R
6 # - w4mcorcov_calc.R
7
8 ## constants
9 ##----------
10
11 modNamC <- "w4mcorcov" ## module name
12
13 topEnvC <- environment()
14 nl <- "\n"
15
16 ## options
17 ##--------
18
19 strAsFacL <- options()$stringsAsFactors
20 options(stringsAsFactors = FALSE)
21
22 ## subroutines
23 ##----------
24
25 source("w4mcorcov_lib.R")
26 source("w4mcorcov_util.R")
27 source("w4mcorcov_input.R")
28 source("w4mcorcov_salience.R")
29 source("w4mcorcov_calc.R")
30 source("w4mcorcov_output.R")
31
32 ## log file
33 ##---------
34
35 my_log <- function(x, ...) { cat(paste(iso8601.znow(), " ", x, ..., nl, sep=""))}
36 my_fatal <- function(x, ...) {
37 my_log("ERROR: ", x, ...)
38 quit(save = "no", status = 11, runLast = TRUE)
39 }
40
41 my_log("Start of the '", modNamC, "' Galaxy module call: ")
42
43
44 ########
45 # MAIN #
46 ########
47
48 argVc <- unlist(parseCommandArgs(evaluate=FALSE))
49 my_env <- new.env()
50
51 ##------------------------------
52 ## Initializing
53 ##------------------------------
54
55 ## arguments
56 ##----------
57
58 # files
59
60 my_env$dataMatrix_in <- as.character(argVc["dataMatrix_in"])
61 my_env$sampleMetadata_in <- as.character(argVc["sampleMetadata_in"])
62 my_env$variableMetadata_in <- as.character(argVc["variableMetadata_in"])
63 my_env$contrast_detail <- as.character(argVc["contrast_detail"])
64 my_env$contrast_corcov <- as.character(argVc["contrast_corcov"])
65 my_env$contrast_salience <- as.character(argVc["contrast_salience"])
66 # print(sprintf("contrast_salience: %s", my_env$contrast_salience))
67
68 # other parameters
69
70 my_env$tesC <- as.character(argVc["tesC"])
71 my_env$facC <- as.character(argVc["facC"])
72 my_env$pairSigFeatOnly <- as.logical(argVc["pairSigFeatOnly"])
73 my_env$levCSV <- as.character(argVc["levCSV"])
74 my_env$matchingC <- as.character(argVc["matchingC"])
75 my_env$labelFeatures <- as.logical(argVc["labelFeatures"])
76
77 tsv_action_factory <- function(file, colnames, append) {
78 return (
79 function(tsv) {
80 write.table(
81 x = tsv
82 , file = file
83 , sep = "\t"
84 , quote = FALSE
85 , row.names = FALSE
86 , col.names = colnames
87 , append = append
88 )
89 }
90 )
91 }
92
93 corcov_tsv_colnames <- TRUE
94 corcov_tsv_append <- FALSE
95 corcov_tsv_action <- function(tsv) {
96 tsv_action_factory(
97 file = my_env$contrast_corcov
98 , colnames = corcov_tsv_colnames
99 , append = corcov_tsv_append
100 )(tsv)
101 corcov_tsv_colnames <<- FALSE
102 corcov_tsv_append <<- TRUE
103 }
104
105 salience_tsv_colnames <- TRUE
106 salience_tsv_append <- FALSE
107 salience_tsv_action <- function(tsv) {
108 tsv_action_factory(
109 file = my_env$contrast_salience
110 , colnames = salience_tsv_colnames
111 , append = salience_tsv_append
112 )(tsv)
113 salience_tsv_colnames <<- FALSE
114 salience_tsv_append <<- TRUE
115 }
116
117 my_log( "-------------------------- Reading input data --------------------------")
118
119 # read_inputs is defined in w4mcorcov_input.R
120 my_result <- read_inputs(input_env = my_env, failure_action = my_log)
121
122 if ( is.logical(my_result) && my_result) {
123 my_log( "-------------------------- Beginning data processing --------------------------")
124
125 # receiver for result of the call to corcov_calc
126 my_result <- NULL
127
128 # compute and plot the correlation_vs_covariance details plot
129 # The parameter settings here are generally taken from bioconductor ropls::plot.opls source.
130 marVn <- c(4.6, 4.1, 2.6, 1.6)
131 old_par <- par(
132 font = 2 # bold font face
133 , font.axis = 2 # bold font face for axis
134 , font.lab = 2 # bold font face for x and y labels
135 , lwd = 2 # line-width - interpretation is device spcific
136 , mar = marVn # margins
137 , pch = 18 # black diamond plot-character, see help for graphics::points
138 # , mfrow = c(2,2) # two rows by two columns
139 , pty = "s" # force plots to be square
140 )
141 plot2pdf(
142 file.name = my_env$contrast_detail
143 , width = 8
144 , height = 8
145 , plot.function = function() {
146 # plot layout four plots per page
147 layout(matrix(1:4, byrow = TRUE, nrow = 2))
148 my_result <<- corcov_calc(
149 calc_env = my_env
150 , failure_action = my_fatal
151 , progress_action = my_log
152 , corcov_tsv_action = corcov_tsv_action
153 , salience_tsv_action = salience_tsv_action
154 )
155 }
156 )
157 par(old_par)
158
159 my_log( "-------------------------- Finished data processing --------------------------")
160 }
161
162 my_log( "End of the '", modNamC, "' Galaxy module call")
163
164 if (is.logical(my_result) && my_result) {
165 quit(save = "no", status = 0, runLast = TRUE)
166 } else {
167 my_log("failure :(")
168 quit(save = "no", status = 10, runLast = TRUE)
169 }