annotate runit/checkformat_runtests.R @ 0:059eb452931e draft

planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
author ethevenot
date Tue, 24 Oct 2017 08:44:02 -0400
parents
children b642f4f87022
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
1 #!/usr/bin/env Rscript
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
2
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
3 ## Package
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
4 ##--------
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
5
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
6 library(RUnit)
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
7
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
8 ## Constants
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
9 ##----------
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
10
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
11 testOutDirC <- "output"
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
12 argVc <- commandArgs(trailingOnly = FALSE)
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
13 scriptPathC <- sub("--file=", "", argVc[grep("--file=", argVc)])
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
14
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
15
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
16 ## Functions
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
17 ##-----------
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
18
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
19 ## Reading tables (matrix or data frame)
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
20 readTableF <- function(fileC, typeC = c("matrix", "dataframe")[1]) {
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
21
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
22 file.exists(fileC) || stop(paste0("No output file \"", fileC ,"\"."))
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
23
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
24 switch(typeC,
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
25 matrix = return(t(as.matrix(read.table(file = fileC,
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
26 header = TRUE,
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
27 row.names = 1,
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
28 sep = "\t",
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
29 stringsAsFactors = FALSE)))),
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
30 dataframe = return(read.table(file = fileC,
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
31 header = TRUE,
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
32 row.names = 1,
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
33 sep = "\t",
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
34 stringsAsFactors = FALSE)))
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
35
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
36 }
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
37
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
38 ## Call wrapper
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
39 wrapperCallF <- function(paramLs) {
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
40
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
41 ## Set program path
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
42 wrapperPathC <- file.path(dirname(scriptPathC), "..", "checkformat_wrapper.R")
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
43
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
44 ## Set arguments
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
45 argLs <- NULL
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
46 for (parC in names(paramLs))
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
47 argLs <- c(argLs, parC, paramLs[[parC]])
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
48
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
49 ## Call
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
50 wrapperCallC <- paste(c(wrapperPathC, argLs), collapse = " ")
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
51
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
52 if(.Platform$OS.type == "windows")
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
53 wrapperCallC <- paste("Rscript", wrapperCallC)
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
54
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
55 wrapperCodeN <- system(wrapperCallC)
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
56
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
57 if (wrapperCodeN != 0)
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
58 stop("Error when running checkformat_wrapper.R.")
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
59
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
60 ## Get output
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
61 outLs <- list()
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
62 if ("dataMatrix_out" %in% names(paramLs))
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
63 outLs[["datMN"]] <- readTableF(paramLs[["dataMatrix_out"]], "matrix")
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
64 if ("sampleMetadata_out" %in% names(paramLs))
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
65 outLs[["samDF"]] <- readTableF(paramLs[["sampleMetadata_out"]], "dataframe")
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
66 if ("variableMetadata_out" %in% names(paramLs))
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
67 outLs[["varDF"]] <- readTableF(paramLs[["variableMetadata_out"]], "dataframe")
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
68 if("information" %in% names(paramLs))
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
69 outLs[["infVc"]] <- readLines(paramLs[["information"]])
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
70
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
71 return(outLs)
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
72 }
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
73
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
74 ## Setting default parameters
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
75 defaultArgF <- function(testInDirC) {
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
76
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
77 defaultArgLs <- list()
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
78 if(file.exists(file.path(dirname(scriptPathC), testInDirC, "dataMatrix.tsv")))
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
79 defaultArgLs[["dataMatrix_in"]] <- file.path(dirname(scriptPathC), testInDirC, "dataMatrix.tsv")
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
80 if(file.exists(file.path(dirname(scriptPathC), testInDirC, "sampleMetadata.tsv")))
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
81 defaultArgLs[["sampleMetadata_in"]] <- file.path(dirname(scriptPathC), testInDirC, "sampleMetadata.tsv")
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
82 if(file.exists(file.path(dirname(scriptPathC), testInDirC, "variableMetadata.tsv")))
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
83 defaultArgLs[["variableMetadata_in"]] <- file.path(dirname(scriptPathC), testInDirC, "variableMetadata.tsv")
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
84
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
85 defaultArgLs[["information"]] <- file.path(dirname(scriptPathC), testOutDirC, "information.txt")
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
86
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
87 defaultArgLs
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
88
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
89 }
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
90
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
91 ## Main
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
92 ##-----
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
93
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
94 ## Create output folder
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
95 file.exists(testOutDirC) || dir.create(testOutDirC)
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
96
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
97 ## Run tests
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
98 test.suite <- defineTestSuite('tests', dirname(scriptPathC), testFileRegexp = paste0('^.*_tests\\.R$'), testFuncRegexp = '^.*$')
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
99 isValidTestSuite(test.suite)
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
100 test.results <- runTestSuite(test.suite)
059eb452931e planemo upload for repository https://github.com/workflow4metabolomics/checkformat.git commit e17f78630b4d21b54a4edd6015d50969ac859d6b
ethevenot
parents:
diff changeset
101 print(test.results)