Mercurial > repos > ethevenot > heatmap
comparison runit/heatmap_runtests.R @ 1:db1d80e89156 draft
planemo upload for repository https://github.com/workflow4metabolomics/heatmap.git commit 29f9ccf5bd558becff5913528bb998aa7bb82d44
author | ethevenot |
---|---|
date | Sat, 06 Aug 2016 12:18:15 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:ad06aeed02c9 | 1:db1d80e89156 |
---|---|
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), "..", "heatmap_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 heatmap_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[["dataMatrix_out"]] <- file.path(dirname(scriptPathC), testOutDirC, "dataMatrix.tsv") | |
86 defaultArgLs[["sampleMetadata_out"]] <- file.path(dirname(scriptPathC), testOutDirC, "sampleMetadata.tsv") | |
87 defaultArgLs[["variableMetadata_out"]] <- file.path(dirname(scriptPathC), testOutDirC, "variableMetadata.tsv") | |
88 defaultArgLs[["figure"]] <- file.path(dirname(scriptPathC), testOutDirC, "figure.pdf") | |
89 defaultArgLs[["information"]] <- file.path(dirname(scriptPathC), testOutDirC, "information.txt") | |
90 | |
91 defaultArgLs | |
92 | |
93 } | |
94 | |
95 ## Main | |
96 ##----- | |
97 | |
98 ## Create output folder | |
99 file.exists(testOutDirC) || dir.create(testOutDirC) | |
100 | |
101 ## Run tests | |
102 test.suite <- defineTestSuite('tests', dirname(scriptPathC), testFileRegexp = paste0('^.*_tests\\.R$'), testFuncRegexp = '^.*$') | |
103 isValidTestSuite(test.suite) | |
104 test.results <- runTestSuite(test.suite) | |
105 print(test.results) |