diff --git a/DESCRIPTION b/DESCRIPTION new file mode 100644 index 0000000..032b9cc --- /dev/null +++ b/DESCRIPTION @@ -0,0 +1,33 @@ +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, + jsonlite, + pathological, + rlist, + stringi, + magrittr +Depends: + R (>= 2.10) +Suggests: + readODS, + knitr, + rmarkdown +RoxygenNote: 6.1.1 +VignetteBuilder: knitr diff --git a/MARMoSET.Rproj b/MARMoSET.Rproj new file mode 100644 index 0000000..292ab7c --- /dev/null +++ b/MARMoSET.Rproj @@ -0,0 +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 +PackageRoxygenize: rd,collate,namespace diff --git a/NAMESPACE b/NAMESPACE new file mode 100644 index 0000000..42788a6 --- /dev/null +++ b/NAMESPACE @@ -0,0 +1,18 @@ +# Generated by roxygen2: do not edit by hand + +export("%<>%") +export("%>%") +export(create_term_match_table) +export(files_in_group) +export(flatten_json) +export(gradient_tables) +export(group_count) +export(instrument_names) +export(match_terms) +export(one_gradient_table) +export(one_group_match_terms) +export(save_all_groups) +export(save_group_table) +export(use_rawMetaAsJson) +importFrom(magrittr,"%<>%") +importFrom(magrittr,"%>%") diff --git a/R/additional_functions.R b/R/additional_functions.R new file mode 100644 index 0000000..0a9ce3e --- /dev/null +++ b/R/additional_functions.R @@ -0,0 +1,80 @@ +#' Number of groups in the json file +#' +#' @param json A JSON file generated by the function "use_rawMetaAsJson()" or by using rawMetaAsJson.exe externaly. +#' +#' @return Count of groups in the JSON file. +#' +#' @examples +#' data <- system.file( +#' file.path('extdata', 'testfile.raw'), +#' package = 'MARMoSET', mustWork = TRUE) +#' json <- use_rawMetaAsJson(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 "use_rawMetaAsJson()" or by using rawMetaAsJson.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 <- use_rawMetaAsJson(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 "use_rawMetaAsJson()" or by using rawMetaAsJson.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 <- use_rawMetaAsJson(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/data.R b/R/data.R new file mode 100644 index 0000000..4204461 --- /dev/null +++ b/R/data.R @@ -0,0 +1,13 @@ +#' Term matching tables for different instruments +#' +#' +#' +#' @format A list of data frames: +#' \describe{ +#' \item{Q_Exactive_Plus_-_Orbitrap_MS}{MS instrument} +#' \item{Q_Exactive_HF_-_Orbitrap_MS}{MS instrument} +#' \item{Q_Exactive_-_Orbitrap_MS}{MS instrument} +#' \item{Thermo_EASY-nLC}{LC pump} +#' ... +#' } +"tmt_list" diff --git a/R/gradient_functions.R b/R/gradient_functions.R new file mode 100644 index 0000000..c82d07b --- /dev/null +++ b/R/gradient_functions.R @@ -0,0 +1,114 @@ +#' Gradient table to string. +#' +#' @param flat_json A flattened JSON file, created by "prepare_json()". +#' @param group_number An index that determines the group. +#' +#' @return Gradient information as sentence. + +gradient_as_string <- function(flat_json, group_number) +{ + assertive.types::assert_is_list(flat_json) + assertive.types::assert_is_a_number(group_number) + + grad_tab <- one_gradient_table(flat_json, group_number) + grad_tab$`Duration[mm:ss]` %<>% + stringi::stri_replace_all_regex(pattern = ":.*", replacement = "") %<>% + stringi::stri_replace_all_regex(pattern = "^0", replacement = "") + + + if(dim(table(grad_tab$`Flow[nl/min]`)) == 1) + { + flow <- paste("The flow is consistently at", grad_tab$`Flow[nl/min]`[1],"nl/min.", + sep = " ") + } else + { + flow <- paste("The flow is ranging from ", min(grad_tab$`Flow[nl/min]`), + " to ", max(grad_tab$`Flow[nl/min]`," nl/min."), + sep = "") + } + + first <- paste("The quantity of B in percent is from ", grad_tab$`Mixture[%B]`[1], "% B in ", + grad_tab$`Duration[mm:ss]`[2], " minutes to ", + grad_tab$`Mixture[%B]`[2], "% B.", + sep = "") + + following <- paste("In ", grad_tab$`Duration[mm:ss]`[3:nrow(grad_tab)], " minutes to ", + grad_tab$`Mixture[%B]`[3:nrow(grad_tab)], "% B.", sep = "", collapse = " ") + + paste(flow, first, following, sep=" ") %>% + return() +} + +#' Gradient. +#' +#' @param flat_json A flattened JSON file, created by "prepare_json()". +#' @param group_number An index that determines the group. +#' @param lc_pump Name of the used lc_pump, default = "Thermo EASY-nLC". +#' +#' @return A table with gradient. +#' +#' @examples +#' data <- system.file( +#' file.path('extdata', 'testfile.raw'), +#' package = 'MARMoSET', mustWork = TRUE) +#' json <- use_rawMetaAsJson(data) +#' +#' flat_json <- flatten_json(json) +#' +#' one_gradient_table(flat_json, 1) +#' +#' @export + +one_gradient_table <- function(flat_json, group_number, lc_pump = "Thermo EASY-nLC") +{ + assertive.types::assert_is_list(flat_json) + assertive.types::assert_is_a_number(group_number) + assertive.properties::assert_is_not_null(flat_json[[paste("Group" , group_number , "Instruments", lc_pump, "InstrumentFriendName", sep = ".")]]) + + time <- flat_json[[paste0("Group.",group_number,".Instruments.Thermo EASY-nLC.Method.Gradient.Time [mm:ss]")]] + duration <- flat_json[[paste0("Group.",group_number,".Instruments.Thermo EASY-nLC.Method.Gradient.Duration [mm:ss]")]] + flow <- flat_json[[paste0("Group.",group_number,".Instruments.Thermo EASY-nLC.Method.Gradient.Flow [nl/min]")]] + mixture <- flat_json[[paste0("Group.",group_number,".Instruments.Thermo EASY-nLC.Method.Gradient.Mixture [%B]")]] + + gradient_tab <- data.frame( + "Time[mm:ss]" = time, + "Duration[mm:ss]" = duration, + "Flow[nl/min]" = flow, + "Mixture[%B]" = mixture, + check.names = FALSE, + stringsAsFactors = FALSE) + + return(gradient_tab) +} + + +#' Create a list with all gradient tables. +#' +#' @param flat_json A flattened JSON file, created by "prepare_json()". +#' @param lc_pump Name of the used lc pump, default = "Thermo EASY-nLC" +#' +#' @return List of gradients for all groups +#' +#' @examples +#' data <- system.file( +#' file.path('extdata', 'testfile.raw'), +#' package = 'MARMoSET', mustWork = TRUE) +#' json <- use_rawMetaAsJson(data) +#' +#' flat_json <- flatten_json(json) +#' +#' gradient_tables(flat_json) +#' +#' @export + +gradient_tables <- function(flat_json, lc_pump = "Thermo EASY-nLC") +{ + assertive.types::assert_is_list(flat_json) + assertive.types::assert_is_a_string(lc_pump) + + group_count <- flat_json %>% names() %>% stringi::stri_extract_first_regex('^Group\\.\\d+\\.') %>% table() %>% length() + + vector_of_gradient_tables <- lapply(1:group_count, function(group) one_gradient_table(flat_json, group, lc_pump)) + + return(vector_of_gradient_tables) +} diff --git a/R/load_meta_functions.R b/R/load_meta_functions.R new file mode 100644 index 0000000..4d78c14 --- /dev/null +++ b/R/load_meta_functions.R @@ -0,0 +1,65 @@ +#' create a JSON File +#' +#' @param path_data Path to raw file or directory containing raw files. +#' +#' @return JSON object containing the meta data of the raw files. +#' +#' @examples +#' data <- system.file( +#' file.path('extdata', 'testfile.raw'), +#' package = 'MARMoSET', mustWork = TRUE) +#' json <- use_rawMetaAsJson(data) +#' +#' @export + +use_rawMetaAsJson <- function(path_data) +{ + new_file <- tempfile() + path_rawMetaAsJson <- system.file( + file.path('bin','rawMetaAsJson.exe'), + package = 'MARMoSET', mustWork = TRUE) + + assertive.files::assert_all_are_executable_files(path_rawMetaAsJson, warn_about_windows = F) + + path_data_is_ok <- function(x){ assertive.files::is_dir(x) || assertive.files::is_readable_file(x, warn_about_windows = F)} + assertive.base::assert_engine( path_data_is_ok, path_data, + msg = "path_data is not a file or directory!", + severity = "stop", + what = "any") + + if(!assertive.reflection::is_windows()) + { + stop("Function is only working under windows.") + } + + system(command = paste(path_rawMetaAsJson, paste0('"',path_data, '"'), new_file), + intern = T) + + json <- jsonlite::fromJSON(new_file) + + return(json) +} + + +#' flattening JSON +#' +#' @param json A JSON file generated by the function "use_rawMetaAsJson()" or by using rawMetaAsJson.exe externaly. +#' +#' @return A flattened Json for better access. +#' +#' @examples +#' data <- system.file( +#' file.path('extdata', 'testfile.raw'), +#' package = 'MARMoSET', mustWork = TRUE) +#' json <- use_rawMetaAsJson(data) +#' +#' flat_json <- flatten_json(json) +#' +#' @export + +flatten_json <- function(json) +{ + assertive.types::assert_is_list(json) + + return(json %>% rlist::list.flatten()) +} diff --git a/R/load_term_matching_table_function.R b/R/load_term_matching_table_function.R new file mode 100644 index 0000000..d17615f --- /dev/null +++ b/R/load_term_matching_table_function.R @@ -0,0 +1,53 @@ +#' 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" for the requirements of the Journal of Proteome Research. +#' "mcp" for the requirements of the Molecular and Cellular Proteomics. +#' +#' +#' @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") +#' +#' @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. +#' "mcp_guidelines_ms" for the requirements of the Molecular and Cellular Proteomics. +#' +#' +#' @return Table with tmt part for this instrument. + +tmt_one_instrument <- function(instrument, origin_key = "") +{ + instrument %<>% gsub(pattern = " ", replacement = "_" ) + + assertive.sets::assert_is_subset(instrument, names(MARMoSET::tmt_list)) + assertive.properties::assert_is_non_empty(grep(MARMoSET::tmt_list[[instrument]][["origin"]], pattern = origin_key)) + + sub_index <- MARMoSET::tmt_list[[instrument]][["origin"]] %>% + grep(pattern = origin_key) + + rbind( MARMoSET::tmt_list[[instrument]][sub_index,]) %>% + return() +} diff --git a/R/output_functions.R b/R/output_functions.R new file mode 100644 index 0000000..e648de1 --- /dev/null +++ b/R/output_functions.R @@ -0,0 +1,80 @@ +#' write table of specified group to file +#' +#' @param groups_vector A List with a table for each group. +#' @param output_path A path and filename where to write the output. +#' @param group_number An index that determines the group. +#' +#' @examples +#' data <- system.file( +#' file.path('extdata', 'testfile.raw'), +#' package = 'MARMoSET', mustWork = TRUE) +#' json <- use_rawMetaAsJson(data) +#' +#' flat_json <- flatten_json(json) +#' +#' term_matching_table <- create_term_match_table( +#' instrument_list = c("Thermo_EASY-nLC", "Q_Exactive_-_Orbitrap_MS"), +#' origin_key = "jpr") +#' +#' vector_of_group_tables <- match_terms(flat_json, term_matching_table) +#' +#' (partial_path_for_output <- tempfile()) +#' save_group_table(vector_of_group_tables, partial_path_for_output, 1) +#' head(readLines(paste(partial_path_for_output, 'txt', sep = '.'))) +#' +#' @export + +save_group_table <- function(groups_vector, output_path, group_number) +{ + assertive.types::assert_is_list(groups_vector) + assertive.types::assert_is_a_number(group_number) + assertive.files::assert_all_are_dirs(output_path %>% pathological::decompose_path() %>% .$dirname) + assertive.strings::assert_all_are_non_empty_character(output_path %>% pathological::decompose_path() %>% .$filename) + + if (output_path %>% pathological::decompose_path() %>% .$extension != "txt") + { + output_path %<>% pathological::decompose_path() %>% + magrittr::inset2('extension', value = paste(.$extension,'txt', sep = '')) %>% + pathological::recompose_path() + } + + utils::write.table(groups_vector[[group_number]], file = output_path, sep = "\t") +} + +utils::globalVariables('.') + +#' write all groups to files +#' +#' @param groups_vector A List with a table for each group. +#' @param output_path A path and filename where to write the outputfiles. [output_path]_group_[index].txt +#' +#' @examples +#' data <- system.file( +#' file.path('extdata', 'testfile.raw'), +#' package = 'MARMoSET', mustWork = TRUE) +#' json <- use_rawMetaAsJson(data) +#' +#' flat_json <- flatten_json(json) +#' +#' term_matching_table <- create_term_match_table( +#' instrument_list = c("Thermo_EASY-nLC", "Q_Exactive_-_Orbitrap_MS"), +#' origin_key = "jpr") +#' +#' vector_of_group_tables <- match_terms(flat_json, term_matching_table) +#' +#' (partial_path_for_output <- tempfile()) +#' save_all_groups(vector_of_group_tables, partial_path_for_output) +#' head(readLines(paste0(partial_path_for_output, '_group_1.txt'))) +#' +#' @export + +save_all_groups <- function(groups_vector, output_path) +{ + assertive.types::assert_is_list(groups_vector) + assertive.types::assert_is_a_string(output_path) + + for (group in seq_along(groups_vector)) + { + save_group_table(groups_vector, paste0(output_path, "_group_", group), group) + } +} diff --git a/R/reexports.R b/R/reexports.R new file mode 100644 index 0000000..d846f41 --- /dev/null +++ b/R/reexports.R @@ -0,0 +1,15 @@ +#' magrittr forward-pipe operator +#' +#' See \code{\link[magrittr]{\\\%>\\\%}}. +#' @name %>% +#' @importFrom magrittr %>% +#' @export %>% +NULL + +#' magrittr compound assignment pipe operator +#' +#' See \code{\link[magrittr]{\\\%<>\\\%}}. +#' @name %<>% +#' @importFrom magrittr %<>% +#' @export %<>% +NULL diff --git a/R/term_matching_functions.R b/R/term_matching_functions.R new file mode 100644 index 0000000..427c881 --- /dev/null +++ b/R/term_matching_functions.R @@ -0,0 +1,92 @@ +#' Match terms for all groups +#' +#' @param flat_json A flattened JSON file, created by "flatten_json()". +#' @param term_matching_table A table containing handles, created by "read_tm_table()". +#' +#' @return A vector containing tables with meta data for each group of raw files. +#' +#' @examples +#' data <- system.file( +#' file.path('extdata', 'testfile.raw'), +#' package = 'MARMoSET', mustWork = TRUE) +#' json <- use_rawMetaAsJson(data) +#' +#' flat_json <- flatten_json(json) +#' +#' term_matching_table <- create_term_match_table( +#' instrument_list = instrument_names(json, 1), +#' origin_key = "jpr") +#' +#' vector_of_group_tables <- match_terms(flat_json, term_matching_table) +#' +#' @export + +match_terms <- function(flat_json, term_matching_table) +{ + assertive.types::assert_is_list(flat_json) + assertive.types::assert_is_data.frame(term_matching_table) + + group_count <- flat_json %>% names() %>% stringi::stri_extract_first_regex('^Group\\.\\d+\\.') %>% table() %>% length() + + vector_of_group_tables <- lapply(1:group_count, function(group) one_group_match_terms(flat_json, term_matching_table, group)) + + return(vector_of_group_tables) +} + + +#' Match terms for one group +#' +#' @param flat_json A flattened JSON file, created by "flatten_json()". +#' @param term_matching_table A table containing handles, created by "read_tm_table()". +#' @param group_number An index that determines the group. +#' +#' @return Table with meta data for the choosen group of raw files. +#' +#' @examples +#' data <- system.file( +#' file.path('extdata', 'testfile.raw'), +#' package = 'MARMoSET', mustWork = TRUE) +#' json <- use_rawMetaAsJson(data) +#' +#' flat_json <- flatten_json(json) +#' +#' term_matching_table <- create_term_match_table( +#' instrument_list = instrument_names(json, 1), +#' origin_key = "jpr") +#' +#' meta_data_table <- one_group_match_terms(flat_json, term_matching_table, 1) +#' +#' @export + +one_group_match_terms <- function(flat_json, term_matching_table, group_number) +{ + assertive.types::assert_is_list(flat_json) + assertive.types::assert_is_data.frame(term_matching_table) + assertive.types::assert_is_a_number(group_number) + + ### create new table + meta_data_table <- data.frame(term = term_matching_table[[2]], + value = NA) + + ### get values + for (this_row in 1:nrow(term_matching_table)) + { + handle_type <- term_matching_table[[4]][[this_row]] + + handle <- flat_json[[paste0("Group.",group_number, ".", term_matching_table[[5]][[this_row]])]] + + if (handle_type == "list_path" && !is.null(handle) && handle != "?") + { + meta_data_table[["value"]][[this_row]] <- handle + } + else if (handle_type == "literal") + { + meta_data_table[["value"]][[this_row]] <- term_matching_table[[5]][[this_row]] + } + else if (handle_type == "function") + { + meta_data_table[["value"]][[this_row]] <- gradient_as_string(flat_json, group_number) + } + } + return(meta_data_table) +} diff --git a/README.md b/README.md index 526f503..b415dac 100644 --- a/README.md +++ b/README.md @@ -1,2 +1 @@ -# MARMoSET -MetAdata fRom Mass SpectromETry +# rpackage \ No newline at end of file diff --git a/data/tmt_list.rda b/data/tmt_list.rda new file mode 100644 index 0000000..fe43b2c Binary files /dev/null and b/data/tmt_list.rda differ diff --git a/inst/bin/Newtonsoft.Json.Net20.dll b/inst/bin/Newtonsoft.Json.Net20.dll new file mode 100644 index 0000000..5b9827d Binary files /dev/null and b/inst/bin/Newtonsoft.Json.Net20.dll differ diff --git a/inst/bin/ThermoFisher.CommonCore.BackgroundSubtraction.dll b/inst/bin/ThermoFisher.CommonCore.BackgroundSubtraction.dll new file mode 100644 index 0000000..abe28a8 Binary files /dev/null and b/inst/bin/ThermoFisher.CommonCore.BackgroundSubtraction.dll differ diff --git a/inst/bin/ThermoFisher.CommonCore.Data.dll b/inst/bin/ThermoFisher.CommonCore.Data.dll new file mode 100644 index 0000000..d799117 Binary files /dev/null and b/inst/bin/ThermoFisher.CommonCore.Data.dll differ diff --git a/inst/bin/ThermoFisher.CommonCore.MassPrecisionEstimator.dll b/inst/bin/ThermoFisher.CommonCore.MassPrecisionEstimator.dll new file mode 100644 index 0000000..717fc8b Binary files /dev/null and b/inst/bin/ThermoFisher.CommonCore.MassPrecisionEstimator.dll differ diff --git a/inst/bin/ThermoFisher.CommonCore.RawFileReader.dll b/inst/bin/ThermoFisher.CommonCore.RawFileReader.dll new file mode 100644 index 0000000..f89a35f Binary files /dev/null and b/inst/bin/ThermoFisher.CommonCore.RawFileReader.dll differ diff --git a/inst/bin/rawMetaAsJson.exe b/inst/bin/rawMetaAsJson.exe new file mode 100644 index 0000000..bc6456f Binary files /dev/null and b/inst/bin/rawMetaAsJson.exe differ diff --git a/inst/bin/rawMetaAsJson.exe.config b/inst/bin/rawMetaAsJson.exe.config new file mode 100644 index 0000000..00bfd11 --- /dev/null +++ b/inst/bin/rawMetaAsJson.exe.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/inst/bin/rawMetaAsJson.pdb b/inst/bin/rawMetaAsJson.pdb new file mode 100644 index 0000000..e19b339 Binary files /dev/null and b/inst/bin/rawMetaAsJson.pdb differ diff --git a/inst/extdata/testfile.raw b/inst/extdata/testfile.raw new file mode 100644 index 0000000..5fd56af Binary files /dev/null and b/inst/extdata/testfile.raw differ diff --git a/man/create_term_match_table.Rd b/man/create_term_match_table.Rd new file mode 100644 index 0000000..eefbeab --- /dev/null +++ b/man/create_term_match_table.Rd @@ -0,0 +1,29 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/load_term_matching_table_function.R +\name{create_term_match_table} +\alias{create_term_match_table} +\title{create term matching Table} +\usage{ +create_term_match_table(instrument_list = c("Thermo_EASY-nLC", + "Q Exactive_Plus_-_Orbitrap_MS"), origin_key = "") +} +\arguments{ +\item{instrument_list}{list of instruments in the raw file, get it with "instrument_names()".} + +\item{origin_key}{Specifies which information is required. +If empty, all information is used. +"jpr" for the requirements of the Journal of Proteome Research. +"mcp" for the requirements of the Molecular and Cellular Proteomics.} +} +\value{ +A table needed to extract the meta data with match_terms(). +} +\description{ +create term matching Table +} +\examples{ +term_matching_table <- create_term_match_table( + instrument_list = c("Thermo_EASY-nLC", "Q_Exactive_-_Orbitrap_MS"), + origin_key = "jpr") + +} diff --git a/man/files_in_group.Rd b/man/files_in_group.Rd new file mode 100644 index 0000000..6f11d35 --- /dev/null +++ b/man/files_in_group.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/additional_functions.R +\name{files_in_group} +\alias{files_in_group} +\title{Filenames of one group} +\usage{ +files_in_group(json, group_number) +} +\arguments{ +\item{json}{A JSON file generated by the function "use_rawMetaAsJson()" or by using rawMetaAsJson.exe externaly.} + +\item{group_number}{An index that determines the group.} +} +\value{ +A list of filenames belonging to the choosen group. +} +\description{ +Filenames of one group +} +\examples{ +data <- system.file( + file.path('extdata', 'testfile.raw'), + package = 'MARMoSET', mustWork = TRUE) +json <- use_rawMetaAsJson(data) + +files_in_group(json, 1) + +} diff --git a/man/flatten_json.Rd b/man/flatten_json.Rd new file mode 100644 index 0000000..611094b --- /dev/null +++ b/man/flatten_json.Rd @@ -0,0 +1,26 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/load_meta_functions.R +\name{flatten_json} +\alias{flatten_json} +\title{flattening JSON} +\usage{ +flatten_json(json) +} +\arguments{ +\item{json}{A JSON file generated by the function "use_rawMetaAsJson()" or by using rawMetaAsJson.exe externaly.} +} +\value{ +A flattened Json for better access. +} +\description{ +flattening JSON +} +\examples{ +data <- system.file( + file.path('extdata', 'testfile.raw'), + package = 'MARMoSET', mustWork = TRUE) +json <- use_rawMetaAsJson(data) + +flat_json <- flatten_json(json) + +} diff --git a/man/gradient_as_string.Rd b/man/gradient_as_string.Rd new file mode 100644 index 0000000..96ffdaf --- /dev/null +++ b/man/gradient_as_string.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/gradient_functions.R +\name{gradient_as_string} +\alias{gradient_as_string} +\title{Gradient table to string.} +\usage{ +gradient_as_string(flat_json, group_number) +} +\arguments{ +\item{flat_json}{A flattened JSON file, created by "prepare_json()".} + +\item{group_number}{An index that determines the group.} +} +\value{ +Gradient information as sentence. +} +\description{ +Gradient table to string. +} diff --git a/man/gradient_tables.Rd b/man/gradient_tables.Rd new file mode 100644 index 0000000..2389d2b --- /dev/null +++ b/man/gradient_tables.Rd @@ -0,0 +1,30 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/gradient_functions.R +\name{gradient_tables} +\alias{gradient_tables} +\title{Create a list with all gradient tables.} +\usage{ +gradient_tables(flat_json, lc_pump = "Thermo EASY-nLC") +} +\arguments{ +\item{flat_json}{A flattened JSON file, created by "prepare_json()".} + +\item{lc_pump}{Name of the used lc pump, default = "Thermo EASY-nLC"} +} +\value{ +List of gradients for all groups +} +\description{ +Create a list with all gradient tables. +} +\examples{ +data <- system.file( + file.path('extdata', 'testfile.raw'), + package = 'MARMoSET', mustWork = TRUE) +json <- use_rawMetaAsJson(data) + +flat_json <- flatten_json(json) + +gradient_tables(flat_json) + +} diff --git a/man/grapes-greater-than-grapes.Rd b/man/grapes-greater-than-grapes.Rd new file mode 100644 index 0000000..8ad1eb4 --- /dev/null +++ b/man/grapes-greater-than-grapes.Rd @@ -0,0 +1,8 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/reexports.R +\name{\%>\%} +\alias{\%>\%} +\title{magrittr forward-pipe operator} +\description{ +See \code{\link[magrittr]{\\\%>\\\%}}. +} diff --git a/man/grapes-less-than-greater-than-grapes.Rd b/man/grapes-less-than-greater-than-grapes.Rd new file mode 100644 index 0000000..5eb1285 --- /dev/null +++ b/man/grapes-less-than-greater-than-grapes.Rd @@ -0,0 +1,8 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/reexports.R +\name{\%<>\%} +\alias{\%<>\%} +\title{magrittr compound assignment pipe operator} +\description{ +See \code{\link[magrittr]{\\\%<>\\\%}}. +} diff --git a/man/group_count.Rd b/man/group_count.Rd new file mode 100644 index 0000000..dd9858d --- /dev/null +++ b/man/group_count.Rd @@ -0,0 +1,26 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/additional_functions.R +\name{group_count} +\alias{group_count} +\title{Number of groups in the json file} +\usage{ +group_count(json) +} +\arguments{ +\item{json}{A JSON file generated by the function "use_rawMetaAsJson()" or by using rawMetaAsJson.exe externaly.} +} +\value{ +Count of groups in the JSON file. +} +\description{ +Number of groups in the json file +} +\examples{ +data <- system.file( + file.path('extdata', 'testfile.raw'), + package = 'MARMoSET', mustWork = TRUE) +json <- use_rawMetaAsJson(data) + +group_count(json) + +} diff --git a/man/instrument_names.Rd b/man/instrument_names.Rd new file mode 100644 index 0000000..a3f198a --- /dev/null +++ b/man/instrument_names.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/additional_functions.R +\name{instrument_names} +\alias{instrument_names} +\title{Get instrument names} +\usage{ +instrument_names(json, group_number) +} +\arguments{ +\item{json}{A JSON file generated by the function "use_rawMetaAsJson()" or by using rawMetaAsJson.exe externaly.} + +\item{group_number}{An index that determines the group.} +} +\value{ +A list of instruments used in the choosen group. +} +\description{ +Get instrument names +} +\examples{ +data <- system.file( + file.path('extdata', 'testfile.raw'), + package = 'MARMoSET', mustWork = TRUE) +json <- use_rawMetaAsJson(data) + +instrument_names(json, 1) + +} diff --git a/man/match_terms.Rd b/man/match_terms.Rd new file mode 100644 index 0000000..e80cceb --- /dev/null +++ b/man/match_terms.Rd @@ -0,0 +1,34 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/term_matching_functions.R +\name{match_terms} +\alias{match_terms} +\title{Match terms for all groups} +\usage{ +match_terms(flat_json, term_matching_table) +} +\arguments{ +\item{flat_json}{A flattened JSON file, created by "flatten_json()".} + +\item{term_matching_table}{A table containing handles, created by "read_tm_table()".} +} +\value{ +A vector containing tables with meta data for each group of raw files. +} +\description{ +Match terms for all groups +} +\examples{ +data <- system.file( + file.path('extdata', 'testfile.raw'), + package = 'MARMoSET', mustWork = TRUE) +json <- use_rawMetaAsJson(data) + +flat_json <- flatten_json(json) + +term_matching_table <- create_term_match_table( + instrument_list = instrument_names(json, 1), + origin_key = "jpr") + +vector_of_group_tables <- match_terms(flat_json, term_matching_table) + +} diff --git a/man/one_gradient_table.Rd b/man/one_gradient_table.Rd new file mode 100644 index 0000000..9f12a0e --- /dev/null +++ b/man/one_gradient_table.Rd @@ -0,0 +1,32 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/gradient_functions.R +\name{one_gradient_table} +\alias{one_gradient_table} +\title{Gradient.} +\usage{ +one_gradient_table(flat_json, group_number, lc_pump = "Thermo EASY-nLC") +} +\arguments{ +\item{flat_json}{A flattened JSON file, created by "prepare_json()".} + +\item{group_number}{An index that determines the group.} + +\item{lc_pump}{Name of the used lc_pump, default = "Thermo EASY-nLC".} +} +\value{ +A table with gradient. +} +\description{ +Gradient. +} +\examples{ +data <- system.file( + file.path('extdata', 'testfile.raw'), + package = 'MARMoSET', mustWork = TRUE) +json <- use_rawMetaAsJson(data) + +flat_json <- flatten_json(json) + +one_gradient_table(flat_json, 1) + +} diff --git a/man/one_group_match_terms.Rd b/man/one_group_match_terms.Rd new file mode 100644 index 0000000..35d088c --- /dev/null +++ b/man/one_group_match_terms.Rd @@ -0,0 +1,36 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/term_matching_functions.R +\name{one_group_match_terms} +\alias{one_group_match_terms} +\title{Match terms for one group} +\usage{ +one_group_match_terms(flat_json, term_matching_table, group_number) +} +\arguments{ +\item{flat_json}{A flattened JSON file, created by "flatten_json()".} + +\item{term_matching_table}{A table containing handles, created by "read_tm_table()".} + +\item{group_number}{An index that determines the group.} +} +\value{ +Table with meta data for the choosen group of raw files. +} +\description{ +Match terms for one group +} +\examples{ +data <- system.file( + file.path('extdata', 'testfile.raw'), + package = 'MARMoSET', mustWork = TRUE) +json <- use_rawMetaAsJson(data) + +flat_json <- flatten_json(json) + +term_matching_table <- create_term_match_table( + instrument_list = instrument_names(json, 1), + origin_key = "jpr") + +meta_data_table <- one_group_match_terms(flat_json, term_matching_table, 1) + +} diff --git a/man/save_all_groups.Rd b/man/save_all_groups.Rd new file mode 100644 index 0000000..5ad464c --- /dev/null +++ b/man/save_all_groups.Rd @@ -0,0 +1,35 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/output_functions.R +\name{save_all_groups} +\alias{save_all_groups} +\title{write all groups to files} +\usage{ +save_all_groups(groups_vector, output_path) +} +\arguments{ +\item{groups_vector}{A List with a table for each group.} + +\item{output_path}{A path and filename where to write the outputfiles. [output_path]_group_[index].txt} +} +\description{ +write all groups to files +} +\examples{ +data <- system.file( + file.path('extdata', 'testfile.raw'), + package = 'MARMoSET', mustWork = TRUE) +json <- use_rawMetaAsJson(data) + +flat_json <- flatten_json(json) + +term_matching_table <- create_term_match_table( + instrument_list = c("Thermo_EASY-nLC", "Q_Exactive_-_Orbitrap_MS"), + origin_key = "jpr") + +vector_of_group_tables <- match_terms(flat_json, term_matching_table) + +(partial_path_for_output <- tempfile()) +save_all_groups(vector_of_group_tables, partial_path_for_output) +head(readLines(paste0(partial_path_for_output, '_group_1.txt'))) + +} diff --git a/man/save_group_table.Rd b/man/save_group_table.Rd new file mode 100644 index 0000000..ec06be5 --- /dev/null +++ b/man/save_group_table.Rd @@ -0,0 +1,37 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/output_functions.R +\name{save_group_table} +\alias{save_group_table} +\title{write table of specified group to file} +\usage{ +save_group_table(groups_vector, output_path, group_number) +} +\arguments{ +\item{groups_vector}{A List with a table for each group.} + +\item{output_path}{A path and filename where to write the output.} + +\item{group_number}{An index that determines the group.} +} +\description{ +write table of specified group to file +} +\examples{ +data <- system.file( + file.path('extdata', 'testfile.raw'), + package = 'MARMoSET', mustWork = TRUE) +json <- use_rawMetaAsJson(data) + +flat_json <- flatten_json(json) + +term_matching_table <- create_term_match_table( + instrument_list = c("Thermo_EASY-nLC", "Q_Exactive_-_Orbitrap_MS"), + origin_key = "jpr") + +vector_of_group_tables <- match_terms(flat_json, term_matching_table) + +(partial_path_for_output <- tempfile()) +save_group_table(vector_of_group_tables, partial_path_for_output, 1) +head(readLines(paste(partial_path_for_output, 'txt', sep = '.'))) + +} diff --git a/man/tmt_list.Rd b/man/tmt_list.Rd new file mode 100644 index 0000000..4da4bfe --- /dev/null +++ b/man/tmt_list.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/data.R +\docType{data} +\name{tmt_list} +\alias{tmt_list} +\title{Term matching tables for different instruments} +\format{A list of data frames: +\describe{ + \item{Q_Exactive_Plus_-_Orbitrap_MS}{MS instrument} + \item{Q_Exactive_HF_-_Orbitrap_MS}{MS instrument} + \item{Q_Exactive_-_Orbitrap_MS}{MS instrument} + \item{Thermo_EASY-nLC}{LC pump} + ... +}} +\usage{ +tmt_list +} +\description{ +Term matching tables for different instruments +} +\keyword{datasets} diff --git a/man/tmt_one_instrument.Rd b/man/tmt_one_instrument.Rd new file mode 100644 index 0000000..fb152f4 --- /dev/null +++ b/man/tmt_one_instrument.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/load_term_matching_table_function.R +\name{tmt_one_instrument} +\alias{tmt_one_instrument} +\title{read tmt table for one instrument} +\usage{ +tmt_one_instrument(instrument, origin_key = "") +} +\arguments{ +\item{instrument}{Name of the instrument in tmt_list.} + +\item{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. +"mcp_guidelines_ms" for the requirements of the Molecular and Cellular Proteomics.} +} +\value{ +Table with tmt part for this instrument. +} +\description{ +read tmt table for one instrument +} diff --git a/man/use_rawMetaAsJson.Rd b/man/use_rawMetaAsJson.Rd new file mode 100644 index 0000000..3f2922c --- /dev/null +++ b/man/use_rawMetaAsJson.Rd @@ -0,0 +1,24 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/load_meta_functions.R +\name{use_rawMetaAsJson} +\alias{use_rawMetaAsJson} +\title{create a JSON File} +\usage{ +use_rawMetaAsJson(path_data) +} +\arguments{ +\item{path_data}{Path to raw file or directory containing raw files.} +} +\value{ +JSON object containing the meta data of the raw files. +} +\description{ +create a JSON File +} +\examples{ +data <- system.file( + file.path('extdata', 'testfile.raw'), + package = 'MARMoSET', mustWork = TRUE) +json <- use_rawMetaAsJson(data) + +} diff --git a/vignettes/using_MARMoSET.Rmd b/vignettes/using_MARMoSET.Rmd new file mode 100644 index 0000000..4d73cdf --- /dev/null +++ b/vignettes/using_MARMoSET.Rmd @@ -0,0 +1,135 @@ +--- +title: "Using MARMoSET" +author: "Marina Kiweler" +date: "`r Sys.Date()`" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{using MARMoSET} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +```{r setup, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" + ) +``` + + +A package to extract meta data out of Thermo Fischer raw files. +Meta data refers to what is found in a raw file as parts of the file header, sample information, instrument method and mass spectrometer tune data. + +Works with the following instruments: + +* Thermo EASY-nLC +* Q Exactive Plus - Orbitrap MS +* Q Exactive HF - Orbitrap MS +* Q Exactive - Orbitrap MS + +## Motivation: + +In the context of evaluability and reproducibility in mass spectrometry, the standardization of reporting instrument settings and other metadata is common. But in case of the raw file format the Xcalibur software accesses the raw files instrument settings but has no feature to extract it, let alone to compare these settings of multiple raw files. Therefore MARMoSET should solve this issue and provide an easy way of extracting meta data out of raw files. + +## Raw files: + +The raw file format starts with meta data. It consists of more information about the instrument settings and chromatography data on a deeper layer of the file. Therefore it contains all the information about how the run was set up besides of the results. To access this format and extract these information, the interface ‘IRaw DataPlus’ was defined. With Thermo Fischers RawFileReader it can return all valuable data in a raw file. + +## Installing: + +The package can be installed and loaded the following way: + +```{r} + +library(MARMoSET) + + + +``` + +## Usage: + +The c# command line tool can be used in R with `use_rawMetaAsJson()` to create a JSON file including only the meta data of grouped raw files. +It takes as argument `path_data`, a path to a raw file or a directory containing raw files. + +```{r} +data <- system.file( + file.path('extdata', 'testfile.raw'), + package = 'MARMoSET', mustWork = TRUE) + +json <- use_rawMetaAsJson(path_data = data) + +``` + +This JSON file can also be created by using the rawMetaAsJson.exe externally. + +To allow an easier access to the JSON file it needs to be flattened, this works with `flatten_json()` which takes only one argument: `json`. + +```{r} +flat_json <- flatten_json(json = json) +``` + +Since raw files include a huge amount of meta data and only several of this information is required by journals there is the need to sort out. Therefore a table linking which information is essential and where to find it in the flattened JSON is useful. Such a here refered to as 'term matching table' can be created with `term_matching_table()` by submitting two arguments. The first, `instrument_list` takes a vector with the names of the instruments represented in the JSON file. +The second one, `origin_key` specifies which requirements should be met. If it stays empty, all journals are selected. While `"jpr"` stands for the requirements of the Journal of Proteome Research, `"mcp"` chooses the requirements of the Molecular and Cellular Proteomics. + +```{r} +term_matching_table <- create_term_match_table( + instrument_list = c("Thermo EASY-nLC", "Q Exactive - Orbitrap_MS"), + origin_key = "jpr") +``` + +The names of the instruments can be shown for each group with `instrument_names()` with the json and the group number as arguments. + +```{r} +instrument_names(json = json, group_number = 1) +``` + +To combine the JSON with the created term matching table and get a clear table there are two possibilities. The function `one_group_match_terms()` creates one table with the information choosen in the term matching table for one group, while `match_terms()` creates a vector with a table for each group. +Hence `match_terms()` takes the flattened json as first and the term matching table as second argument while `one_group_match_terms()` additonally has the group number as third argument. +Note that for the use of `match_terms()` all raw files in the JSON need to be recorded by the same constellation of instruments. If this is not given each group needs a separate term matching table and therefore the use of `one_group_match_terms()`. + +```{r} +meta_data_table <- one_group_match_terms(flat_json = flat_json, + term_matching_table = term_matching_table, + group_number = 1) + +vector_of_group_tables <- match_terms(flat_json = flat_json, + term_matching_table = term_matching_table) + +head(meta_data_table, 3) +``` + +In the meta data of the 'Thermo EASY-nlc' is a gradient table. This table can be grabbed either by `one_gradient_table()` for one specified group or with `gradient_tables()` for all groups at once. Output will be either one table or a vector of tables. + +```{r} +gradient_table <- one_gradient_table(flat_json = flat_json, + group_number = 1) + +vector_of_gradient_tables <- gradient_tables(flat_json = flat_json) + +head(gradient_table, 3) +``` + +Finally to export all tables in a vector or one specific, the functions `save_group_table()` and `save_all_groups()`are helpful. The output of `gradient_tables()` or `match_terms()` goes in as `groups_vector` whereas the second argument, `output_path` expects a path with filename. `save_all_groups()` adds the group numbers automatically to each filename, `save_group_table()` takes it as third argument but doesn't add. + +The output file is a tab delimited .txt file for each group. + +```{r} +partial_path_for_output <- tempfile() + +save_group_table(groups_vector = vector_of_group_tables, + output_path = partial_path_for_output, + group_number = 1) + +save_all_groups(groups_vector = vector_of_group_tables, + output_path = partial_path_for_output) +``` + +Additional functions are `group_count()` which just returns how many groups the json file contains. `files_in_groups()`returns a list of the filenames in the group determined with the second parameter `group_number`. Both functions work with the original JSON file, not the flattened one. + +```{r} +group_count(json) + +files_in_group(json, 1) + +``` diff --git a/vignettes/using_MARMoSET.html b/vignettes/using_MARMoSET.html new file mode 100644 index 0000000..8f21ad7 --- /dev/null +++ b/vignettes/using_MARMoSET.html @@ -0,0 +1,183 @@ + + + + + + + + + + + + + + + + +Using MARMoSET + + + + + + + + + + + + + + + + + + +

Using MARMoSET

+

Marina Kiweler

+

2019-01-22

+ + + +

A package to extract meta data out of Thermo Fischer raw files. Meta data refers to what is found in a raw file as parts of the file header, sample information, instrument method and mass spectrometer tune data.

+

Works with the following instruments:

+ +
+

Usage:

+

The c# command line tool can be used in R with use_rawMetaAsJson() to create a JSON file including only the meta data of grouped raw files. It takes as argument path_data, a path to a raw file or a directory containing raw files.

+
data <- system.file(
+    file.path('extdata', '20190116_SJ_short_for_Marina_LC_A.raw'),
+    package = 'MARMoSET', mustWork = TRUE)
+
+json <- use_rawMetaAsJson(path_data = data)
+

This JSON file can also be created by using the rawMetaAsJson.exe externally.

+

To allow an easier access to the JSON file it needs to be flattened, this works with flatten_json() which takes only one argument: json.

+
flat_json <- flatten_json(json = json)
+

Since raw files include a huge amount of meta data and only several of this information is required by journals there is the need to sort out. Therefore a table linking which information is essential and where to find it in the flattened JSON is useful. Such a here refered to as ‘term matching table’ can be created with term_matching_table() by submitting two arguments. The first, instrument_list takes a vector with the names of the instruments represented in the JSON file. The second one, origin_key specifies which requirements should be met. If it stays empty, all journals are selected. While "jpr" stands for the requirements of the Journal of Proteome Research, "mcp" chooses the requirements of the Molecular and Cellular Proteomics.

+
term_matching_table <- create_term_match_table(
+  instrument_list = c("Thermo EASY-nLC", "Q Exactive - Orbitrap_MS"),
+  origin_key = "jpr")
+

The names of the instruments can be shown for each group with instrument_names() with the json and the group number as arguments.

+
instrument_names(json = json, group_number = 1)
+#> [1] "Thermo EASY-nLC"          "Q Exactive - Orbitrap MS"
+

To combine the JSON with the created term matching table and get a clear table there are two possibilities. The function one_group_match_terms() creates one table with the information choosen in the term matching table for one group, while match_terms() creates a vector with a table for each group. Hence match_terms() takes the flattened json as first and the term matching table as second argument while one_group_match_terms() additonally has the group number as third argument. Note that for the use of match_terms() all raw files in the JSON need to be recorded by the same constellation of instruments. If this is not given each group needs a separate term matching table and therefore the use of one_group_match_terms().

+
meta_data_table <- one_group_match_terms(flat_json = flat_json,
+                                         term_matching_table = term_matching_table,
+                                         group_number = 1)
+
+vector_of_group_tables <- match_terms(flat_json = flat_json,
+                                      term_matching_table = term_matching_table)
+
+head(meta_data_table, 3)
+#>                                                       term
+#> 1 High Performance Liquid Chromatography (HPLC) Instrument
+#> 2                                              HPLC Vendor
+#> 3                                               HPLC Model
+#>               value
+#> 1   Thermo EASY-nLC
+#> 2 Thermo Scientific
+#> 3              <NA>
+

In the meta data of the ‘Thermo EASY-nlc’ is a gradient table. This table can be grabbed either by one_gradient_table() for one specified group or with gradient_tables() for all groups at once. Output will be either one table or a vector of tables.

+
gradient_table <- one_gradient_table(flat_json = flat_json,
+                                     group_number = 1)
+
+vector_of_gradient_tables <- gradient_tables(flat_json = flat_json)
+
+head(gradient_table, 3)
+#>   Time[mm:ss] Duration[mm:ss] Flow[nl/min] Mixture[%B]
+#> 1       00:00           00:00          300           5
+#> 2       01:00           01:00          300           5
+

Finally to export all tables in a vector or one specific, the functions save_group_table() and save_all_groups()are helpful. The output of gradient_tables() or match_terms() goes in as groups_vector whereas the second argument, output_path expects a path with filename. save_all_groups() adds the group numbers automatically to each filename, save_group_table() takes it as third argument but doesn’t add.

+

The output file is a tab delimited .txt file for each group.

+
partial_path_for_output <- tempfile()
+
+save_group_table(groups_vector = vector_of_group_tables,
+                 output_path = partial_path_for_output,
+                 group_number = 1)
+
+save_all_groups(groups_vector = vector_of_group_tables,
+                output_path =  partial_path_for_output)
+

Additional functions are group_count() which just returns how many groups the json file contains. files_in_groups()returns a list of the filenames in the group determined with the second parameter group_number. Both functions work with the original JSON file, not the flattened one.

+
group_count(json)
+#> [1] 1
+
+files_in_group(json, 1)
+#> [1] "C:/Users/mkiwele/Documents/R/win-library/3.5/MARMoSET/extdata/20190116_SJ_short_for_Marina_LC_A.raw"
+
+ + + + + + + +