comparison w4mcorcov_wrapper.R @ 0:50a07adddfbd draft

planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 52e588e19fe93d83d221710bb75559c5700ba637
author eschen42
date Mon, 09 Oct 2017 15:46:13 -0400
parents
children e25fd8a13665
comparison
equal deleted inserted replaced
-1:000000000000 0:50a07adddfbd
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
66 # other parameters
67
68 my_env$tesC <- as.character(argVc["tesC"])
69 my_env$facC <- as.character(argVc["facC"])
70 my_env$pairSigFeatOnly <- as.logical(argVc["pairSigFeatOnly"])
71 my_env$levCSV <- as.character(argVc["levCSV"])
72 my_env$matchingC <- as.character(argVc["matchingC"])
73 my_env$labelFeatures <- as.logical(argVc["labelFeatures"])
74
75 tsv_action_factory <- function(file, colnames, append) {
76 return (
77 function(tsv) {
78 write.table(
79 x = tsv
80 , file = file
81 , sep = "\t"
82 , quote = FALSE
83 , row.names = FALSE
84 , col.names = colnames
85 , append = append
86 )
87 }
88 )
89 }
90
91 corcov_tsv_colnames <- TRUE
92 corcov_tsv_append <- FALSE
93 corcov_tsv_action <- function(tsv) {
94 tsv_action_factory(
95 file = my_env$contrast_corcov
96 , colnames = corcov_tsv_colnames
97 , append = corcov_tsv_append
98 )(tsv)
99 corcov_tsv_colnames <<- FALSE
100 corcov_tsv_append <<- TRUE
101 }
102
103 my_log( "-------------------------- Reading input data --------------------------")
104
105 # read_inputs is defined in w4mcorcov_input.R
106 my_result <- read_inputs(input_env = my_env, failure_action = my_log)
107
108 if ( is.logical(my_result) && my_result) {
109 my_log( "-------------------------- Beginning data processing --------------------------")
110
111 # receiver for result of the call to corcov_calc
112 my_result <- NULL
113
114 # compute and plot the correlation_vs_covariance details plot
115 # The parameter settings here are generally taken from bioconductor ropls::plot.opls source.
116 marVn <- c(4.6, 4.1, 2.6, 1.6)
117 old_par <- par(
118 font = 2 # bold font face
119 , font.axis = 2 # bold font face for axis
120 , font.lab = 2 # bold font face for x and y labels
121 , lwd = 2 # line-width - interpretation is device spcific
122 , mar = marVn # margins
123 , pch = 18 # black diamond plot-character, see help for graphics::points
124 # , mfrow = c(2,2) # two rows by two columns
125 , pty = "s" # force plots to be square
126 )
127 plot2pdf(
128 file.name = my_env$contrast_detail
129 , width = 8
130 , height = 8
131 , plot.function = function() {
132 # plot layout four plots per page
133 layout(matrix(1:4, byrow = TRUE, nrow = 2))
134 my_result <<- corcov_calc(
135 calc_env = my_env
136 , failure_action = my_fatal
137 , progress_action = my_log
138 , corcov_tsv_action = corcov_tsv_action
139 )
140 }
141 )
142 par(old_par)
143
144 my_log( "-------------------------- Finished data processing --------------------------")
145 }
146
147 my_log( "End of the '", modNamC, "' Galaxy module call")
148
149 if (is.logical(my_result) && my_result) {
150 quit(save = "no", status = 0, runLast = TRUE)
151 } else {
152 my_log("failure :(")
153 quit(save = "no", status = 10, runLast = TRUE)
154 }