Skip to content

Commit

Permalink
vignette update
Browse files Browse the repository at this point in the history
  • Loading branch information
marinakiweler committed Feb 7, 2019
1 parent 75f731a commit 02d1c77
Showing 1 changed file with 58 additions and 12 deletions.
70 changes: 58 additions & 12 deletions vignettes/manipulate_term_match_table.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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}
---
Expand All @@ -19,23 +19,23 @@ 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.

```{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.
```{r}
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])
Expand All @@ -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)])
Expand All @@ -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,]
```

0 comments on commit 02d1c77

Please sign in to comment.