From 02d1c77a4c6482aa9b5fe03a4ae25cfc2bc756a3 Mon Sep 17 00:00:00 2001 From: Marina Kiweler Date: Thu, 7 Feb 2019 16:50:24 +0100 Subject: [PATCH] vignette update --- vignettes/manipulate_term_match_table.Rmd | 70 +++++++++++++++++++---- 1 file changed, 58 insertions(+), 12 deletions(-) diff --git a/vignettes/manipulate_term_match_table.Rmd b/vignettes/manipulate_term_match_table.Rmd index 0ca62ed..aa06f85 100644 --- a/vignettes/manipulate_term_match_table.Rmd +++ b/vignettes/manipulate_term_match_table.Rmd @@ -4,7 +4,7 @@ author: "Marina Kiweler" date: "`r Sys.Date()`" output: rmarkdown::html_vignette vignette: > - %\VignetteIndexEntry{Vignette Title} + %\VignetteIndexEntry{Term matching tables} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- @@ -19,7 +19,7 @@ library(MARMoSET) ## Structure -The term matching table contains links between the information needed to create the output table. +The term matching table contains links to the information needed to create the output table. Some general term matching tables can be created by the function `create_term_matching_table()` by specifying the used instruments and the origin key. This function falls back on the included list of data frames `tmt_list` where each table is designed to fit one instrument. By calling the function with only one instrument name it will just extract the specific data frame. If called with more than one instrument (ordinarily 2) it will bind the tables together. @@ -27,7 +27,7 @@ This function falls back on the included list of data frames `tmt_list` where ea ```{r} tmt_LC_pump <- create_term_match_table( instrument_list = c("Thermo EASY-nLC")) - # no origin key + # no origin key set ``` The table always consists of 6 columns whose order is important. The count of rows differ depending on the choosen requirements and the type of instrument. @@ -35,7 +35,7 @@ The table always consists of 6 columns whose order is important. The count of ro colnames(tmt_LC_pump) ``` -The first collumn of the resulting table is always the `term`. It is a short and unique description of the row. While the second, `term_verbose` contains a more detailed and readable title. +The first column of the resulting table is always the `term`. It is a short and unique description of the row. While the second, `term_verbose` contains a more detailed and readable title. ```{r} head(tmt_LC_pump[1:2]) @@ -47,15 +47,15 @@ The third collumn `origin` contains keys determining which requirements to satis head(tmt_LC_pump[3]) ``` In the fourth column `handle_type` specifys how to interpret the fifth column `handle`. -"list_path" indicates that `handle` is a path in the flattened json. -"literal" leads to just copy the value of the handle. +`"list_path"` indicates that `handle` is a path in the flattened json. +`"literal"` leads to just copy the value of `handle`. With "parameter" the row stays empty because the information is not represented in the json. ```{r} head(tmt_LC_pump[4:5]) ``` -The last collumn shows an example of which value the row could have. +The last column shows an example of which value the row could have. ```{r} head(tmt_LC_pump[c(2,6)]) @@ -68,17 +68,63 @@ First extract a term matching table for the used instruments without specifying ```{r} full_tmt <- create_term_match_table( instrument_list = c("Thermo EASY-nLC", "Q Exactive - Orbitrap_MS")) - # no origin key + # no origin key set ``` Now it is possible to subset or delete some rows with r tools. +```{r} +sub_rows <- c(1, 6:8, 10) # wanted rows +subset_tmt <- full_tmt[sub_rows,] + +head(subset_tmt) +``` -New rows can be added too. +New rows can be added. It is mandatory to fill in `term_verbose`, `handle_type` and `handle` in their specific column. +`term_verbose` should be a short desription for the column as it will show up as key in the final table. -It is necessary to fill in `term_verbose`, `handle_type` and `handle` in their specific column. -`term_verbose` should be a short desription for the collumn as it will show up as key in the final table. If `handle` contains a string that just needs to be copied to the output table the collumn `handle_type` should contain `"literal"`. -If the row is meant to show an entry of the json `handle_type` needs to be `"list_path"` and `handle` should contain the path to the information in the flattened json after the group number. For example: The entry `flat_json[["Group.1.Instruments.Thermo EASY-nLC.InstrumentFriendName"]]` can be accessed with the value of handle = `"Instruments.Thermo EASY-nLC.InstrumentFriendName`" +```{r} +# create row +new_row <- data.frame(term = "example_line", + term_verbose = "Example line", # Term in the final table + origin = "", + handle_type = "literal", + handle = "this will be the value", # Value in the final table + example = "") +# add to subset +subset_tmt <- rbind(subset_tmt, new_row) +``` + +If the row is meant to show an entry of the json `handle_type` needs to be `"list_path"` and `handle` should contain the path to the information in the flattened json after the group number. +```{r} +# create the flattened json (explained in using_MARMoSET) +flat_json <- flatten_json(json = MARMoSET::testfile_json) + +# choose/search for item of the flattened list, get path without group number. +fj_path <- stringi::stri_subset(names(flat_json), regex = "Flush") %>% +stringi::stri_replace_all_regex(pattern = "^Group.[:digit:].", replacement = "") + +# create row +new_row <- data.frame(term = "second_example_line", + term_verbose = "Second example, Autosampler flush volume", # Term in the final table + origin = "", + handle_type = "list_path", + handle = fj_path, # Value in the final table + example = "") +# add to subset +subset_tmt <- rbind(subset_tmt, new_row) +``` + + +This so changed term matching table can be used with the function `match_terms()`. + +```{R} + +subset_table <- one_group_match_terms(flat_json = flat_json, + term_matching_table = subset_tmt, + group_number = 1) +subset_table[5:7,] +```