From c02a67297c50a3e4af9931519a52d553eb8bebf2 Mon Sep 17 00:00:00 2001 From: Johannes Graumann Date: Thu, 7 Feb 2019 13:05:57 +0000 Subject: [PATCH] Johannification; --- DESCRIPTION | 72 ++++++------ MARMoSET.Rproj | 39 ++++--- R/additional_functions.R | 162 +++++++++++++------------- R/load_term_matching_table_function.R | 136 ++++++++++----------- 4 files changed, 208 insertions(+), 201 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 3686370..ded0e4f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,35 +1,37 @@ -Package: MARMoSET -Type: Package -Title: Get metadata out of raw files -Version: 0.1.0 -Author: Who wrote it -Maintainer: The package maintainer -Description: This packages uses a c# command line tool to extract the meta data of a raw file into a json file. - It contains methods to collect data requred for publication by journal and to write them into a tab delimited text file. -License: What license is it under? -Encoding: UTF-8 -LazyData: true -Imports: - assertive.base, - assertive.files, - assertive.numbers, - assertive.properties, - assertive.reflection, - assertive.sets, - assertive.strings, - assertive.types, - dplyr, - jsonlite, - pathological, - rlist, - stringi, - tidyr, - magrittr -Depends: - R (>= 2.10) -Suggests: - readODS, - knitr, - rmarkdown -RoxygenNote: 6.1.1 -VignetteBuilder: knitr +Package: MARMoSET +Type: Package +Title: Get metadata out of raw files +Version: 0.1.0 +Author: Who wrote it +Maintainer: The package maintainer +Description: Extraction of meta data from Thermo Fisher Scientific mass spectrometric raw data files into a json file via a + c# command line tool. + Also provided are methods to assemble data requred for publication by journals and to write them into a tab delimited text file. +License: GPL (>= 3) +Encoding: UTF-8 +LazyData: true +Imports: + assertive.base, + assertive.files, + assertive.numbers, + assertive.properties, + assertive.reflection, + assertive.sets, + assertive.strings, + assertive.types, + dplyr, + jsonlite, + magrittr, + pathological, + rlist, + stringi, + tidyr, + utils +Depends: + R (>= 2.10) +Suggests: + readODS, + knitr, + rmarkdown +RoxygenNote: 6.1.1 +VignetteBuilder: knitr diff --git a/MARMoSET.Rproj b/MARMoSET.Rproj index 4a9bcdb..6e1420a 100644 --- a/MARMoSET.Rproj +++ b/MARMoSET.Rproj @@ -1,19 +1,20 @@ -Version: 1.0 - -RestoreWorkspace: Default -SaveWorkspace: Default -AlwaysSaveHistory: Default - -EnableCodeIndexing: Yes -UseSpacesForTab: Yes -NumSpacesForTab: 2 -Encoding: UTF-8 - -RnwWeave: Sweave -LaTeX: pdfLaTeX - -AutoAppendNewline: Yes -StripTrailingWhitespace: Yes - -BuildType: Package -PackageInstallArgs: --no-multiarch --with-keep.source +Version: 1.0 + +RestoreWorkspace: Default +SaveWorkspace: Default +AlwaysSaveHistory: Default + +EnableCodeIndexing: Yes +UseSpacesForTab: Yes +NumSpacesForTab: 2 +Encoding: UTF-8 + +RnwWeave: Sweave +LaTeX: pdfLaTeX + +AutoAppendNewline: Yes +StripTrailingWhitespace: Yes + +BuildType: Package +PackageInstallArgs: --no-multiarch --with-keep.source +PackageCheckArgs: --as-cran diff --git a/R/additional_functions.R b/R/additional_functions.R index 3a52a38..09934a6 100644 --- a/R/additional_functions.R +++ b/R/additional_functions.R @@ -1,80 +1,82 @@ -#' Number of groups in the json file -#' -#' @param json A JSON file generated by the function "generate_json()" or by using MARMoSET.exe externaly. -#' -#' @return Count of groups in the JSON file. -#' -#' @examples -#' data <- system.file( -#' file.path('extdata', 'testfile.raw'), -#' package = 'MARMoSET', mustWork = TRUE) -#' json <- generate_json(data) -#' -#' group_count(json) -#' -#' @export - -group_count <- function(json) -{ - assertive.types::assert_is_list(json) - - return(json[["Group"]] %>% length()) -} - - -#' Filenames of one group -#' -#' @param json A JSON file generated by the function "generate_json()" or by using MARMoSET.exe externaly. -#' @param group_number An index that determines the group. -#' -#' @return A list of filenames belonging to the choosen group. -#' -#' @examples -#' data <- system.file( -#' file.path('extdata', 'testfile.raw'), -#' package = 'MARMoSET', mustWork = TRUE) -#' json <- generate_json(data) -#' -#' files_in_group(json, 1) -#' -#' @export - -files_in_group <- function(json, group_number) -{ - assertive.types::assert_is_list(json) - assertive.types::assert_is_a_number(group_number) - assertive.numbers::assert_all_are_less_than_or_equal_to(group_number, group_count(json)) - - return(json[["Group"]][[group_number]][["Names"]]) -} - - -#' Get instrument names -#' -#' @param json A JSON file generated by the function "generate_json()" or by using MARMoSET.exe externaly. -#' @param group_number An index that determines the group. -#' -#' @return A list of instruments used in the choosen group. -#' -#' @examples -#' data <- system.file( -#' file.path('extdata', 'testfile.raw'), -#' package = 'MARMoSET', mustWork = TRUE) -#' json <- generate_json(data) -#' -#' instrument_names(json, 1) -#' -#' @export - -instrument_names <- function(json, group_number) -{ - assertive.types::assert_is_list(json) - assertive.types::assert_is_a_number(group_number) - assertive.numbers::assert_all_are_less_than_or_equal_to(group_number, group_count(json)) - - instruments <- json[["Group"]][[group_number]][["Instruments"]] %>% - summary() %>% - rownames() - - return(instruments) -} +#' Number of groups in the json file +#' +#' @param json A JSON file generated by the function "generate_json()" or by using MARMoSET.exe externaly. +#' +#' @return Count of groups in the JSON file. +#' +#' @examples +#' data <- system.file( +#' file.path('extdata', 'testfile.raw'), +#' package = 'MARMoSET', mustWork = TRUE) +#' json <- generate_json(data) +#' +#' group_count(json) +#' +#' @export + +group_count <- function(json) +{ + assertive.types::assert_is_list(json) + + return(json[["Group"]] %>% length()) +} + + +#' Filenames of one group +#' +#' @param json A JSON file generated by the function "generate_json()" or by using MARMoSET.exe externaly. +#' @param group_number An index that determines the group. +#' +#' @return A list of filenames belonging to the choosen group. +#' +#' @examples +#' data <- system.file( +#' file.path('extdata', 'testfile.raw'), +#' package = 'MARMoSET', mustWork = TRUE) +#' +#' # Real-time JSON-generation: `json <- generate_json(data)` +#' json <- MARMoSET::testfile_json +#' +#' files_in_group(json, 1) +#' +#' @export + +files_in_group <- function(json, group_number) +{ + assertive.types::assert_is_list(json) + assertive.types::assert_is_a_number(group_number) + assertive.numbers::assert_all_are_less_than_or_equal_to(group_number, group_count(json)) + + return(json[["Group"]][[group_number]][["Names"]]) +} + + +#' Get instrument names +#' +#' @param json A JSON file generated by the function "generate_json()" or by using MARMoSET.exe externaly. +#' @param group_number An index that determines the group. +#' +#' @return A list of instruments used in the choosen group. +#' +#' @examples +#' data <- system.file( +#' file.path('extdata', 'testfile.raw'), +#' package = 'MARMoSET', mustWork = TRUE) +#' json <- generate_json(data) +#' +#' instrument_names(json, 1) +#' +#' @export + +instrument_names <- function(json, group_number) +{ + assertive.types::assert_is_list(json) + assertive.types::assert_is_a_number(group_number) + assertive.numbers::assert_all_are_less_than_or_equal_to(group_number, group_count(json)) + + instruments <- json[["Group"]][[group_number]][["Instruments"]] %>% + summary() %>% + rownames() + + return(instruments) +} diff --git a/R/load_term_matching_table_function.R b/R/load_term_matching_table_function.R index 45bd7d2..cbc1811 100644 --- a/R/load_term_matching_table_function.R +++ b/R/load_term_matching_table_function.R @@ -1,67 +1,69 @@ -#' create term matching Table -#' -#' @param instrument_list list of instruments in the raw file, get it with "instrument_names()". -#' @param origin_key Specifies which information is required. -#' If empty, all information is used. -#' "jpr_guidelines_ms" for the requirements of the Journal of Proteome Research. -#' "miape" for The Minimal Information about a Proteomics Experiment (MIAPE) from the Proteomics Standards Initiative. -#' -#' -#' @return A table needed to extract the meta data with match_terms(). -#' -#' @examples -#' term_matching_table <- create_term_match_table( -#' instrument_list = c("Thermo_EASY-nLC", "Q_Exactive_-_Orbitrap_MS"), -#' origin_key = "jpr_guidelines_ms") -#' -#' @export - -create_term_match_table <- function(instrument_list = c("Thermo_EASY-nLC", "Q Exactive_Plus_-_Orbitrap_MS"), origin_key = "") -{ - assertive.types::assert_is_character(instrument_list) - assertive.types::assert_is_character(origin_key) - - lapply(instrument_list, function(instrument) tmt_one_instrument(instrument = instrument, origin_key = origin_key)) %>% - do.call(what = rbind) %>% - return() -} - - -#' read tmt table for one instrument -#' -#' @param instrument Name of the instrument in tmt_list. -#' @param origin_key Specifies which information is required. -#' If empty, all information is used. -#' "jpr_guidelines_ms" for the requirements of the Journal of Proteome Research. -#' "miape" for The Minimal Information about a Proteomics Experiment (MIAPE) from the Proteomics Standards Initiative. -#' -#' -#' @return Table with tmt part for this instrument. - -tmt_one_instrument <- function(instrument, origin_key = "all") -{ - instrument %<>% gsub(pattern = " ", replacement = "_" ) - - assertive.sets::assert_is_subset(instrument, names(MARMoSET::tmt_list)) - - okey_is_ok <- function(x){ assertive.properties::has_rows(MARMoSET::tmt_list[[instrument]] %>% - tidyr::separate_rows(origin, sep=';') %>% - dplyr::filter(origin == origin_key)) || - (origin_key == "" || origin_key == "all")} - - assertive.base::assert_engine( okey_is_ok, origin_key, - msg = "origin_key is not a valid key!", - severity = "stop", - what = "any") - - sub_index <- MARMoSET::tmt_list[[instrument]] - - if(origin_key != "" && origin_key != "all") - { - sub_index %<>% - tidyr::separate_rows(origin, sep=';') %>% - dplyr::filter(origin == origin_key) - } - - return(sub_index) -} +#' create term matching Table +#' +#' @param instrument_list list of instruments in the raw file, get it with "instrument_names()". +#' @param origin_key Specifies which information is required. +#' If empty, all information is used. +#' "jpr_guidelines_ms" for the requirements of the Journal of Proteome Research. +#' "miape" for The Minimal Information about a Proteomics Experiment (MIAPE) from the Proteomics Standards Initiative. +#' +#' +#' @return A table needed to extract the meta data with match_terms(). +#' +#' @examples +#' term_matching_table <- create_term_match_table( +#' instrument_list = c("Thermo_EASY-nLC", "Q_Exactive_-_Orbitrap_MS"), +#' origin_key = "jpr_guidelines_ms") +#' +#' @export + +create_term_match_table <- function(instrument_list = c("Thermo_EASY-nLC", "Q Exactive_Plus_-_Orbitrap_MS"), origin_key = "") +{ + assertive.types::assert_is_character(instrument_list) + assertive.types::assert_is_character(origin_key) + + lapply(instrument_list, function(instrument) tmt_one_instrument(instrument = instrument, origin_key = origin_key)) %>% + do.call(what = rbind) %>% + return() +} + + +#' read tmt table for one instrument +#' +#' @param instrument Name of the instrument in tmt_list. +#' @param origin_key Specifies which information is required. +#' If empty, all information is used. +#' "jpr_guidelines_ms" for the requirements of the Journal of Proteome Research. +#' "miape" for The Minimal Information about a Proteomics Experiment (MIAPE) from the Proteomics Standards Initiative. +#' +#' +#' @return Table with tmt part for this instrument. + +tmt_one_instrument <- function(instrument, origin_key = "all") +{ + instrument %<>% gsub(pattern = " ", replacement = "_" ) + + assertive.sets::assert_is_subset(instrument, names(MARMoSET::tmt_list)) + + okey_is_ok <- function(x){ assertive.properties::has_rows(MARMoSET::tmt_list[[instrument]] %>% + tidyr::separate_rows(origin, sep=';') %>% + dplyr::filter(origin == origin_key)) || + (origin_key == "" || origin_key == "all")} + + assertive.base::assert_engine( okey_is_ok, origin_key, + msg = "origin_key is not a valid key!", + severity = "stop", + what = "any") + + sub_index <- MARMoSET::tmt_list[[instrument]] + + if(origin_key != "" && origin_key != "all") + { + sub_index %<>% + tidyr::separate_rows(origin, sep=';') %>% + dplyr::filter(origin == origin_key) + } + + return(sub_index) +} + +utils::globalVariables('origin')