comparison runit/univariate_runtests.R @ 2:09799fc16bc6 draft

planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit 2c0d4d97c208edca1ada2035a7b7af9c4eb31afe
author ethevenot
date Sat, 06 Aug 2016 12:42:42 -0400
parents
children 140290de7986
comparison
equal deleted inserted replaced
1:fdefbc780d2e 2:09799fc16bc6
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) {
40
41 ## Set program path
42 wrapperPathC <- file.path(dirname(scriptPathC), "..", "univariate_wrapper.R")
43
44 ## Set arguments
45 argLs <- NULL
46 for (parC in names(paramLs))
47 argLs <- c(argLs, parC, paramLs[[parC]])
48
49 ## Call
50 wrapperCallC <- paste(c(wrapperPathC, argLs), collapse = " ")
51
52 if(.Platform$OS.type == "windows")
53 wrapperCallC <- paste("Rscript", wrapperCallC)
54
55 wrapperCodeN <- system(wrapperCallC)
56
57 if (wrapperCodeN != 0)
58 stop("Error when running univariate_wrapper.R.")
59
60 ## Get output
61 outLs <- list()
62 if ("dataMatrix_out" %in% names(paramLs))
63 outLs[["datMN"]] <- readTableF(paramLs[["dataMatrix_out"]], "matrix")
64 if ("sampleMetadata_out" %in% names(paramLs))
65 outLs[["samDF"]] <- readTableF(paramLs[["sampleMetadata_out"]], "dataframe")
66 if ("variableMetadata_out" %in% names(paramLs))
67 outLs[["varDF"]] <- readTableF(paramLs[["variableMetadata_out"]], "dataframe")
68 if("information" %in% names(paramLs))
69 outLs[["infVc"]] <- readLines(paramLs[["information"]])
70
71 return(outLs)
72 }
73
74 ## Setting default parameters
75 defaultArgF <- function(testInDirC) {
76
77 defaultArgLs <- list()
78 if(file.exists(file.path(dirname(scriptPathC), testInDirC, "dataMatrix.tsv")))
79 defaultArgLs[["dataMatrix_in"]] <- file.path(dirname(scriptPathC), testInDirC, "dataMatrix.tsv")
80 if(file.exists(file.path(dirname(scriptPathC), testInDirC, "sampleMetadata.tsv")))
81 defaultArgLs[["sampleMetadata_in"]] <- file.path(dirname(scriptPathC), testInDirC, "sampleMetadata.tsv")
82 if(file.exists(file.path(dirname(scriptPathC), testInDirC, "variableMetadata.tsv")))
83 defaultArgLs[["variableMetadata_in"]] <- file.path(dirname(scriptPathC), testInDirC, "variableMetadata.tsv")
84
85 defaultArgLs[["variableMetadata_out"]] <- file.path(dirname(scriptPathC), testOutDirC, "variableMetadata.tsv")
86 defaultArgLs[["information"]] <- file.path(dirname(scriptPathC), testOutDirC, "information.txt")
87
88 defaultArgLs
89
90 }
91
92 ## Main
93 ##-----
94
95 ## Create output folder
96 file.exists(testOutDirC) || dir.create(testOutDirC)
97
98 ## Run tests
99 test.suite <- defineTestSuite('tests', dirname(scriptPathC), testFileRegexp = paste0('^.*_tests\\.R$'), testFuncRegexp = '^.*$')
100 isValidTestSuite(test.suite)
101 test.results <- runTestSuite(test.suite)
102 print(test.results)