diff --git a/R/shiny-ui-base.R b/R/shiny-ui-base.R index 36d6c0e76fce3eb749d16ca21ce4f2567bf30f1e..4941b39d44f46ea8eb50da3c88a4788f7c0a52f6 100644 --- a/R/shiny-ui-base.R +++ b/R/shiny-ui-base.R @@ -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) diff --git a/R/state.R b/R/state.R index 319cb100feae1a6a5ee459fe66ee28dfd89466a4..7bdb5b05ef5b1c47394cd9d24a4bfdda565d0446 100644 --- a/R/state.R +++ b/R/state.R @@ -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] +} diff --git a/inst/rmd/app.Rmd b/inst/rmd/app.Rmd index 7cd799bf903458f8fdace5cf93622729184ba657..a0a04acdc489194bd1a460ab18d34eda29a891d8 100644 --- a/inst/rmd/app.Rmd +++ b/inst/rmd/app.Rmd @@ -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 -->