Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
app.Rmd 33.90 KiB
output: html_document
runtime: shiny_prerendered
author: Environmental Cheminformatics Group, LCSB, University of Luxembourg
title: "`r paste('Shinyscreen', packageVersion('shinyscreen'))`"
library(data.table)
library(shinyscreen)
def_state <- new_state()
def_datafiles <- shinyscreen:::dtable(File=character(0),
                                      tag=character(0))
def_datatab <- shinyscreen:::dtable("tag"=factor(),
                                    "adduct"=factor(levels=shinyscreen:::DISP_ADDUCTS),
                                    "set"=factor())

def_summ_subset <- shinyscreen:::dtable("QA Column"=shinyscreen:::QA_FLAGS,
                                        "Select"=factor("il irrilevante",levels=c("il irrilevante",
                                                                                  "il buono",
                                                                                  "il cattivo")))
## RMassBank masks shiny::validate. Unmask it.
validate <- shiny::validate
## def_state$input$tab$tags <- def_datatab
rv_state <- list2rev(def_state)
compl_sets <- eventReactive(rv_state$input$tab$setid,
                            rv_state$input$tab$setid[,unique(set)])
## Reactive values to support some of the UI elements.
## rv_ui <- reactiveValues(datatab=def_tags)

## Update with data-files.
rv_dfiles <- reactiveVal(def_datafiles)

## Data-file table when loading.
rv_datatab <- reactiveVal(def_datatab)


Configuration {.tabset}

Inputs

Specify the project directory This is where the output files and the state of the analysis will be saved.
```{r, echo=FALSE} actionButton(inputId = "project_b", label= "Project")

Current project directory is `r textOutput("project", inline=T)`

<details><summary>Load the compound list(s)</summary>
A compound list is composed of entries describing compounds. This
description is used to search for its spectrum in the data file. The
list is a table in the ***CSV*** format and contains these columns,

* ***ID*** : required column, must be filled; this is a user-defined
  ID, uniquely associated with a compound
  
* ***Name*** : this column can be left blank; if not, it should contain the
  names of the compounds
  
* ***SMILES*** : a _SMILES_ string, describing the structure of the
  compound; this entry can be left empty only if one of either
  ***Formula***, or ***mz*** entries are not
  
* ***Formula*** : a chemical formula of a compound; this field can be
  empty only if one of either ***SMILES***, or ***mz*** entries are
  not
  
* ***mz*** : mass of the ionised compound; this field can be left
  empty only if one of either ***SMILES***, or ***Formula*** is not
  
* ***CAS*** : the CAS number of the compound; it can be left empty

* ***RT*** : retention time of the MS1 peak in minutes, if known; can
  be left empty.
  
Only ***ID*** and one of ***SMILES***, ***Formula*** or ***mz*** must
be filled. When structure, or a formula of a compound is known, it is
also possible to look for various adducts in the sample. Of course,
scanning for completely unknown compounds is also supported by the
***mz*** column. In this case, ***mz*** is the mass of the ion.

It is strongly recommended to quote SMILES, names and formulas in the
CSV file used with Shinyscreen.
</details>
```{r, echo=FALSE}
actionButton(inputId = "comp_list_b",
             label= "Compound list(s)")

r htmlOutput("comp_lists")

Load compound set list (_setid_ table) The compound lists can contain more entries than is necessary. Using the _setid_ lists, it is possible to create _compound sets_ which contain only those compounds that will actually be searched for in the data files. A _setid table_ is a _CSV_ containing at least two columns,
  • ID : the ID entry from the compound list

  • set : an user-defined set name.

```{r, echo=FALSE} actionButton(inputId = "setid_b", label= "Load the setid table")

`r htmlOutput("setids", inline=T)`

## Data files
<details><summary>Load data files</summary>
Shinyscreen currently supports only the **mzML** file format. After
loading the files, set file tags in the file table (column
**tag**). Additionally, specify a set of compounds that is supposed
to be extracted from the file using the **set** column. Finally,
specify the **adduct** in the adduct column. In case of compounds
with unknown structure and formula, the adduct is ignored for obvious
reasons.
</details>
```{r, echo=FALSE}
actionButton(inputId = "datafiles_b",
             label= "Load data files.")
Assign tags to data files. Each tag designates an unique file. Use the table below to assign tags.
rhandsontable::rHandsontableOutput("datafiles")
Assign sets to tags. For each tag, assign a set and an adduct (if the structure information exists, otherwise _adduct_ column is ignored).
rhandsontable::rHandsontableOutput("datatab")

Extraction

Spectra extraction based settings

MS1 coarse error

Extract all entries matching the target mass within this error in the precursor table.

```{r, echo=F} shinyscreen::mz_input(input_mz = "ms1_coarse", input_unit = "ms1_coarse_unit", def_mz = def_state$conf$tolerance[["ms1 coarse"]], def_unit = "Da") ```
MS1 fine error

The precursor table masses can be of lower accuracy. Once there is a match within the coarse error, it can be further checked versus the fine error bounds directly in the mass spectrum.

```{r, echo=F} shinyscreen::mz_input(input_mz = "ms1_fine", input_unit = "ms1_fine_unit", def_mz = def_state$conf$tolerance[["ms1 fine"]], def_unit = "ppm") ```
MS1 EIC window

The mz interval over which the intensities are aggregated to generate a chromatogram.

```{r, echo=F} shinyscreen::mz_input(input_mz = "ms1_eic", input_unit = "ms1_eic_unit", def_mz = def_state$conf$tolerance[["eic"]], def_unit = "Da") ```
Retention time window

If the expected retention time has been specified for the compound, then search for the MS1 signature inside the window defined by this range.

```{r, echo=F} shinyscreen::rt_input(input_rt = "ms1_rt_win", input_unit = "ms1_rt_win_unit", def_rt = def_state$conf$tolerance[["rt"]], def_unit = "min") ```

Prescreening

MS1 intensity threshold

Ignore MS1 signal below the threshold.

```{r, echo=F}

numericInput(inputId = "ms1_int_thresh", label = NULL, value = def_stateconfprescreen$ms1_int_thresh)


<details><summary>MS2 intensity threshold</summary>

Ignore MS2 signal below the threshold.

</details>
```{r, echo=F}

numericInput(inputId = "ms2_int_thresh",
             label = NULL,
             value = def_state$conf$prescreen$ms2_int_thresh)

MS1 signal-to-noise ratio.


numericInput(inputId = "s2n",
             label = NULL,
             value = def_state$conf$prescreen$s2n)
MS1/MS2 retention delay.

Look for associated MS2 spectrum within this window around the MS1 peak.

```{r, echo=F} shinyscreen::rt_input(input_rt = "ret_time_shift_tol", input_unit = "ret_time_shift_tol_unit", def_rt = def_state$conf$prescreen[["ret_time_shift_tol"]], def_unit = "min") ```

Filter and order the summary table

Filter summary table

Filter entries in the summary table according to the QA criteria.

  • qa_pass : entries that passed all checks

  • qa_ms1_exists : MS1 intensity is above the MS1 threshold

  • qa_ms2_exists : those entries for which some MS2 spectra have been found

  • qa_ms1_above_noise : MS1 is intense enough and above the noise level

  • qa_ms2_good_int : MS2 intensity is above the MS2 threshold

  • qa_ms2_near : MS2 spectrum is close enough to the MS1 peak

For those who do not speak Italian (and do not dig the bad Sergio Leone pun):

  • l'irrelevante : ignore QA criterion
  • il buono : entry passed QA
  • il cattivo : entry failed QA
```{r, echo=F}

rhandsontable::rHandsontableOutput("summ_subset")

</div>

<div style="padding-left: 0.5em">

<details><summary>Ordering by columns</summary>
It is possible to order the summary table using columns (keys): 
*`r paste(gsub("^-(.+)","\\1",shinyscreen:::DEF_INDEX_SUMM), collapse = ',')`*.
The sequence of columns in the table below describes the
sequence of ordering steps -- the key in the first row sorts the
entire summary table and subsequent keys break the ties.

</details>

```{r, echo=F}
rhandsontable::rHandsontableOutput("order_summ")

Plots

Logarithmic axis

checkboxGroupInput("plot_log",
                   label=NULL,
                   choices = c("MS1 EIC","MS2 EIC","MS2 Spectrum"),
                   selected = character(0))

Global retention time range

shinyscreen::rt_input(input_rt = "plot_rt_min",
                      input_unit = "plot_rt_min_unit",
                      def_rt = NA_real_,
                      def_unit = "min",
                      pref = "min:")

shinyscreen::rt_input(input_rt = "plot_rt_max",
                      input_unit = "plot_rt_max_unit",
                      def_rt = NA_real_,
                      def_unit = "min",
                      pref = "max:")

Grouping plots

How to group plots?

The Select plot group and Select plot label controls control how the data is visually grouped together. The plot group groups together multiple curves in a single graph. Each curve in a graph is designated by the plot label.

```{r, echo=F} p_feats <- 1:length(shinyscreen:::PLOT_FEATURES) names(p_feats) <- shinyscreen:::PLOT_FEATURES selectInput(inputId = "plot_grp_plot", label = "Select plot group", choices = p_feats, selected = p_feats[[shinyscreen:::FIG_DEF_CONF$grouping[["plot"]]]], width = "100%") ```
```{r, echo=F} p_feats <- 1:length(shinyscreen:::PLOT_FEATURES) names(p_feats) <- shinyscreen:::PLOT_FEATURES selectInput(inputId = "plot_label", label = "Select plot label", choices = p_feats, selected = p_feats[[shinyscreen:::FIG_DEF_CONF$grouping[["label"]]]], width = "100%") ```
## Report
shiny::textInput(inputId = "rep_aut", label = "Report author", value = def_state$conf$report$author)
shiny::textInput(inputId = "rep_tit", label = "Report title", value = def_state$conf$report$title)

View compound Lists and Sets {.tabset}

Compound List

DT::dataTableOutput("comp_table")

Setid Table

DT::dataTableOutput("setid_table")

Save and Restore

Shinyscreen can start from either a previously saved state file (in RDS format), or from a YAML config file. States saved using GUI can also be used from the script.

actionButton(inputId = "state_file_load_b",
             label= "Restore project state")
actionButton(inputId = "state_file_save_b",
             label= "Save project state")

Extract Data and Prescreen

Extract spectra from data files.

After Shinyscreen is configured, the compound and setid lists loaded, it is possible to proceed with extracting the data. This is potentially a time-intensive step, so some patience might be needed.

Once the data is extracted, it will be possible to quality check the spectra associated with the compounds specified in the setid list, to subset that data, look at the plots and publish a report.

```{r, echo=FALSE} actionButton(inputId = "extract_b", label = "Extract") ```
Prescreen extracted spectra.

After the data extraction is finished, the quality of the retrieved spectra can be checked using the criteria defined in the Prescreening tab of the Configuration Section. The resulting summary table is given below and is based on the prescreening criteria and filter and ordering setup specified in Filter and order the summary table configuration subsection.

```{r, echo=FALSE} actionButton(inputId = "presc_b", label = "Prescreen and filter") ```
DT::dataTableOutput("summ_table")