|
4
|
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), "..", "qualitymetrics_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 qualitymetrics_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[["sampleMetadata_out"]] <- file.path(dirname(scriptPathC), testOutDirC, "sampleMetadata.tsv")
|
|
|
86 defaultArgLs[["variableMetadata_out"]] <- file.path(dirname(scriptPathC), testOutDirC, "variableMetadata.tsv")
|
|
|
87 defaultArgLs[["figure"]] <- file.path(dirname(scriptPathC), testOutDirC, "figure.pdf")
|
|
|
88 defaultArgLs[["information"]] <- file.path(dirname(scriptPathC), testOutDirC, "information.txt")
|
|
|
89
|
|
|
90 defaultArgLs
|
|
|
91
|
|
|
92 }
|
|
|
93
|
|
|
94 ## Main
|
|
|
95 ##-----
|
|
|
96
|
|
|
97 ## Create output folder
|
|
|
98 file.exists(testOutDirC) || dir.create(testOutDirC)
|
|
|
99
|
|
|
100 ## Run tests
|
|
|
101 test.suite <- defineTestSuite('tests', dirname(scriptPathC), testFileRegexp = paste0('^.*_tests\\.R$'), testFuncRegexp = '^.*$')
|
|
|
102 isValidTestSuite(test.suite)
|
|
|
103 test.results <- runTestSuite(test.suite)
|
|
|
104 print(test.results)
|
|
|
105
|
|
|
106
|