-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f6ab556
commit 563d0a1
Showing
41 changed files
with
1,351 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <yourself@somewhere.net> | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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,"%>%") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()) | ||
} |
Oops, something went wrong.