Mercurial > repos > melpetera > batchcorrection
comparison runit/batchcorrection_runtests.R @ 0:71d83d8920bf draft
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit de79117e6ab856420b87efca3675c7963688f975
author | melpetera |
---|---|
date | Tue, 09 Aug 2016 06:47:41 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:71d83d8920bf |
---|---|
1 #!/usr/bin/env Rscript | |
2 | |
3 ## Package | |
4 ##-------- | |
5 | |
6 library(RUnit) | |
7 | |
8 ## Constants | |
9 ##---------- | |
10 | |
11 testOutDirC <- "output" | |
12 argVc <- commandArgs(trailingOnly = FALSE) | |
13 scriptPathC <- sub("--file=", "", argVc[grep("--file=", argVc)]) | |
14 | |
15 | |
16 ## Functions | |
17 ##----------- | |
18 | |
19 ## Reading tables (matrix or data frame) | |
20 readTableF <- function(fileC, typeC = c("matrix", "dataframe")[1]) { | |
21 | |
22 file.exists(fileC) || stop(paste0("No output file \"", fileC ,"\".")) | |
23 | |
24 switch(typeC, | |
25 matrix = return(t(as.matrix(read.table(file = fileC, | |
26 header = TRUE, | |
27 row.names = 1, | |
28 sep = "\t", | |
29 stringsAsFactors = FALSE)))), | |
30 dataframe = return(read.table(file = fileC, | |
31 header = TRUE, | |
32 row.names = 1, | |
33 sep = "\t", | |
34 stringsAsFactors = FALSE))) | |
35 | |
36 } | |
37 | |
38 ## Call wrapper | |
39 wrapperCallF <- function(paramLs, allLoessL) { | |
40 | |
41 ## Set program path | |
42 wrapperPathC <- file.path(dirname(scriptPathC), "..", | |
43 ifelse(allLoessL, | |
44 "batch_correction_all_loess_wrapper.R", | |
45 "batch_correction_wrapper.R")) | |
46 | |
47 ## Set arguments | |
48 argLs <- NULL | |
49 for (parC in names(paramLs)) | |
50 argLs <- c(argLs, parC, paramLs[[parC]]) | |
51 | |
52 ## Call | |
53 wrapperCallC <- paste(c(wrapperPathC, argLs), collapse = " ") | |
54 | |
55 if(.Platform$OS.type == "windows") | |
56 wrapperCallC <- paste("Rscript", wrapperCallC) | |
57 | |
58 | |
59 print(wrapperCallC) | |
60 | |
61 | |
62 wrapperCodeN <- system(wrapperCallC) | |
63 | |
64 if (wrapperCodeN != 0) | |
65 stop(paste0("Error when running 'batch_correction_", | |
66 ifelse(allLoessL, "all_loess_", ""), | |
67 "wrapper.R'")) | |
68 | |
69 ## Get output | |
70 outLs <- list() | |
71 if ("dataMatrix_out" %in% names(paramLs)) | |
72 outLs[["datMN"]] <- readTableF(paramLs[["dataMatrix_out"]], "matrix") | |
73 if ("sampleMetadata_out" %in% names(paramLs)) | |
74 outLs[["samDF"]] <- readTableF(paramLs[["sampleMetadata_out"]], "dataframe") | |
75 if ("variableMetadata_out" %in% names(paramLs)) | |
76 outLs[["varDF"]] <- readTableF(paramLs[["variableMetadata_out"]], "dataframe") | |
77 if("information" %in% names(paramLs)) | |
78 outLs[["infVc"]] <- readLines(paramLs[["information"]]) | |
79 | |
80 if("out_preNormSummary" %in% names(paramLs)) | |
81 outLs[["sumDF"]] <- readTableF(paramLs[["out_preNormSummary"]], "dataframe") | |
82 | |
83 return(outLs) | |
84 | |
85 } | |
86 | |
87 ## Setting default parameters | |
88 defaultArgF <- function(testInDirC, determineL) { | |
89 | |
90 defaultArgLs <- list() | |
91 | |
92 if(file.exists(file.path(dirname(scriptPathC), testInDirC, "dataMatrix.tsv"))) | |
93 defaultArgLs[["dataMatrix"]] <- file.path(dirname(scriptPathC), testInDirC, "dataMatrix.tsv") | |
94 if(file.exists(file.path(dirname(scriptPathC), testInDirC, "sampleMetadata.tsv"))) | |
95 defaultArgLs[["sampleMetadata"]] <- file.path(dirname(scriptPathC), testInDirC, "sampleMetadata.tsv") | |
96 | |
97 if(!determineL) | |
98 if(file.exists(file.path(dirname(scriptPathC), testInDirC, "variableMetadata.tsv"))) | |
99 defaultArgLs[["variableMetadata"]] <- file.path(dirname(scriptPathC), testInDirC, "variableMetadata.tsv") | |
100 | |
101 if(determineL) { ## determinebc | |
102 | |
103 defaultArgLs[["out_graph_pdf"]] <- file.path(dirname(scriptPathC), testOutDirC, "out_graph.pdf") | |
104 defaultArgLs[["out_preNormSummary"]] <- file.path(dirname(scriptPathC), testOutDirC, "preNormSummary.txt") | |
105 | |
106 } else { ## batchcorrection | |
107 | |
108 defaultArgLs[["dataMatrix_out"]] <- file.path(dirname(scriptPathC), testOutDirC, "dataMatrix.tsv") | |
109 defaultArgLs[["variableMetadata_out"]] <- file.path(dirname(scriptPathC), testOutDirC, "variableMetadata.tsv") | |
110 defaultArgLs[["variable_for_simca"]] <- file.path(dirname(scriptPathC), testOutDirC, "variable_for_simca.tsv") | |
111 defaultArgLs[["graph_output"]] <- file.path(dirname(scriptPathC), testOutDirC, "graph_output.pdf") | |
112 defaultArgLs[["rdata_output"]] <- file.path(dirname(scriptPathC), testOutDirC, "rdata_output.rdata") | |
113 | |
114 } | |
115 | |
116 defaultArgLs | |
117 | |
118 } | |
119 | |
120 ## Main | |
121 ##----- | |
122 | |
123 ## Create output folder | |
124 file.exists(testOutDirC) || dir.create(testOutDirC) | |
125 | |
126 ## Run tests | |
127 test.suite <- defineTestSuite('tests', dirname(scriptPathC), testFileRegexp = paste0('^.*_tests\\.R$'), testFuncRegexp = '^.*$') | |
128 isValidTestSuite(test.suite) | |
129 test.results <- runTestSuite(test.suite) | |
130 print(test.results) | |
131 |