diff --git a/DESCRIPTION b/DESCRIPTION index b94ce0ac8437d52b173c9f834df5e390470385c1..1953c5f8c96639c16e2bd881c1e33f914d57029a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: shinyscreen Title: Pre-screening of Mass Spectrometry Data -Version: 1.2.1 +Version: 1.2.2 Author: Todor Kondić Maintainer: Todor Kondić <todor.kondic@uni.lu> Authors@R: diff --git a/NAMESPACE b/NAMESPACE index fe8b0e5fc1384d6701df5669ecd70b924668f629..ec49d636bb38ba31aa5e0927b310bd99501641fe 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -7,7 +7,6 @@ export(create_plots) export(create_stub_gui) export(extr_data) export(extract) -export(gen_struct_plots) export(get_fn_comp) export(get_fn_conf) export(get_fn_extr) diff --git a/R/api.R b/R/api.R index 65d7014bc5113592e0b79d62e297780372b96ee5..20a3fe3528ca68d5b416fdfafa2d5f97b04fec0a 100644 --- a/R/api.R +++ b/R/api.R @@ -192,6 +192,10 @@ mk_comp_tab <- function(m) { } smiforadd <- smiles[smiforadd,.(ID,SMILES,Formula,adduct),on=c("SMILES")] data.table::setkey(smiforadd,"adduct","ID") + + ## FIXME: Why is Formula a list when there are no SMILES, instead + ## of an empty string? + smiforadd[,Formula:=as.character(Formula)] ## Update the intermediate table with masses. message("Formulas have been calculated. Start calculating masses from formulas.") @@ -611,31 +615,6 @@ subset_summary <- function(m) { m } - -##' @export -gen_struct_plots <- function(m) { - ## Generate structure plots. - comp <- m$out$tab$comp - - res <- if (NROW(comp)>0) { - structtab <- m$out$tab$comp[known=="structure",unique(.SD),.SDcols=c("ID","SMILES")] - message("Start generating structures.") - if (NROW(structtab)>0) { - structtab[,img:=.({tmp <- lapply(SMILES,function (sm) smiles2img(sm,width = 500,height = 500, zoom = 4.5)) - tmp})] - message("Done generating structures.") - structtab - } else dtable(ID=character(0),SMILES=character(0),img=list()) - } else { - dtable(ID=character(0),SMILES=character(0),img=list()) - } - - m$out$tab$structfig <- res - - m -} - - #' @export create_plots <- function(m) { ## Produce plots of EICs and spectra and group them acording to diff --git a/R/mix.R b/R/mix.R index 69176c73875ecec0638a6ce021b57e55593fd3de..aa8897089fa7033ffc238ce3b583fd2a448a8f0d 100644 --- a/R/mix.R +++ b/R/mix.R @@ -132,6 +132,9 @@ calc_mz_from_formula <- function(chform,adduct,id) { smiles2form <- function(smiles) { + res <- character(length(smiles)) + res <- NA_character_ + isomething <- which(!is.na(smiles) | nchar(smiles) > 0L) one2form <- function (s) { mol <- try(RMassBank::getMolecule(s), silent = T) if (!is.atomic(mol)) { @@ -139,7 +142,8 @@ smiles2form <- function(smiles) { } else "" } - sapply(smiles,one2form,USE.NAMES = F) + res[isomething] <- sapply(smiles[isomething],one2form,USE.NAMES = F) + res } diff --git a/R/plotting.R b/R/plotting.R index 0f1004dcb44566cfc4ae54e02c70b54e0a0808a5..e98256ff9f27e459f404b5ec3f82d51078da2f43 100644 --- a/R/plotting.R +++ b/R/plotting.R @@ -101,18 +101,35 @@ pal_maker <- function(n,palname = NULL) { } ### PLOTTING: AESTHETIC FUNCTIONS -smiles2img <- function(smiles, kekulise=TRUE, width=300, height=300, + + +make_struct_plot <- function(smiles, kekulise=TRUE, width=300, height=300, zoom=1.3,style="cow", annotate="off", abbr="on",suppressh=TRUE, showTitle=FALSE, smaLimit=100, sma=NULL) { - dep <- rcdk::get.depictor(width = width, height = height, zoom = zoom, style = style, annotate = annotate, - abbr = abbr, suppressh = suppressh, showTitle = showTitle, smaLimit = smaLimit, - sma = NULL) - mol <- RMassBank::getMolecule(smiles) - z<-rcdk::view.image.2d(mol, depictor=dep) - grid::rasterGrob(z) + ## structure -> grob + smiles2img <- function() { + if (is.na(smiles) || nchar(smiles)==0) return(NULL) #Handle empty SMILES. + dep <- rcdk::get.depictor(width = width, height = height, zoom = zoom, style = style, annotate = annotate, + abbr = abbr, suppressh = suppressh, showTitle = showTitle, smaLimit = smaLimit, + sma = NULL) + + mol <- RMassBank::getMolecule(smiles) + z<-rcdk::view.image.2d(mol, depictor=dep) + grid::rasterGrob(z) + } + + grob <- smiles2img() + + if (!is.null(grob)) { + qplot(1:5, 2*(1:5), geom="blank") + + annotation_custom(grob, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf) + + theme_empty + } else NULL + } + guide_fun <- function() { ## ggplot2::guides(colour=ggplot2::guide_legend(nrow=2, ## byrow=T, diff --git a/R/shiny-ui-base.R b/R/shiny-ui-base.R index c730e229425c9aa0adf4b6e13b94e9a42084e252..05702e121a401ffd86f1890ef2025a0e9a6626d0 100644 --- a/R/shiny-ui-base.R +++ b/R/shiny-ui-base.R @@ -871,11 +871,7 @@ mk_shinyscreen_server <- function(projects,init) { row <- req(input$cindex_row_last_clicked) id <- rowtab <- cind[row][,..key][["ID"]][[1]] smi <- rvs$m$out$tab$comp[ID==(id),SMILES][[1]] - grb <- smiles2img(smi) - xx <- qplot(1:5, 2*(1:5), geom="blank") + - annotation_custom(grb, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf) + - theme_empty - xx + make_struct_plot(smi) }) rf_plot_spec_ms2 <- reactive({ @@ -1260,10 +1256,7 @@ mk_shinyscreen_server <- function(projects,init) { id <- rowtab <- cind[ri][,..key][["ID"]][[1]] smi <- rvs$m$out$tab$comp[ID==(id),SMILES][[1]] - grb <- smiles2img(smi) - p_struc <- qplot(1:5, 2*(1:5), geom="blank") + - annotation_custom(grb, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf) + - theme_empty + p_struc <- make_struct_plot(smi) p_spec <- make_spec_ms2_plot(ms2, summ,