diff --git a/NAMESPACE b/NAMESPACE index b7bd3fd4603ce3137e90e7101f1277782ac78144..658ae9e9b80c2940151e41788c73e2a2227e813c 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -11,6 +11,7 @@ export(get_fn_conf) export(get_fn_extr) export(get_fn_ftab) export(get_fn_summ) +export(grab_unit) export(launch) export(list2rev) export(load_compound_input) diff --git a/R/api.R b/R/api.R index feb653eafef7a36ac14a0ab57a6c9855fac6a4c0..39e54934cd407095d6f06a94402c0dd94f6a7b32 100644 --- a/R/api.R +++ b/R/api.R @@ -500,7 +500,6 @@ create_plots <- function(m) { y <- m$out$tab$flt_summ - ## Logarithmic, or linear y axis? scale_y_ms1_eic <- if (shiny::isTruthy(m$conf$logaxes$ms1_eic_int)) ggplot2::scale_y_log10 else ggplot2::scale_y_continuous @@ -511,6 +510,8 @@ create_plots <- function(m) { scale_y_ms2_spec <- if (shiny::isTruthy(m$conf$logaxes$ms2_spec_int)) ggplot2::scale_y_log10 else ggplot2::scale_y_continuous + scale_x <- function(...) ggplot2::scale_x_continuous(...,limits=DEFAULT_RT_RANGE) + ## Colour palette. tags <- y[,unique(tag)] getpal <- colorRampPalette(RColorBrewer::brewer.pal(8,"Dark2")) @@ -518,10 +519,10 @@ create_plots <- function(m) { names(col_all_vals) <- tags scale_colour <- function(values=col_all_vals,...) ggplot2::scale_colour_manual(values = values,name=m$conf$figures[["legend title"]],...) - - rt_lim <- DEFAULT_RT_RANGE - if (!is.null(m$conf$figures$rt_min)) rt_lim[[1]] <- m$conf$figures$rt_min - if (!is.null(m$conf$figures$rt_max)) rt_lim[[2]] <- m$conf$figures$rt_max + rt_new_lim <- c(rt_in_min(m$conf$figures$rt_min), + rt_in_min(m$conf$figures$rt_max)) + rt_lim <- get_coord_lim(rt_new_lim,DEFAULT_RT_RANGE) + my_coord <- ggplot2::coord_cartesian(xlim = rt_lim) conf_psub <- m$conf$figures[["plot subset"]] @@ -556,6 +557,7 @@ create_plots <- function(m) { ) + scale_y_ms1_eic(labels=sci10) + scale_colour(values=col_all_vals[as.character(tags)]) + + scale_x() + my_coord + my_theme() } @@ -574,6 +576,7 @@ create_plots <- function(m) { ) + scale_y_ms2_eic(labels=sci10) + scale_colour(values=col_all_vals[as.character(ddf$tag)]) + + scale_x() + my_coord + my_theme() } @@ -602,6 +605,7 @@ create_plots <- function(m) { ## title=mk_title("MS2 spectrum for precursor",mz) ) + scale_y_ms2_spec(labels=sci10) + + scale_x() + scale_colour(values=col_all_vals[as.character(tags)]) + my_theme() } @@ -671,8 +675,8 @@ save_plots <- function(m) { dir.create(topdir,showWarnings = F) rt_lim <- DEFAULT_RT_RANGE - if (!is.null(m$conf$figures$rt_min)) rt_lim[[1]] <- m$conf$figures$rt_min - if (!is.null(m$conf$figures$rt_max)) rt_lim[[2]] <- m$conf$figures$rt_max + if (isTruthy(m$conf$figures$rt_min)) rt_lim[[1]] <- rt_in_min(m$conf$figures$rt_min) + if (isTruthy(m$conf$figures$rt_max)) rt_lim[[2]] <- rt_in_min(m$conf$figures$rt_max) my_theme <- function(...) ggplot2::theme(legend.position = "none",...) @@ -695,6 +699,7 @@ save_plots <- function(m) { ids <- asdf[,unique(ID)] for (id in ids) { message("Image ","set: ",s," group: ", g, " id: ",id) + tab <- asdf[ID==id,.(tag,ms1_int,ms1_rt,adduct,mz)] ms1_figs <- m$out$tab$ms1_plot_eic[set==s & adduct==g & ID==id,.(fig,structfig)] ms2_figs <- m$out$tab$ms2_plot[set==s & adduct==g & ID==id,.(fig_eic,fig_spec)] diff --git a/R/mix.R b/R/mix.R index f0268b7f4cf94b66ef0bc5fa8d992d30299410cc..233fa46bb29eb62cb8deb69175a980b984e04e0e 100644 --- a/R/mix.R +++ b/R/mix.R @@ -819,6 +819,8 @@ verify_cmpd_l <- function(dt,fn) { ## INPUT TRANSLATORS + +#' @export grab_unit <- function(entry,unit) { what <- paste0("\\<",unit,"\\>$") entry <- trimws(entry,which="both") @@ -827,6 +829,13 @@ grab_unit <- function(entry,unit) { } +rt_in_min <- function(entry) { + xs <- grab_unit(entry,"s") + xm <- grab_unit(entry,"min") + x <- if (is.na(xm)) xs/60. else xm + x +} + conf_trans_pres <- function(pres_list) { ## Translate and validate prescreening input. pres_list[CONF_PRES_NUM] <- sapply(pres_list[CONF_PRES_NUM],as.numeric) @@ -1028,3 +1037,11 @@ fig_path <- function(top,set,group,id,suff,ext="pdf") { fn <- gsub("-","m",fn) if (!is.null(top)) file.path(top,fn) else fn } + +get_coord_lim <- function(new,def) { + if (is.null(new)) return(def) + res <- new + if (length(new[[1]])==0) res[[1]]<-def[[1]] + if (length(new[[2]])==0) res[[2]]<-def[[2]] + res +} diff --git a/inst/rmd/app.Rmd b/inst/rmd/app.Rmd index 7d359e1eeb5edc465bab495132e8eca6aa98ebbe..661ba0da97e815a5b8257d59eeab70dd695e96e6 100644 --- a/inst/rmd/app.Rmd +++ b/inst/rmd/app.Rmd @@ -291,7 +291,7 @@ Filter entries in the summary table according to the QA criteria. For those who do not speak Italian (and do not dig the bad Sergio Leone pun): -* **il irrelevante** : ignore QA criterion +* **l'irrelevante** : ignore QA criterion * **il buono** : entry passed QA * **il cattivo** : entry failed QA @@ -442,6 +442,57 @@ DT::dataTableOutput("summ_table") # Browse Results +Generate plots. + +```{r, echo=F} + +uiOutput("plot_b_ctrl") + +``` +<div style="display: flex; "> + +<div> +```{r, echo=F} + +uiOutput("plot_set_b_ctrl") + +## selectInput(inputId = "plot_set_b", +## label = "Select set", +## choices = c("uninitialised"=0)) +``` +</div> + +<div style="vertical-align: bottom; "> +```{r, echo=F} + +uiOutput("plot_id_b_ctrl") +## selectInput(inputId = "plot_id_b", +## label = "Select ID", +## choices = c("uninitialised"=0)) +``` +</div> + +</div> + + +<div style="display: flex; "> + +<div style="vertical-align: bottom; "> +```{r, echo=F} +actionButton(inputId = "plot_next_b", + label = "Previous") +``` +</div> + +<div style="vertical-align: bottom; "> +```{r, echo=F} +actionButton(inputId = "plot_prev_b", + label = "Next") +``` +</div> + + +</div> <!-- ENGINE --> @@ -801,6 +852,26 @@ observeEvent(input$presc_b,{ }) +observeEvent(input$plot_b,{ + validate(need(NROW(rv_state$out$tab$flt_summ) > 0, + message = "Perform prescreening first.")) + m <- rev2list(rv_state) + + fn_c_state <- file.path(m$conf$project, + paste0("genplot.",shinyscreen:::FN_CONF)) + yaml::write_yaml(x=m$conf,file=fn_c_state) + message("(generate plots) Config written to ", fn_c_state) + state <- withr::with_dir(new=m$conf$project, + code = { + m <- create_plots(m) + save_plots(m) + }) + message("(generate plots) Done generating plots.") + + z <- shinyscreen::merge2rev(rv_state,lst = state) + eval(z) +}) + observeEvent(input$conf_file_save_b, { state <- rf_conf_state() @@ -1015,9 +1086,12 @@ output$summ_subset <- rhandsontable::renderRHandsontable({ output$summ_table <- DT::renderDataTable({ - tab <- rv_state$out$tab$flt_summ[,.(Files=NULL)] + + tab <- rv_state$out$tab$flt_summ + nms <- colnames(tab) + dpl_nms <- nms[nms!="Files"] validate(need(NROW(tab)>0, message = "Please prescreen the data first.")) - DT::datatable(tab, + DT::datatable(tab[,..dpl_nms], style = 'bootstrap', class = 'table-condensed', extensions = 'Scroller', @@ -1026,8 +1100,23 @@ output$summ_table <- DT::renderDataTable({ deferRender = T, scroller = T)) }) -``` +output$plot_set_b_ctrl <- renderUI({ + tab <- rv_state$out$tab$flt_summ + req(NROW(tab)>0) + selectInput(inputId = "plot_set_b", + label = "Select set", + choices = c("uninitialised"=0)) +}) + +output$plot_b_ctrl <- renderUI({ + tab <- rv_state$out$tab$flt_summ + req(NROW(tab)>0) + actionButton(inputId = "plot_b", + label= "Generate plots") + +}) +``` ```{r, echo=F, context = 'server'}