Mercurial > repos > ethevenot > profia
comparison runit/profia_runtests.R @ 0:39ccace77270 draft
planemo upload for repository https://github.com/workflow4metabolomics/profia.git commit 2757590af8c7ba9833ba3bebd7da7f96b20d1128-dirty
author | ethevenot |
---|---|
date | Sun, 26 Mar 2017 17:37:12 -0400 |
parents | |
children | 3f8ae071bdda |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:39ccace77270 |
---|---|
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), "..", "profia_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 print(wrapperCallC) | |
53 | |
54 if(.Platform$OS.type == "windows") | |
55 wrapperCallC <- paste("Rscript", wrapperCallC) | |
56 | |
57 wrapperCodeN <- system(wrapperCallC) | |
58 | |
59 if (wrapperCodeN != 0) | |
60 stop("Error when running profia_wrapper.R.") | |
61 | |
62 ## Get output | |
63 outLs <- list() | |
64 if ("dataMatrix_out" %in% names(paramLs)) | |
65 outLs[["datMN"]] <- readTableF(paramLs[["dataMatrix_out"]], "matrix") | |
66 if ("sampleMetadata_out" %in% names(paramLs)) | |
67 outLs[["samDF"]] <- readTableF(paramLs[["sampleMetadata_out"]], "dataframe") | |
68 if ("variableMetadata_out" %in% names(paramLs)) | |
69 outLs[["varDF"]] <- readTableF(paramLs[["variableMetadata_out"]], "dataframe") | |
70 if("information" %in% names(paramLs)) | |
71 outLs[["infVc"]] <- readLines(paramLs[["information"]]) | |
72 | |
73 return(outLs) | |
74 } | |
75 | |
76 ## Setting default parameters | |
77 defaultArgF <- function(testInDirC) { | |
78 | |
79 defaultArgLs <- list() | |
80 if(file.exists(file.path(dirname(scriptPathC), testInDirC, "dataMatrix.tsv"))) | |
81 defaultArgLs[["dataMatrix_in"]] <- file.path(dirname(scriptPathC), testInDirC, "dataMatrix.tsv") | |
82 if(file.exists(file.path(dirname(scriptPathC), testInDirC, "sampleMetadata.tsv"))) | |
83 defaultArgLs[["sampleMetadata_in"]] <- file.path(dirname(scriptPathC), testInDirC, "sampleMetadata.tsv") | |
84 if(file.exists(file.path(dirname(scriptPathC), testInDirC, "variableMetadata.tsv"))) | |
85 defaultArgLs[["variableMetadata_in"]] <- file.path(dirname(scriptPathC), testInDirC, "variableMetadata.tsv") | |
86 | |
87 defaultArgLs[["dataMatrix_out"]] <- file.path(dirname(scriptPathC), testOutDirC, "dataMatrix.tsv") | |
88 defaultArgLs[["sampleMetadata_out"]] <- file.path(dirname(scriptPathC), testOutDirC, "sampleMetadata.tsv") | |
89 defaultArgLs[["variableMetadata_out"]] <- file.path(dirname(scriptPathC), testOutDirC, "variableMetadata.tsv") | |
90 defaultArgLs[["figure"]] <- file.path(dirname(scriptPathC), testOutDirC, "figure.pdf") | |
91 defaultArgLs[["information"]] <- file.path(dirname(scriptPathC), testOutDirC, "information.txt") | |
92 | |
93 defaultArgLs | |
94 | |
95 } | |
96 | |
97 ## Main | |
98 ##----- | |
99 | |
100 ## Create output folder | |
101 file.exists(testOutDirC) || dir.create(testOutDirC) | |
102 | |
103 ## Run tests | |
104 test.suite <- defineTestSuite('tests', dirname(scriptPathC), testFileRegexp = paste0('^.*_tests\\.R$'), testFuncRegexp = '^.*$') | |
105 isValidTestSuite(test.suite) | |
106 test.results <- runTestSuite(test.suite) | |
107 print(test.results) |