Mercurial > repos > ethevenot > transformation
comparison transformation_wrapper.R @ 0:eacea1349a7c draft
planemo upload for repository https://github.com/workflow4metabolomics/transformation.git commit 83f2d1045c0bf086bbe2de5204cd5c1d8354116f
author | ethevenot |
---|---|
date | Fri, 29 Jul 2016 12:11:01 -0400 |
parents | |
children | d9e05021553c |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:eacea1349a7c |
---|---|
1 #!/usr/bin/Rscript --vanilla --slave --no-site-file | |
2 | |
3 | |
4 library(batch) ## parseCommandArgs | |
5 | |
6 source_local <- function(fname){ | |
7 argv <- commandArgs(trailingOnly = FALSE) | |
8 base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)) | |
9 source(paste(base_dir, fname, sep="/")) | |
10 } | |
11 | |
12 source_local("transformation_script.R") | |
13 | |
14 argVc <- unlist(parseCommandArgs(evaluate=FALSE)) | |
15 | |
16 | |
17 #### Start_of_tested_code <- function() {} | |
18 | |
19 | |
20 ##------------------------------ | |
21 ## Initializing | |
22 ##------------------------------ | |
23 | |
24 ## options | |
25 ##-------- | |
26 | |
27 strAsFacL <- options()[["stringsAsFactors"]] | |
28 options(stringsAsFactors=FALSE) | |
29 | |
30 ## constants | |
31 ##---------- | |
32 | |
33 modNamC <- "Transformation" ## module name | |
34 metVc <- c("log2", "log10") ## available methods | |
35 | |
36 topEnvC <- environment() | |
37 flagC <- "\n" | |
38 | |
39 ## functions | |
40 ##---------- | |
41 | |
42 flgF <- function(tesC, | |
43 envC = topEnvC, | |
44 txtC = NA) { ## management of warning and error messages | |
45 | |
46 tesL <- eval(parse(text = tesC), envir = envC) | |
47 | |
48 if(!tesL) { | |
49 | |
50 sink(NULL) | |
51 stpTxtC <- ifelse(is.na(txtC), | |
52 paste0(tesC, " is FALSE"), | |
53 txtC) | |
54 | |
55 stop(stpTxtC, | |
56 call. = FALSE) | |
57 | |
58 } | |
59 | |
60 } ## flgF | |
61 | |
62 ## log file | |
63 ##--------- | |
64 | |
65 sink(argVc[["information"]]) | |
66 | |
67 cat("\nStart of the '", modNamC, "' module: ", | |
68 format(Sys.time(), "%a %d %b %Y %X"), "\n", sep="") | |
69 | |
70 ## loading | |
71 ##-------- | |
72 | |
73 datMN <- t(as.matrix(read.table(argVc[["dataMatrix_in"]], | |
74 check.names = FALSE, | |
75 header = TRUE, | |
76 row.names = 1, | |
77 sep = "\t"))) | |
78 | |
79 metC <- argVc[["method"]] | |
80 | |
81 ## checking | |
82 ##--------- | |
83 | |
84 flgF("metC %in% metVc", txtC = paste0("Transformation method must be either '", paste(metVc, collapse = "', '"), "'")) | |
85 | |
86 | |
87 ##------------------------------ | |
88 ## Computation | |
89 ##------------------------------ | |
90 | |
91 | |
92 datMN <- transformF(datMN = datMN, ## dataMatrix | |
93 metC = metC) ## transformation method | |
94 | |
95 | |
96 ##------------------------------ | |
97 ## Ending | |
98 ##------------------------------ | |
99 | |
100 | |
101 ## saving | |
102 ##------- | |
103 | |
104 datDF <- cbind.data.frame(dataMatrix = colnames(datMN), | |
105 as.data.frame(t(datMN))) | |
106 write.table(datDF, | |
107 file = argVc[["dataMatrix_out"]], | |
108 quote = FALSE, | |
109 row.names = FALSE, | |
110 sep = "\t") | |
111 | |
112 ## ending | |
113 ##------- | |
114 | |
115 cat("\nEnd of the '", modNamC, "' Galaxy module call: ", | |
116 format(Sys.time(), "%a %d %b %Y %X"), "\n", sep = "") | |
117 | |
118 sink() | |
119 | |
120 options(stringsAsFactors = strAsFacL) | |
121 | |
122 | |
123 #### End_of_tested_code <- function() {} | |
124 | |
125 | |
126 rm(list = ls()) |