From 961742d2916b1cc3afa2bd328d4ee0be817bffc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Wiegandt?= Date: Fri, 13 Jul 2018 07:34:25 -0400 Subject: [PATCH] Fixed more style mistakes, added try/catch warning handling --- R/parser.R | 15 +++++++-------- tests/testthat/test_mqparser.R | 34 +++++++++++++++++----------------- 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/R/parser.R b/R/parser.R index 57b8141..475ecb1 100644 --- a/R/parser.R +++ b/R/parser.R @@ -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") @@ -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)) { diff --git a/tests/testthat/test_mqparser.R b/tests/testthat/test_mqparser.R index e36f613..616056c 100644 --- a/tests/testthat/test_mqparser.R +++ b/tests/testthat/test_mqparser.R @@ -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") })