Skip to content
This repository has been archived by the owner. It is now read-only.

Commit

Permalink
Fixed more style mistakes, added try/catch warning handling
Browse files Browse the repository at this point in the history
  • Loading branch information
renewiegandt committed Jul 13, 2018
1 parent 6111a8a commit 961742d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
15 changes: 7 additions & 8 deletions R/parser.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ parse_MaxQuant <- function(proteinGroups_in, summary_in, outfile, outfile_reduce
# @return String level of given column
get_sample_level <- function(col_head, isSample, full_list) {
# Get the level of all 'sample' columns.
# Default: level <- "sample"
# Default: level is "sample"
if (grepl("Ratio", col_head, perl = TRUE)) {
if (grepl("type", col_head, perl = TRUE)) return("feature")
return("contrast")
Expand Down Expand Up @@ -191,14 +191,13 @@ parse_MaxQuant <- function(proteinGroups_in, summary_in, outfile, outfile_reduce
proteinGroups <- data.table::fread(proteinGroups_in, header = TRUE, quote = "")
summary_file <- data.table::fread(summary_in, header = TRUE)

if (config == "") {
meta_config <- tryCatch({
rjson::fromJSON(file = config)
}, error = function(cond) {
stop("Could not read config file")
}

meta_config <- tryCatch({rjson::fromJSON(file = config)},
error = function(cond) {
stop("Could not read config file")
})
}, warning = function(w) {
stop("Could not read config file")
})

# getting experiment names
if ("Experiment" %in% colnames(summary_file)) {
Expand Down
34 changes: 17 additions & 17 deletions tests/testthat/test_mqparser.R
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
context("MaxQuant parser")

testthat::test_that("all needed input parameteres are given", {
expect_error(wilson::parse_MaxQuant(),"The proteinGroups file was not given")
expect_error(wilson::parse_MaxQuant(proteinGroups_in = "/path/path/"),"The summary file was not given")
expect_error(wilson::parse_MaxQuant(proteinGroups_in = "/path/path/",summary_in = "/path/path/"),
test_that("all needed input parameteres are given", {
expect_error(wilson::parse_MaxQuant(), "The proteinGroups file was not given")
expect_error(wilson::parse_MaxQuant(proteinGroups_in = "./path/path/"), "The summary file was not given")
expect_error(wilson::parse_MaxQuant(proteinGroups_in = "./path/path/", summary_in = "./path/path/"),
"The output file was not given")
expect_error(wilson::parse_MaxQuant(proteinGroups_in = "/path/path/",summary_in = "/path/path/",
outfile = "/path/path/"),"The output_reduced file was not given")
expect_error(wilson::parse_MaxQuant(proteinGroups_in = "./path/path/", summary_in = "./path/path/",
outfile = "./path/path/"), "The output_reduced file was not given")
})

testthat::test_that("mq_parser",{
test_that("mq_parser", {

expect_error(wilson::parse_MaxQuant(proteinGroups_in = system.file("/tests/testthat", "proteinGroups_test.txt", package = "wilson"),
summary_in = system.file("/tests/testthat", "summary_test_2.txt", package = "wilson"),
expect_error(wilson::parse_MaxQuant(proteinGroups_in = "proteinGroups_test.txt",
summary_in = "summary_test_2.txt",
outfile = "./out", outfile_reduced = "./outres" ),
"wrong format on summary file: column \'Experiment\' misssing")
expect_true(wilson::parse_MaxQuant(proteinGroups_in = system.file("/tests/testthat", "proteinGroups_test.txt", package = "wilson"),
summary_in = system.file("/tests/testthat", "summary_test.txt", package = "wilson"),
outfile = "./out", outfile_reduced = "./outres", config = system.file("/tests/testthat", "success_config.json", package = "wilson")))
expect_error(wilson::parse_MaxQuant(proteinGroups_in = system.file("/tests/testthat", "proteinGroups_test.txt", package = "wilson"),
summary_in = system.file("/tests/testthat", "summary_test.txt", package = "wilson"),
expect_true(wilson::parse_MaxQuant(proteinGroups_in = "proteinGroups_test.txt",
summary_in = "summary_test.txt",
outfile = "./out", outfile_reduced = "./outres", config = "success_config.json"))
expect_error(wilson::parse_MaxQuant(proteinGroups_in = "proteinGroups_test.txt",
summary_in = "summary_test.txt",
outfile = "./out", outfile_reduced = "./outres", config = "" ),
"Could not read config file")
expect_error(wilson::parse_MaxQuant(proteinGroups_in = system.file("/tests/testthat", "proteinGroups_test.txt", package = "wilson"),
summary_in = system.file("/tests/testthat", "summary_test.txt", package = "wilson"),
outfile = "./out", outfile_reduced = "./outres", config = system.file("/tests/testthat", "fail_config.json", package = "wilson") ),
expect_error(wilson::parse_MaxQuant(proteinGroups_in = "proteinGroups_test.txt",
summary_in = "summary_test.txt",
outfile = "./out", outfile_reduced = "./outres", config = "fail_config.json" ),
"reduced_list is missing in config file")
})

0 comments on commit 961742d

Please sign in to comment.