Mercurial > repos > ethevenot > univariate
comparison univariate_wrapper.R @ 0:ef64d3752050 draft
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
author | ethevenot |
---|---|
date | Wed, 27 Jul 2016 11:44:34 -0400 |
parents | |
children | 09799fc16bc6 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:ef64d3752050 |
---|---|
1 #!/usr/bin/env Rscript | |
2 | |
3 library(batch) ## parseCommandArgs | |
4 | |
5 source_local <- function(fname){ | |
6 argv <- commandArgs(trailingOnly = FALSE) | |
7 base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)) | |
8 source(paste(base_dir, fname, sep="/")) | |
9 } | |
10 | |
11 source_local("univariate_script.R") | |
12 | |
13 argVc <- unlist(parseCommandArgs(evaluate=FALSE)) | |
14 | |
15 | |
16 #### Start_of_tested_code <- function() {} | |
17 | |
18 | |
19 ##------------------------------ | |
20 ## Initializing | |
21 ##------------------------------ | |
22 | |
23 ## options | |
24 ##-------- | |
25 | |
26 strAsFacL <- options()$stringsAsFactors | |
27 options(stringsAsFactors = FALSE) | |
28 | |
29 ## packages | |
30 ##--------- | |
31 | |
32 library(PMCMR) | |
33 | |
34 ## constants | |
35 ##---------- | |
36 | |
37 modNamC <- "Univariate" ## module name | |
38 | |
39 topEnvC <- environment() | |
40 flagC <- "\n" | |
41 | |
42 ## functions | |
43 ##---------- | |
44 | |
45 flgF <- function(tesC, | |
46 envC = topEnvC, | |
47 txtC = NA) { ## management of warning and error messages | |
48 | |
49 tesL <- eval(parse(text = tesC), envir = envC) | |
50 | |
51 if(!tesL) { | |
52 | |
53 sink(NULL) | |
54 stpTxtC <- ifelse(is.na(txtC), | |
55 paste0(tesC, " is FALSE"), | |
56 txtC) | |
57 | |
58 stop(stpTxtC, | |
59 call. = FALSE) | |
60 | |
61 } | |
62 | |
63 } ## flgF | |
64 | |
65 ## log file | |
66 ##--------- | |
67 | |
68 sink(argVc["information"]) | |
69 | |
70 cat("\nStart of the '", modNamC, "' Galaxy module call: ", | |
71 format(Sys.time(), "%a %d %b %Y %X"), "\n", sep="") | |
72 | |
73 ## loading | |
74 ##-------- | |
75 | |
76 datMN <- t(as.matrix(read.table(argVc["dataMatrix_in"], | |
77 check.names = FALSE, | |
78 header = TRUE, | |
79 row.names = 1, | |
80 sep = "\t"))) | |
81 | |
82 samDF <- read.table(argVc["sampleMetadata_in"], | |
83 check.names = FALSE, | |
84 header = TRUE, | |
85 row.names = 1, | |
86 sep = "\t") | |
87 | |
88 varDF <- read.table(argVc["variableMetadata_in"], | |
89 check.names = FALSE, | |
90 header = TRUE, | |
91 row.names = 1, | |
92 sep = "\t") | |
93 | |
94 tesC <- argVc["tesC"] | |
95 | |
96 ## checking | |
97 ##--------- | |
98 | |
99 flgF("identical(rownames(datMN), rownames(samDF))", txtC = "Column names of the dataMatrix are not identical to the row names of the sampleMetadata; check your data with the 'Check Format' module in the 'Quality Control' section") | |
100 flgF("identical(colnames(datMN), rownames(varDF))", txtC = "Row names of the dataMatrix are not identical to the row names of the variableMetadata; check your data with the 'Check Format' module in the 'Quality Control' section") | |
101 | |
102 flgF("argVc['facC'] %in% colnames(samDF)", txtC = paste0("Required factor of interest '", argVc['facC'], "' could not be found in the column names of the sampleMetadata")) | |
103 flgF("mode(samDF[, argVc['facC']]) %in% c('character', 'numeric')", txtC = paste0("The '", argVc['facC'], "' column of the sampleMetadata should contain either number only, or character only")) | |
104 | |
105 flgF("!(tesC %in% c('ttest', 'wilcoxon')) || (mode(samDF[, argVc['facC']]) == 'character' && length(unique(samDF[, argVc['facC']])) == 2)", txtC = paste0("For 'ttest' and 'wilcoxon', the chosen factor column ('", argVc['facC'], "') of the sampleMetadata should contain characters with only two different classes")) | |
106 flgF("!(tesC %in% c('anova', 'kruskal')) || (mode(samDF[, argVc['facC']]) == 'character' && length(unique(samDF[, argVc['facC']])) > 2)", txtC = paste0("For 'anova' and 'kruskal', the chosen factor column ('", argVc['facC'], "') of the sampleMetadata should contain characters with at least three different classes")) | |
107 flgF("!(tesC %in% c('pearson', 'spearman')) || mode(samDF[, argVc['facC']]) == 'numeric'", txtC = paste0("For 'pearson' and 'spearman', the chosen factor column ('", argVc['facC'], "') of the sampleMetadata should contain numbers only")) | |
108 | |
109 flgF("argVc['adjC'] %in% c('holm', 'hochberg', 'hommel', 'bonferroni', 'BH', 'BY', 'fdr', 'none')") | |
110 | |
111 flgF("0 <= as.numeric(argVc['thrN']) && as.numeric(argVc['thrN']) <= 1", | |
112 txtC = "(corrected) p-value threshold must be between 0 and 1") | |
113 | |
114 | |
115 ##------------------------------ | |
116 ## Computation | |
117 ##------------------------------ | |
118 | |
119 | |
120 varDF <- univariateF(datMN = datMN, | |
121 samDF = samDF, | |
122 varDF = varDF, | |
123 facC = argVc["facC"], | |
124 tesC = tesC, | |
125 adjC = argVc["adjC"], | |
126 thrN = as.numeric(argVc["thrN"])) | |
127 | |
128 | |
129 ##------------------------------ | |
130 ## Ending | |
131 ##------------------------------ | |
132 | |
133 | |
134 ## saving | |
135 ##-------- | |
136 | |
137 varDF <- cbind.data.frame(variableMetadata = rownames(varDF), | |
138 varDF) | |
139 write.table(varDF, | |
140 file = argVc["variableMetadata_out"], | |
141 quote = FALSE, | |
142 row.names = FALSE, | |
143 sep = "\t") | |
144 | |
145 ## closing | |
146 ##-------- | |
147 | |
148 cat("\nEnd of '", modNamC, "' Galaxy module call: ", | |
149 as.character(Sys.time()), "\n", sep = "") | |
150 | |
151 sink() | |
152 | |
153 options(stringsAsFactors = strAsFacL) | |
154 | |
155 | |
156 #### End_of_tested_code <- function() {} | |
157 | |
158 | |
159 rm(list = ls()) |