Skip to content
Snippets Groups Projects
Commit 7cec0b03 authored by Todor Kondić's avatar Todor Kondić
Browse files

shiny-ui-base, state, app: Export MS2 spectra.

* state.R (encode_ms2_to_line, pack_ms2_w_summ): Functions to pack ms2
data based on selected entries in `summ'.

* app (ms2_spectra_tab_name, ms2_spectra_tab_b): New widgets.

* shiny-ui-base: Added input$ms2_spectra_tab_b observer.
parent 62a105d2
No related branches found
No related tags found
No related merge requests found
......@@ -1270,6 +1270,17 @@ mk_shinyscreen_server <- function(projects,init) {
tab2file(rvs$m$out$tab$summ,fn)
})
observeEvent(input$ms2_spectra_tab_b,{
req(NROW(rvs$m$out$tab$summ)>0L)
projdir <- rvs$gui$paths$project
fn <- file.path(projdir,input$ms2_spectra_tab_name)
shinymsg(paste0("Saving MS2 spectra table to: ",basename(fn)))
tab2file(pack_ms2_w_summ(rvs$m$out$tab$summ,
rvs$m$extr$ms2),
fn)
shinymsg("Done saving MS2 spectra table.")
})
observeEvent(input$plot_brush,{
xmin <- round(input$plot_brush[["xmin"]],3)
......
......@@ -237,3 +237,18 @@ new_conf <- function() fig_conf(
presc_conf(
extr_conf(
base_conf())))
encode_ms2_to_line <- function(ms2) {
## ms2 is a data.frame whose first column is mz and the second intensity.
paste0(paste(ms2[[1]],ms2[[2]],sep=':'),collapse=';')
}
pack_ms2_w_summ <- function(summ,ms2) {
## Takes summ, finds entries with high quality spectra and subsets ms2 based on that.
## Take the columns we need from summ.
x = summ[ms2_sel==T,.SD,.SDcols=c(key(summ),"mz","SMILES","Formula","Name")]
mrg_keys = c(intersect(key(ms2),key(summ)),"an")
ms2[x,.(mz=i.mz,ms2_spectrum=encode_ms2_to_line(.SD[,c("mz","intensity")])),on=mrg_keys,by=.EACHI]
}
......@@ -733,6 +733,11 @@ textInput("summ_name",
label="Summary table name",
value="summary.csv")
actionButton("summ_tab_b", "Save summary table")
textInput("ms2_spectra_tab_name",
label="Table of MS2 spectra",
value="ms2_spectra_table.csv")
actionButton("ms2_spectra_tab_b", "Save MS2 spectra table")
```
</div> <!-- Control Bar -->
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment