From d37339d1a1f1fa8e29562b2b7c979e82de81e79d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Wiegandt?= Date: Wed, 11 Jul 2018 09:22:51 -0400 Subject: [PATCH 01/13] Added tests for parse_MaxQuant --- R/parser.R | 19 +- tests/testthat.R | 4 + tests/testthat/fail_config.json | 291 ++++++++++++++++++++++++++ tests/testthat/proteinGroups_test.txt | 2 + tests/testthat/summary_test.txt | 3 + tests/testthat/summary_test_2.txt | 3 + tests/testthat/test_mqparser.R | 30 +++ 7 files changed, 350 insertions(+), 2 deletions(-) create mode 100644 tests/testthat.R create mode 100644 tests/testthat/fail_config.json create mode 100755 tests/testthat/proteinGroups_test.txt create mode 100755 tests/testthat/summary_test.txt create mode 100755 tests/testthat/summary_test_2.txt create mode 100644 tests/testthat/test_mqparser.R diff --git a/R/parser.R b/R/parser.R index 9827548..cdba934 100644 --- a/R/parser.R +++ b/R/parser.R @@ -25,6 +25,8 @@ #' @param version pre-header information about version (optional) #' @param experiment_id pre-header information about experiment id (optional) #' +#' @return 1 on success +#' #' @export parse_MaxQuant <- function(proteinGroups_in, summary_in, outfile, outfile_reduced, config = system.file("extdata", "parser_MaxQuant_config.json", package = "wilson"), delimiter = ";", format = NULL, version = NULL, experiment_id = NULL){ if (missing(proteinGroups_in)) { @@ -188,13 +190,21 @@ parse_MaxQuant <- function(proteinGroups_in, summary_in, outfile, outfile_reduce # reading files in data tables proteinGroups <- data.table::fread(proteinGroups_in, header = TRUE, quote = "") summary_file <- data.table::fread(summary_in, header = TRUE) - meta_config <- rjson::fromJSON(file = config) + meta_config <- tryCatch({rjson::fromJSON(file = config)}, + error=function(cond){ + stop("Could not read config file") + }) # getting experiment names - exp_names <- (unique(summary_file[Experiment != "", Experiment])) + if("Experiment" %in% colnames(summary_file)){ + exp_names <- (unique(summary_file[Experiment != "", Experiment])) + } else { + stop("wrong format on summary file: column \'Experiment\' misssing") + } meta <- get_meta_from_config(meta_config = meta_config) + sample_scores <- meta_config$type_scores sample_ratios <- meta_config$type_ratios sample_probability <- meta_config$type_probability @@ -203,6 +213,9 @@ parse_MaxQuant <- function(proteinGroups_in, summary_in, outfile, outfile_reduce sample_ary <- meta_config$type_array reduced_list <- meta_config$reduced_list full_sample_list <- c(sample_scores, sample_ratios, sample_probability, sample_category, sample_ary) + if(is.null(reduced_list)){ + stop("reduced_list is missing in config file") + } # get column names col_names <- colnames(proteinGroups) @@ -286,6 +299,8 @@ parse_MaxQuant <- function(proteinGroups_in, summary_in, outfile, outfile_reduce # writing reduced CLARION file write_clarion_file(meta = meta_reduced, out = outfile_reduced, format = format, version = version, exp_id = experiment_id, pGroups = proteinGroups, delimiter = delimiter) + + return(1) } #' Method to parse input file. diff --git a/tests/testthat.R b/tests/testthat.R new file mode 100644 index 0000000..a7d9752 --- /dev/null +++ b/tests/testthat.R @@ -0,0 +1,4 @@ +library(testthat) +library(wilson) + +test_check("wilson") diff --git a/tests/testthat/fail_config.json b/tests/testthat/fail_config.json new file mode 100644 index 0000000..8d82f3b --- /dev/null +++ b/tests/testthat/fail_config.json @@ -0,0 +1,291 @@ +{ + "meta": [ + { + "col_name": "Protein IDs", + "level": "feature", + "type": "array", + "label": "IDs", + "sublabel": "proteins" + }, + { + "col_name": "Majority protein IDs", + "level": "feature", + "type": "array", + "label": "IDs", + "sublabel": "majority protein" + }, + { + "col_name": "Protein names", + "level": "feature", + "type": "array", + "label": "protein names", + "sublabel": "" + }, + { + "col_name": "Gene names", + "level": "feature", + "type": "array", + "label": "gene names", + "sublabel": "" + }, + { + "col_name": "Fasta headers", + "level": "feature", + "type": "array", + "label": "fasta headers", + "sublabel": "" + }, + { + "col_name": "id", + "level": "feature", + "type": "unique_id", + "label": "unique identifier", + "sublabel": "" + }, + { + "col_name": "Peptide IDs", + "level": "feature", + "type": "array", + "label": "IDs", + "sublabel": "peptide" + }, + { + "col_name": "Mod. peptide IDs", + "level": "feature", + "type": "array", + "label": "IDs", + "sublabel": "mod. peptide" + }, + { + "col_name": "Evidence IDs", + "level": "feature", + "type": "array", + "label": "IDs", + "sublabel": "evidence" + }, + { + "col_name": "MS/MS IDs", + "level": "feature", + "type": "array", + "label": "IDs", + "sublabel": "MS/MS" + }, + { + "col_name": "Mol. weight [kDa]", + "level": "feature", + "type": "category", + "label": "Mol. weight [kDa]", + "sublabel": "" + }, + { + "col_name": "Sequence length", + "level": "feature", + "type": "category", + "label": "length", + "sublabel": "Sequence" + }, + { + "col_name": "Sequence lengths", + "level": "feature", + "type": "array", + "label": "lengths", + "sublabel": "Sequence" + }, + { + "col_name": "Reverse", + "level": "feature", + "type": "category", + "label": "Reverse", + "sublabel": "" + }, + { + "col_name": "Potential contaminant", + "level": "feature", + "type": "category", + "label": "Potential contaminant", + "sublabel": "" + }, + { + "col_name": "Oxidation (M) site IDs", + "level": "feature", + "type": "array", + "label": "IDs", + "sublabel": "Oxidation (M) site" + }, + { + "col_name": "Oxidation (M) site positions", + "level": "feature", + "type": "array", + "label": "positions", + "sublabel": "Oxidation (M) site" + }, + { + "col_name": "Phospho (STY) site IDs", + "level": "feature", + "type": "array", + "label": "IDs", + "sublabel": "Phospho (STY) site" + }, + { + "col_name": "Phospho (STY) site positions", + "level": "feature", + "type": "array", + "label": "positions", + "sublabel": "Phospho (STY) site" + }, + { + "col_name": "Peptide counts (all)", + "level": "condition", + "type": "array", + "label": "counts", + "sublabel": "all peptide" + }, + { + "col_name": "Peptide counts (razor+unique)", + "level": "condition", + "type": "array", + "label": "counts", + "sublabel": "razor+unique peptides" + }, + { + "col_name": "Peptide counts (unique)", + "level": "condition", + "type": "array", + "label": "counts", + "sublabel": "unique peptides" + }, + { + "col_name": "Number of proteins", + "level": "condition", + "type": "score", + "label": "count", + "sublabel": "proteins" + }, + { + "col_name": "Peptides", + "level": "condition", + "type": "score", + "label": "count", + "sublabel": "Peptides" + }, + { + "col_name": "Razor + unique peptides", + "level": "condition", + "type": "score", + "label": "count", + "sublabel": "Razor + unique peptides" + }, + { + "col_name": "Unique peptides", + "level": "condition", + "type": "score", + "label": "count", + "sublabel": "Unique peptides" + }, + { + "col_name": "MS/MS count", + "level": "condition", + "type": "score", + "label": "count", + "sublabel": "MS/MS" + }, + { + "col_name": "Fraction average", + "level": "condition", + "type": "score", + "label": "fraction", + "sublabel": "average" + }, + { + "col_name": "Best MS/MS", + "level": "condition", + "type": "array", + "label": "MS/MS", + "sublabel": "best" + }, + { + "col_name": "Intensity", + "level": "condition", + "type": "score", + "label": "Intensity", + "sublabel": "" + }, + { + "col_name": "Intensity L", + "level": "condition", + "type": "score", + "label": "Intensity", + "sublabel": "L" + }, + { + "col_name": "Intensity M", + "level": "condition", + "type": "score", + "label": "Intensity", + "sublabel": "M" + }, + { + "col_name": "Intensity H", + "level": "condition", + "type": "score", + "label": "Intensity", + "sublabel": "H" + }, + { + "col_name": "Q-value", + "level": "condition", + "type": "probability", + "label": "q-value", + "sublabel": "" + }, + { + "col_name": "Score", + "level": "condition", + "type": "probability", + "label": "score", + "sublabel": "" + }, + { + "col_name": "Unique sequence coverage [%]", + "level": "condition", + "type": "ratio", + "label": "sequence coverage", + "sublabel": "Unique" + }, + { + "col_name": "Unique + razor sequence coverage [%]", + "level": "condition", + "type": "ratio", + "label": "sequence coverage", + "sublabel": "Unique + razor" + }, + { + "col_name": "Sequence coverage [%]", + "level": "condition", + "type": "ratio", + "label": "sequence coverage", + "sublabel": "" + }, + { + "col_name": "Only identified by site", + "level": "feature", + "type": "category", + "label": "identified by site", + "sublabel": "" + }, + { + "col_name": "Peptide is razor", + "level": "condition", + "type": "array", + "label": "peptide", + "sublabel": "is razor" + } + ], + + "type_scores": + ["Peptides", "Razor + unique peptides", "Unique peptides", "Ratio M/L count", "Ratio M/L iso-count", "Ratio H/L count", "Ratio H/L iso-count" , + "Ratio H/M count", "Ratio H/M iso-count", "Intensity", "Intensity L", "Intensity M", "Intensity H", "MS/MS count", "LFQ intensity", "Reporter intensity count", + "Reporter intensity corrected", "Reporter intensity", "Fraction", "iBAQ"] + +} + diff --git a/tests/testthat/proteinGroups_test.txt b/tests/testthat/proteinGroups_test.txt new file mode 100755 index 0000000..e83a7ff --- /dev/null +++ b/tests/testthat/proteinGroups_test.txt @@ -0,0 +1,2 @@ +Protein IDs Majority protein IDs Peptide counts (all) Peptide counts (razor+unique) Peptide counts (unique) Protein names Gene names Fasta headers Number of proteins Peptides Razor + unique peptides Unique peptides Peptides Exp1 Peptides Exp2 Razor + unique peptides Exp1 Razor + unique peptides Exp2 Unique peptides Exp1 Unique peptides Exp2 Sequence coverage [%] Unique + razor sequence coverage [%] Unique sequence coverage [%] Mol. weight [kDa] Sequence length Sequence lengths Fraction average Fraction 1 Fraction 2 Fraction 3 Fraction 4 Fraction 5 Fraction 6 Fraction 7 Fraction 8 Q-value Score Reporter intensity corrected 0 Reporter intensity corrected 1 Reporter intensity corrected 2 Reporter intensity corrected 3 Reporter intensity corrected 4 Reporter intensity corrected 5 Reporter intensity 0 Reporter intensity 1 Reporter intensity 2 Reporter intensity 3 Reporter intensity 4 Reporter intensity 5 Reporter intensity count 0 Reporter intensity count 1 Reporter intensity count 2 Reporter intensity count 3 Reporter intensity count 4 Reporter intensity count 5 Reporter intensity corrected 0 Exp1 Reporter intensity corrected 1 Exp1 Reporter intensity corrected 2 Exp1 Reporter intensity corrected 3 Exp1 Reporter intensity corrected 4 Exp1 Reporter intensity corrected 5 Exp1 Reporter intensity corrected 0 Exp2 Reporter intensity corrected 1 Exp2 Reporter intensity corrected 2 Exp2 Reporter intensity corrected 3 Exp2 Reporter intensity corrected 4 Exp2 Reporter intensity corrected 5 Exp2 Reporter intensity 0 Exp1 Reporter intensity 1 Exp1 Reporter intensity 2 Exp1 Reporter intensity 3 Exp1 Reporter intensity 4 Exp1 Reporter intensity 5 Exp1 Reporter intensity 0 Exp2 Reporter intensity 1 Exp2 Reporter intensity 2 Exp2 Reporter intensity 3 Exp2 Reporter intensity 4 Exp2 Reporter intensity 5 Exp2 Reporter intensity count 0 Exp1 Reporter intensity count 1 Exp1 Reporter intensity count 2 Exp1 Reporter intensity count 3 Exp1 Reporter intensity count 4 Exp1 Reporter intensity count 5 Exp1 Reporter intensity count 0 Exp2 Reporter intensity count 1 Exp2 Reporter intensity count 2 Exp2 Reporter intensity count 3 Exp2 Reporter intensity count 4 Exp2 Reporter intensity count 5 Exp2 Sequence coverage Exp1 [%] Sequence coverage Exp2 [%] Intensity Intensity Exp1 Intensity Exp2 MS/MS count Only identified by site Reverse Potential contaminant id Peptide IDs Peptide is razor Mod. peptide IDs Evidence IDs MS/MS IDs Best MS/MS Oxidation (M) site IDs Oxidation (M) site positions +A0A068BEQ2;P50171;P50171-2;G3UX44 A0A068BEQ2;P50171;P50171-2;G3UX44 11;11;11;10 11;11;11;10 11;11;11;10 Estradiol 17-beta-dehydrogenase 8 H2-Ke6;Hsd17b8 tr|A0A068BEQ2|A0A068BEQ2_MOUSE H2-K region expressed gene 6, isoform CRA_a OS=Mus musculus GN=H2-Ke6 PE=2 SV=1;sp|P50171|DHB8_MOUSE Estradiol 17-beta-dehydrogenase 8 OS=Mus musculus GN=Hsd17b8 PE=1 SV=2;sp|P50171-2|DHB8_MOUSE Isoform Long of Estradiol 17-b 4 11 11 11 9 9 9 9 9 9 61.4 61.4 61.4 26.587 259 259;259;274;234 6.32 2 1 1 3 4 4 5 17 0 309.9 422810 381560 394980 374200 414580 428320 405880 379740 401170 384810 418890 414670 29 29 29 29 29 29 159850 141420 149170 147480 162360 166190 262960 240140 245810 226710 252220 262130 153390 140950 151450 151320 164040 160930 252490 238790 249720 233490 254850 253730 12 12 12 12 12 12 17 17 17 17 17 17 46.3 51 8493600000 3090200000 5403400000 42 0 1707;5068;5754;17624;17838;18452;24153;26755;37315;45123;45334 True;True;True;True;True;True;True;True;True;True;True 1818;5449;5450;6176;18892;19121;19782;25924;28715;40406;48814;49037 5720;5721;5722;5723;5724;16176;16177;18100;56337;56338;56339;56340;57035;57036;57037;57038;57039;57040;59065;59066;59067;59068;77499;77500;85797;119780;119781;119782;119783;145479;145480;145481;145482;145483;146163;146164;146165 6359;6360;6361;6362;6363;6364;6365;6366;17918;17919;20019;62610;62611;62612;62613;63369;63370;63371;63372;63373;63374;65658;65659;65660;65661;86004;86005;86006;86007;95195;133113;133114;133115;133116;161672;161673;161674;161675;161676;162411;162412;162413 6366;17919;20019;62610;63370;65660;86006;95195;133113;161676;162411 0;1 113;204 \ No newline at end of file diff --git a/tests/testthat/summary_test.txt b/tests/testthat/summary_test.txt new file mode 100755 index 0000000..0c27eca --- /dev/null +++ b/tests/testthat/summary_test.txt @@ -0,0 +1,3 @@ +Raw file Experiment +Bernd baut bemüht bienen bei blumenbergen Exp1 +Dieter drückt daknbar den dünnen Daniel durch die dicke dauerbelstete Dachrinne Exp2 \ No newline at end of file diff --git a/tests/testthat/summary_test_2.txt b/tests/testthat/summary_test_2.txt new file mode 100755 index 0000000..b487418 --- /dev/null +++ b/tests/testthat/summary_test_2.txt @@ -0,0 +1,3 @@ +Raw file False +Bernd baut bemüht bienen bei blumenbergen Exp1 +Dieter drückt daknbar den dünnen Daniel durch die dicke dauerbelastete Dachrinne Exp2 \ No newline at end of file diff --git a/tests/testthat/test_mqparser.R b/tests/testthat/test_mqparser.R new file mode 100644 index 0000000..bbfe747 --- /dev/null +++ b/tests/testthat/test_mqparser.R @@ -0,0 +1,30 @@ +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/"), + "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") +}) + +testthat::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"), + outfile = "./out", outfile_reduced = "./outres" ), + "wrong format on summary file: column \'Experiment\' misssing") + expect_equal(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" ), + 1) + 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 = "" ), + "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") ), + "reduced_list is missing in config file") +}) From f35d7c96639a9eaef91221f13324b9efce1d6908 Mon Sep 17 00:00:00 2001 From: renewiegandt Date: Thu, 12 Jul 2018 13:18:59 +0200 Subject: [PATCH 02/13] changed return value to TRUE --- R/parser.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/parser.R b/R/parser.R index cdba934..103c4b8 100644 --- a/R/parser.R +++ b/R/parser.R @@ -25,7 +25,7 @@ #' @param version pre-header information about version (optional) #' @param experiment_id pre-header information about experiment id (optional) #' -#' @return 1 on success +#' @return TRUE on success #' #' @export parse_MaxQuant <- function(proteinGroups_in, summary_in, outfile, outfile_reduced, config = system.file("extdata", "parser_MaxQuant_config.json", package = "wilson"), delimiter = ";", format = NULL, version = NULL, experiment_id = NULL){ @@ -300,7 +300,7 @@ parse_MaxQuant <- function(proteinGroups_in, summary_in, outfile, outfile_reduce write_clarion_file(meta = meta_reduced, out = outfile_reduced, format = format, version = version, exp_id = experiment_id, pGroups = proteinGroups, delimiter = delimiter) - return(1) + return(TRUE) } #' Method to parse input file. From ddc89ce601b8b2b187d097324cdcf45a71a9b047 Mon Sep 17 00:00:00 2001 From: renewiegandt Date: Thu, 12 Jul 2018 13:22:40 +0200 Subject: [PATCH 03/13] Fixed typo --- tests/testthat/summary_test.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/summary_test.txt b/tests/testthat/summary_test.txt index 0c27eca..fe507de 100755 --- a/tests/testthat/summary_test.txt +++ b/tests/testthat/summary_test.txt @@ -1,3 +1,3 @@ Raw file Experiment -Bernd baut bemüht bienen bei blumenbergen Exp1 -Dieter drückt daknbar den dünnen Daniel durch die dicke dauerbelstete Dachrinne Exp2 \ No newline at end of file +raw_file1 Exp1 +raw_file2 Exp2 From cf8a9e2ef36ac7a62ea1393972083b2596179d55 Mon Sep 17 00:00:00 2001 From: renewiegandt Date: Thu, 12 Jul 2018 13:25:06 +0200 Subject: [PATCH 04/13] Fixed typo --- tests/testthat/summary_test_2.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/summary_test_2.txt b/tests/testthat/summary_test_2.txt index b487418..1e20ef8 100755 --- a/tests/testthat/summary_test_2.txt +++ b/tests/testthat/summary_test_2.txt @@ -1,3 +1,3 @@ Raw file False -Bernd baut bemüht bienen bei blumenbergen Exp1 -Dieter drückt daknbar den dünnen Daniel durch die dicke dauerbelastete Dachrinne Exp2 \ No newline at end of file +raw_file1 Exp1 +raw_file2 Exp2 From 9d265d648d861693b2730548f42ddc0ab7bb3d0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Wiegandt?= Date: Fri, 13 Jul 2018 02:45:58 -0400 Subject: [PATCH 05/13] Adjust tests to changes of parse_MayQuant --- tests/testthat/test_mqparser.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test_mqparser.R b/tests/testthat/test_mqparser.R index bbfe747..773f542 100644 --- a/tests/testthat/test_mqparser.R +++ b/tests/testthat/test_mqparser.R @@ -18,7 +18,7 @@ testthat::test_that("mq_parser",{ expect_equal(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" ), - 1) + TRUE) 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 = "" ), From 12f7a190ae084f88c504ec32fc7fd2fc24638f9a Mon Sep 17 00:00:00 2001 From: renewiegandt Date: Fri, 13 Jul 2018 09:37:35 +0200 Subject: [PATCH 06/13] Fixed style mistakes --- R/parser.R | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/R/parser.R b/R/parser.R index 103c4b8..449f5da 100644 --- a/R/parser.R +++ b/R/parser.R @@ -167,7 +167,7 @@ parse_MaxQuant <- function(proteinGroups_in, summary_in, outfile, outfile_reduce # @param version version number # @param exp_id experiment id # @param pGroups data table protein groups file - write_clarion_file <- function(meta, out, format, version, exp_id, pGroups, delimiter){ + write_clarion_file <- function(meta, out, format, version, exp_id, pGroups, delimiter) { to_append <- FALSE if (!missing(format)) { write(paste0("!format=", format), file = out, append = to_append) @@ -190,13 +190,13 @@ parse_MaxQuant <- function(proteinGroups_in, summary_in, outfile, outfile_reduce # reading files in data tables proteinGroups <- data.table::fread(proteinGroups_in, header = TRUE, quote = "") summary_file <- data.table::fread(summary_in, header = TRUE) - meta_config <- tryCatch({rjson::fromJSON(file = config)}, - error=function(cond){ + meta_config <- tryCatch( {rjson::fromJSON(file = config)}, + error = function(cond){ stop("Could not read config file") - }) + } ) # getting experiment names - if("Experiment" %in% colnames(summary_file)){ + if ("Experiment" %in% colnames(summary_file)) { exp_names <- (unique(summary_file[Experiment != "", Experiment])) } else { stop("wrong format on summary file: column \'Experiment\' misssing") @@ -204,7 +204,6 @@ parse_MaxQuant <- function(proteinGroups_in, summary_in, outfile, outfile_reduce meta <- get_meta_from_config(meta_config = meta_config) - sample_scores <- meta_config$type_scores sample_ratios <- meta_config$type_ratios sample_probability <- meta_config$type_probability @@ -213,7 +212,7 @@ parse_MaxQuant <- function(proteinGroups_in, summary_in, outfile, outfile_reduce sample_ary <- meta_config$type_array reduced_list <- meta_config$reduced_list full_sample_list <- c(sample_scores, sample_ratios, sample_probability, sample_category, sample_ary) - if(is.null(reduced_list)){ + if (is.null(reduced_list)) { stop("reduced_list is missing in config file") } @@ -227,7 +226,7 @@ parse_MaxQuant <- function(proteinGroups_in, summary_in, outfile, outfile_reduce # append rows to data table with metadata samples_list <- lapply(col_names, function(col_head) { - unlist(lapply(exp_names, function(name){ + unlist(lapply(exp_names, function(name) { name_brackets <- paste0("\\Q", name) exp_regex <- paste0("\\Q ", name) sample_description <- strsplit(col_head, exp_regex) From ec3d416a917087f03ff975634577c5c67b1c7e01 Mon Sep 17 00:00:00 2001 From: renewiegandt Date: Fri, 13 Jul 2018 09:43:03 +0200 Subject: [PATCH 07/13] removed redundant :: notation --- tests/testthat/test_mqparser.R | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/testthat/test_mqparser.R b/tests/testthat/test_mqparser.R index 773f542..e4ae44a 100644 --- a/tests/testthat/test_mqparser.R +++ b/tests/testthat/test_mqparser.R @@ -1,15 +1,15 @@ context("MaxQuant parser") -testthat::test_that("all needed input parameteres are given", { +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/"), + 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"), From 586ed7ea5c91fd944b18ecf31588968e31c2db1b Mon Sep 17 00:00:00 2001 From: renewiegandt Date: Fri, 13 Jul 2018 09:55:56 +0200 Subject: [PATCH 08/13] removed redundant brackets --- R/parser.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/parser.R b/R/parser.R index 449f5da..ee05374 100644 --- a/R/parser.R +++ b/R/parser.R @@ -197,7 +197,7 @@ parse_MaxQuant <- function(proteinGroups_in, summary_in, outfile, outfile_reduce # getting experiment names if ("Experiment" %in% colnames(summary_file)) { - exp_names <- (unique(summary_file[Experiment != "", Experiment])) + exp_names <- unique(summary_file[Experiment != "", Experiment]) } else { stop("wrong format on summary file: column \'Experiment\' misssing") } From 85bc80578cc70fd8b2a5cb95a91d90e8f823a592 Mon Sep 17 00:00:00 2001 From: renewiegandt Date: Fri, 13 Jul 2018 10:08:23 +0200 Subject: [PATCH 09/13] Fixed typo --- R/parser.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/parser.R b/R/parser.R index ee05374..4ece531 100644 --- a/R/parser.R +++ b/R/parser.R @@ -190,10 +190,10 @@ parse_MaxQuant <- function(proteinGroups_in, summary_in, outfile, outfile_reduce # reading files in data tables proteinGroups <- data.table::fread(proteinGroups_in, header = TRUE, quote = "") summary_file <- data.table::fread(summary_in, header = TRUE) - meta_config <- tryCatch( {rjson::fromJSON(file = config)}, - error = function(cond){ + meta_config <- tryCatch({rjson::fromJSON(file = config)}, + error = function(cond) { stop("Could not read config file") - } ) + }) # getting experiment names if ("Experiment" %in% colnames(summary_file)) { From 02c5163be31e7e9a1e07507a4ab3f7e174d2e2d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Wiegandt?= Date: Fri, 13 Jul 2018 05:07:50 -0400 Subject: [PATCH 10/13] Fixed warnings during test runs --- DESCRIPTION | 3 +- R/parser.R | 5 + tests/testthat/proteinGroups_test.txt | 2 +- tests/testthat/success_config.json | 322 ++++++++++++++++++++++++++ tests/testthat/test_mqparser.R | 14 +- 5 files changed, 337 insertions(+), 9 deletions(-) create mode 100644 tests/testthat/success_config.json diff --git a/DESCRIPTION b/DESCRIPTION index 614d338..1cf9a47 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -49,5 +49,6 @@ Imports: shiny, RoxygenNote: 6.0.1 biocViews: Suggests: knitr, - rmarkdown + rmarkdown, + testthat VignetteBuilder: knitr diff --git a/R/parser.R b/R/parser.R index 4ece531..57b8141 100644 --- a/R/parser.R +++ b/R/parser.R @@ -190,6 +190,11 @@ parse_MaxQuant <- function(proteinGroups_in, summary_in, outfile, outfile_reduce # reading files in data tables proteinGroups <- data.table::fread(proteinGroups_in, header = TRUE, quote = "") summary_file <- data.table::fread(summary_in, header = TRUE) + + if (config == "") { + stop("Could not read config file") + } + meta_config <- tryCatch({rjson::fromJSON(file = config)}, error = function(cond) { stop("Could not read config file") diff --git a/tests/testthat/proteinGroups_test.txt b/tests/testthat/proteinGroups_test.txt index e83a7ff..6a22524 100755 --- a/tests/testthat/proteinGroups_test.txt +++ b/tests/testthat/proteinGroups_test.txt @@ -1,2 +1,2 @@ -Protein IDs Majority protein IDs Peptide counts (all) Peptide counts (razor+unique) Peptide counts (unique) Protein names Gene names Fasta headers Number of proteins Peptides Razor + unique peptides Unique peptides Peptides Exp1 Peptides Exp2 Razor + unique peptides Exp1 Razor + unique peptides Exp2 Unique peptides Exp1 Unique peptides Exp2 Sequence coverage [%] Unique + razor sequence coverage [%] Unique sequence coverage [%] Mol. weight [kDa] Sequence length Sequence lengths Fraction average Fraction 1 Fraction 2 Fraction 3 Fraction 4 Fraction 5 Fraction 6 Fraction 7 Fraction 8 Q-value Score Reporter intensity corrected 0 Reporter intensity corrected 1 Reporter intensity corrected 2 Reporter intensity corrected 3 Reporter intensity corrected 4 Reporter intensity corrected 5 Reporter intensity 0 Reporter intensity 1 Reporter intensity 2 Reporter intensity 3 Reporter intensity 4 Reporter intensity 5 Reporter intensity count 0 Reporter intensity count 1 Reporter intensity count 2 Reporter intensity count 3 Reporter intensity count 4 Reporter intensity count 5 Reporter intensity corrected 0 Exp1 Reporter intensity corrected 1 Exp1 Reporter intensity corrected 2 Exp1 Reporter intensity corrected 3 Exp1 Reporter intensity corrected 4 Exp1 Reporter intensity corrected 5 Exp1 Reporter intensity corrected 0 Exp2 Reporter intensity corrected 1 Exp2 Reporter intensity corrected 2 Exp2 Reporter intensity corrected 3 Exp2 Reporter intensity corrected 4 Exp2 Reporter intensity corrected 5 Exp2 Reporter intensity 0 Exp1 Reporter intensity 1 Exp1 Reporter intensity 2 Exp1 Reporter intensity 3 Exp1 Reporter intensity 4 Exp1 Reporter intensity 5 Exp1 Reporter intensity 0 Exp2 Reporter intensity 1 Exp2 Reporter intensity 2 Exp2 Reporter intensity 3 Exp2 Reporter intensity 4 Exp2 Reporter intensity 5 Exp2 Reporter intensity count 0 Exp1 Reporter intensity count 1 Exp1 Reporter intensity count 2 Exp1 Reporter intensity count 3 Exp1 Reporter intensity count 4 Exp1 Reporter intensity count 5 Exp1 Reporter intensity count 0 Exp2 Reporter intensity count 1 Exp2 Reporter intensity count 2 Exp2 Reporter intensity count 3 Exp2 Reporter intensity count 4 Exp2 Reporter intensity count 5 Exp2 Sequence coverage Exp1 [%] Sequence coverage Exp2 [%] Intensity Intensity Exp1 Intensity Exp2 MS/MS count Only identified by site Reverse Potential contaminant id Peptide IDs Peptide is razor Mod. peptide IDs Evidence IDs MS/MS IDs Best MS/MS Oxidation (M) site IDs Oxidation (M) site positions +Protein IDs Majority protein IDs Peptide counts (all) Peptide counts (razor+unique) Peptide counts (unique) Protein names Gene names Fasta headers Number of proteins Peptides Razor + unique peptides Unique peptides Peptides Exp1 Peptides Exp2 Razor + unique peptides Exp1 Razor + unique peptides Exp2 Unique peptides Exp1 Unique peptides Exp2 Sequence coverage [%] Unique + razor sequence coverage [%] Unique sequence coverage [%] Mol. weight [kDa] Sequence length Sequence lengths Fraction average Fraction 1 Fraction 2 Fraction 3 Fraction 4 Fraction 5 Fraction 6 Fraction 7 Fraction 8 Q-value Score Reporter intensity corrected 0 Reporter intensity corrected 1 Reporter intensity corrected 2 Reporter intensity corrected 3 Reporter intensity corrected 4 Reporter intensity corrected 5 Reporter intensity 0 Reporter intensity 1 Reporter intensity 2 Reporter intensity 3 Reporter intensity 4 Reporter intensity 5 Reporter intensity count 0 Reporter intensity count 1 Reporter intensity count 2 Reporter intensity count 3 Reporter intensity count 4 Reporter intensity count 5 Reporter intensity corrected 0 Exp1 Reporter intensity corrected 1 Exp1 Reporter intensity corrected 2 Exp1 Reporter intensity corrected 3 Exp1 Reporter intensity corrected 4 Exp1 Reporter intensity corrected 5 Exp1 Reporter intensity corrected 0 Exp2 Reporter intensity corrected 1 Exp2 Reporter intensity corrected 2 Exp2 Reporter intensity corrected 3 Exp2 Reporter intensity corrected 4 Exp2 Reporter intensity corrected 5 Exp2 Reporter intensity 0 Exp1 Reporter intensity 1 Exp1 Reporter intensity 2 Exp1 Reporter intensity 3 Exp1 Reporter intensity 4 Exp1 Reporter intensity 5 Exp1 Reporter intensity 0 Exp2 Reporter intensity 1 Exp2 Reporter intensity 2 Exp2 Reporter intensity 3 Exp2 Reporter intensity 4 Exp2 Reporter intensity 5 Exp2 Reporter intensity count 0 Exp1 Reporter intensity count 1 Exp1 Reporter intensity count 2 Exp1 Reporter intensity count 3 Exp1 Reporter intensity count 4 Exp1 Reporter intensity count 5 Exp1 Reporter intensity count 0 Exp2 Reporter intensity count 1 Exp2 Reporter intensity count 2 Exp2 Reporter intensity count 3 Exp2 Reporter intensity count 4 Exp2 Reporter intensity count 5 Exp2 Sequence coverage Exp1 [%] Sequence coverage Exp2 [%] Intensity Intensity Exp1 Intensity Exp2 MS/MS count Only identified by site Reverse Potential contaminant id Peptide IDs Peptide is razor Mod. peptide IDs Evidence IDs MS/MS IDs Best MS/MS Oxidation (M) site IDs Oxidation (M) site positions A0A068BEQ2;P50171;P50171-2;G3UX44 A0A068BEQ2;P50171;P50171-2;G3UX44 11;11;11;10 11;11;11;10 11;11;11;10 Estradiol 17-beta-dehydrogenase 8 H2-Ke6;Hsd17b8 tr|A0A068BEQ2|A0A068BEQ2_MOUSE H2-K region expressed gene 6, isoform CRA_a OS=Mus musculus GN=H2-Ke6 PE=2 SV=1;sp|P50171|DHB8_MOUSE Estradiol 17-beta-dehydrogenase 8 OS=Mus musculus GN=Hsd17b8 PE=1 SV=2;sp|P50171-2|DHB8_MOUSE Isoform Long of Estradiol 17-b 4 11 11 11 9 9 9 9 9 9 61.4 61.4 61.4 26.587 259 259;259;274;234 6.32 2 1 1 3 4 4 5 17 0 309.9 422810 381560 394980 374200 414580 428320 405880 379740 401170 384810 418890 414670 29 29 29 29 29 29 159850 141420 149170 147480 162360 166190 262960 240140 245810 226710 252220 262130 153390 140950 151450 151320 164040 160930 252490 238790 249720 233490 254850 253730 12 12 12 12 12 12 17 17 17 17 17 17 46.3 51 8493600000 3090200000 5403400000 42 0 1707;5068;5754;17624;17838;18452;24153;26755;37315;45123;45334 True;True;True;True;True;True;True;True;True;True;True 1818;5449;5450;6176;18892;19121;19782;25924;28715;40406;48814;49037 5720;5721;5722;5723;5724;16176;16177;18100;56337;56338;56339;56340;57035;57036;57037;57038;57039;57040;59065;59066;59067;59068;77499;77500;85797;119780;119781;119782;119783;145479;145480;145481;145482;145483;146163;146164;146165 6359;6360;6361;6362;6363;6364;6365;6366;17918;17919;20019;62610;62611;62612;62613;63369;63370;63371;63372;63373;63374;65658;65659;65660;65661;86004;86005;86006;86007;95195;133113;133114;133115;133116;161672;161673;161674;161675;161676;162411;162412;162413 6366;17919;20019;62610;63370;65660;86006;95195;133113;161676;162411 0;1 113;204 \ No newline at end of file diff --git a/tests/testthat/success_config.json b/tests/testthat/success_config.json new file mode 100644 index 0000000..84bee88 --- /dev/null +++ b/tests/testthat/success_config.json @@ -0,0 +1,322 @@ +{ + "meta": [ + { + "col_name": "Protein IDs", + "level": "feature", + "type": "array", + "label": "IDs", + "sublabel": "proteins" + }, + { + "col_name": "Majority protein IDs", + "level": "feature", + "type": "array", + "label": "IDs", + "sublabel": "majority protein" + }, + { + "col_name": "Protein names", + "level": "feature", + "type": "array", + "label": "protein names", + "sublabel": "" + }, + { + "col_name": "Gene names", + "level": "feature", + "type": "array", + "label": "gene names", + "sublabel": "" + }, + { + "col_name": "Fasta headers", + "level": "feature", + "type": "array", + "label": "fasta headers", + "sublabel": "" + }, + { + "col_name": "id", + "level": "feature", + "type": "unique_id", + "label": "unique identifier", + "sublabel": "" + }, + { + "col_name": "Peptide IDs", + "level": "feature", + "type": "array", + "label": "IDs", + "sublabel": "peptide" + }, + { + "col_name": "Mod. peptide IDs", + "level": "feature", + "type": "array", + "label": "IDs", + "sublabel": "mod. peptide" + }, + { + "col_name": "Evidence IDs", + "level": "feature", + "type": "array", + "label": "IDs", + "sublabel": "evidence" + }, + { + "col_name": "MS/MS IDs", + "level": "feature", + "type": "array", + "label": "IDs", + "sublabel": "MS/MS" + }, + { + "col_name": "Mol. weight [kDa]", + "level": "feature", + "type": "category", + "label": "Mol. weight [kDa]", + "sublabel": "" + }, + { + "col_name": "Sequence length", + "level": "feature", + "type": "category", + "label": "length", + "sublabel": "Sequence" + }, + { + "col_name": "Sequence lengths", + "level": "feature", + "type": "array", + "label": "lengths", + "sublabel": "Sequence" + }, + { + "col_name": "Reverse", + "level": "feature", + "type": "category", + "label": "Reverse", + "sublabel": "" + }, + { + "col_name": "Potential contaminant", + "level": "feature", + "type": "category", + "label": "Potential contaminant", + "sublabel": "" + }, + { + "col_name": "Oxidation (M) site IDs", + "level": "feature", + "type": "array", + "label": "IDs", + "sublabel": "Oxidation (M) site" + }, + { + "col_name": "Oxidation (M) site positions", + "level": "feature", + "type": "array", + "label": "positions", + "sublabel": "Oxidation (M) site" + }, + { + "col_name": "Phospho (STY) site IDs", + "level": "feature", + "type": "array", + "label": "IDs", + "sublabel": "Phospho (STY) site" + }, + { + "col_name": "Phospho (STY) site positions", + "level": "feature", + "type": "array", + "label": "positions", + "sublabel": "Phospho (STY) site" + }, + { + "col_name": "Peptide counts (all)", + "level": "condition", + "type": "array", + "label": "counts", + "sublabel": "all peptide" + }, + { + "col_name": "Peptide counts (razor+unique)", + "level": "condition", + "type": "array", + "label": "counts", + "sublabel": "razor+unique peptides" + }, + { + "col_name": "Peptide counts (unique)", + "level": "condition", + "type": "array", + "label": "counts", + "sublabel": "unique peptides" + }, + { + "col_name": "Number of proteins", + "level": "condition", + "type": "score", + "label": "count", + "sublabel": "proteins" + }, + { + "col_name": "Peptides", + "level": "condition", + "type": "score", + "label": "count", + "sublabel": "Peptides" + }, + { + "col_name": "Razor + unique peptides", + "level": "condition", + "type": "score", + "label": "count", + "sublabel": "Razor + unique peptides" + }, + { + "col_name": "Unique peptides", + "level": "condition", + "type": "score", + "label": "count", + "sublabel": "Unique peptides" + }, + { + "col_name": "MS/MS count", + "level": "condition", + "type": "score", + "label": "count", + "sublabel": "MS/MS" + }, + { + "col_name": "Fraction average", + "level": "condition", + "type": "score", + "label": "fraction", + "sublabel": "average" + }, + { + "col_name": "Best MS/MS", + "level": "condition", + "type": "array", + "label": "MS/MS", + "sublabel": "best" + }, + { + "col_name": "Intensity", + "level": "condition", + "type": "score", + "label": "Intensity", + "sublabel": "" + }, + { + "col_name": "Intensity L", + "level": "condition", + "type": "score", + "label": "Intensity", + "sublabel": "L" + }, + { + "col_name": "Intensity M", + "level": "condition", + "type": "score", + "label": "Intensity", + "sublabel": "M" + }, + { + "col_name": "Intensity H", + "level": "condition", + "type": "score", + "label": "Intensity", + "sublabel": "H" + }, + { + "col_name": "Q-value", + "level": "condition", + "type": "probability", + "label": "q-value", + "sublabel": "" + }, + { + "col_name": "Score", + "level": "condition", + "type": "probability", + "label": "score", + "sublabel": "" + }, + { + "col_name": "Unique sequence coverage [%]", + "level": "condition", + "type": "ratio", + "label": "sequence coverage", + "sublabel": "Unique" + }, + { + "col_name": "Unique + razor sequence coverage [%]", + "level": "condition", + "type": "ratio", + "label": "sequence coverage", + "sublabel": "Unique + razor" + }, + { + "col_name": "Sequence coverage [%]", + "level": "condition", + "type": "ratio", + "label": "sequence coverage", + "sublabel": "" + }, + { + "col_name": "Only identified by site", + "level": "feature", + "type": "category", + "label": "identified by site", + "sublabel": "" + }, + { + "col_name": "Peptide is razor", + "level": "condition", + "type": "array", + "label": "peptide", + "sublabel": "is razor" + } + ], + + "type_scores": + ["Peptides", "Razor + unique peptides", "Unique peptides", "Ratio M/L count", "Ratio M/L iso-count", "Ratio H/L count", "Ratio H/L iso-count" , + "Ratio H/M count", "Ratio H/M iso-count", "Intensity", "Intensity L", "Intensity M", "Intensity H", "MS/MS count", "LFQ intensity", + "Reporter intensity count", "Reporter intensity corrected", "Reporter intensity", "Fraction", "iBAQ", + "Reporter intensity corrected 0", "Reporter intensity corrected 1","Reporter intensity corrected 2", "Reporter intensity corrected 3", + "Reporter intensity corrected 4", "Reporter intensity corrected 5", "Reporter intensity 0", "Reporter intensity 1", + "Reporter intensity 2", "Reporter intensity 3", "Reporter intensity 4", "Reporter intensity 5", "Reporter intensity count 0", + "Reporter intensity count 1", "Reporter intensity count 2", "Reporter intensity count 3", "Reporter intensity count 4", + "Reporter intensity count 5" ], + + "type_ratios": + ["Sequence coverage", "Ratio H/M variability [%]", "Ratio H/M normalized", "Ratio H/M", "Ratio H/L variability [%]", "Ratio H/L normalized", "Ratio H/L", + "Ratio M/L", "Ratio M/L variability [%]", "Ratio M/L normalized"], + + "type_probability":[], + + "type_category": + ["Ratio H/M type", "Ratio H/L type", "Ratio M/L type", "Identification type"], + + "type_array": + [], + + "reduced_list": + ["Protein IDs", "Majority protein IDs", "Protein names", "Gene names", "Fasta headers", + "Peptides;exp", "Razor + unique peptides;exp", "Unique peptides;exp", "Mol. weight [kDa]", + "Sequence length", "Sequence coverage;exp", "Intensity;exp", "Reverse", "Potential contaminant", + "id", "Peptide IDs", "Mod. peptide IDs", "Evidence IDs", "Sequence lengths", "Phospho (STY) site IDs", + "Reporter intensity corrected 0;exp", + "Reporter intensity corrected 1;exp", + "Reporter intensity corrected 2;exp", + "Reporter intensity corrected 3;exp", + "Reporter intensity corrected 4;exp", + "Reporter intensity corrected 5;exp", + "LFQ intensity", + "Intensity L", "Intensity H", "Intensity M", "Ratio M/L normalized;exp", "Ratio H/L normalized;exp", + "Ratio H/M normalized;exp"] +} + diff --git a/tests/testthat/test_mqparser.R b/tests/testthat/test_mqparser.R index e4ae44a..a19089b 100644 --- a/tests/testthat/test_mqparser.R +++ b/tests/testthat/test_mqparser.R @@ -1,15 +1,15 @@ context("MaxQuant parser") -test_that("all needed input parameteres are given", { +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/"), + 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") }) -test_that("mq_parser",{ +testthat::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"), @@ -17,7 +17,7 @@ test_that("mq_parser",{ "wrong format on summary file: column \'Experiment\' misssing") expect_equal(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" ), + outfile = "./out", outfile_reduced = "./outres", config = system.file("/tests/testthat", "success_config.json", package = "wilson")), TRUE) 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"), From 6111a8ab3654455a236f0abf65933d8f11228765 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Wiegandt?= Date: Fri, 13 Jul 2018 05:16:41 -0400 Subject: [PATCH 11/13] changed expect_equal to expect_true --- tests/testthat/test_mqparser.R | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/testthat/test_mqparser.R b/tests/testthat/test_mqparser.R index a19089b..e36f613 100644 --- a/tests/testthat/test_mqparser.R +++ b/tests/testthat/test_mqparser.R @@ -15,10 +15,9 @@ testthat::test_that("mq_parser",{ summary_in = system.file("/tests/testthat", "summary_test_2.txt", package = "wilson"), outfile = "./out", outfile_reduced = "./outres" ), "wrong format on summary file: column \'Experiment\' misssing") - expect_equal(wilson::parse_MaxQuant(proteinGroups_in = system.file("/tests/testthat", "proteinGroups_test.txt", package = "wilson"), + 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")), - TRUE) + 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"), outfile = "./out", outfile_reduced = "./outres", config = "" ), 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 12/13] 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") }) From 45488268c30683836d210104cb1c46720a980f69 Mon Sep 17 00:00:00 2001 From: renewiegandt Date: Mon, 16 Jul 2018 13:14:14 +0200 Subject: [PATCH 13/13] removing redundant :: import --- tests/testthat/test_mqparser.R | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/tests/testthat/test_mqparser.R b/tests/testthat/test_mqparser.R index 616056c..be5acd9 100644 --- a/tests/testthat/test_mqparser.R +++ b/tests/testthat/test_mqparser.R @@ -1,29 +1,25 @@ context("MaxQuant parser") 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/"), + expect_error(parse_MaxQuant(), "The proteinGroups file was not given") + expect_error(parse_MaxQuant(proteinGroups_in = "./path/path/"), "The summary file was not given") + expect_error(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/", + expect_error(parse_MaxQuant(proteinGroups_in = "./path/path/", summary_in = "./path/path/", outfile = "./path/path/"), "The output_reduced file was not given") }) test_that("mq_parser", { - expect_error(wilson::parse_MaxQuant(proteinGroups_in = "proteinGroups_test.txt", - summary_in = "summary_test_2.txt", + expect_error(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 = "proteinGroups_test.txt", - summary_in = "summary_test.txt", + expect_true(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", + expect_error(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 = "proteinGroups_test.txt", - summary_in = "summary_test.txt", + expect_error(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") })