diff --git a/_pkgdown.yaml b/_pkgdown.yaml
deleted file mode 100644
index 723c6b0..0000000
--- a/_pkgdown.yaml
+++ /dev/null
@@ -1,60 +0,0 @@
-title: RHermes
-url: https://rogerginber.github.io/RHermes
-template:
- params:
- bootswatch: flatly
-reference:
- - title: Processing functions
- desc: Needed in the RHermes workflow
- contents:
- - '`setExpParam`'
- - '`setDB`'
- - '`processMS1`'
- - '`findSOI`'
- - '`filterSOI`'
- - '`removeISF`'
- - '`generateIL`'
- - '`filterIL`'
- - '`processMS2`'
- - title: Getters
- desc: Access to the RHermesExp subobjects
- contents:
- - '`adlist`'
- - '`Cluster`'
- - '`DB`'
- - '`PL`'
- - '`SOI`'
- - '`IL`'
- - '`MS2Data`'
- - '`Ident`'
- - title: Exporting functions
- desc: Export your IL and MS2 spectras
- contents:
- - '`exportIL`'
- - '`exportMGF`'
- - '`exportMSP`'
- - '`exportmzML`'
- - '`exportSIRIUS`'
- - title: Plotting functions
- desc: Bring your data alive
- contents:
- - '`plotPL`'
- - '`plotSOI`'
- - '`plotFidelity`'
- - '`plotISF`'
- - '`plotIL`'
- - '`plotSS`'
- - '`plotRawMS2`'
- - title: Accessory functions
- desc: Getting the job done
- contents:
- - '`addAd`'
- - '`remAd`'
- - '`getSOIPar`'
- - '`readTime`'
- - '`setTime`'
- - '`SOIsim`'
- - '`ssNetwork`'
- - '`setCluster`'
-navbar:
- type: default
diff --git a/inst/app/ExtraInfo_UI.R b/inst/app/ExtraInfo_UI.R
index 408e3dc..92fd17f 100644
--- a/inst/app/ExtraInfo_UI.R
+++ b/inst/app/ExtraInfo_UI.R
@@ -38,7 +38,7 @@ ExtraInfo_UI <- function(id){
sidebarPanel(
div(radioButtons(inputId = ns("MS2files"), label = "Select inclusion list with MS2 data:",
choices = "", selected = ""),
- selectInput(ns("MS2ILentry"), "Select IL entry to check:", choices = "", selected = ""),
+ selectizeInput(ns("MS2ILentry"), "Select IL entry to check:", choices = NULL),
style = "margin-left: 5%; margin-top: 3%"), width = "AUTO"),
sidebarPanel(
plotlyOutput(ns("MS2raw")),
@@ -155,7 +155,7 @@ ExtraInfoServer <- function(id, struct){
},{
if(struct$hasMS2){
numMS2entry <- seq_along(struct$dataset@data@MS2Exp[[as.numeric(input$MS2files)]]@MS2Data)
- updateSelectInput(session, "MS2ILentry", choices = numMS2entry, selected = numMS2entry[1])
+ updateSelectizeInput(session, "MS2ILentry", choices = numMS2entry, selected = numMS2entry[1], server = TRUE)
}
})
diff --git a/inst/app/MS2PlotUI.R b/inst/app/MS2PlotUI.R
index f0e6472..91c8a89 100644
--- a/inst/app/MS2PlotUI.R
+++ b/inst/app/MS2PlotUI.R
@@ -1,430 +1,477 @@
-MS2PlotUI <- function(id) {
- ns <- NS(id)
- tagList(
- tags$br(),
-
- radioGroupButtons(inputId = ns("selectclass"), label = "Select a graph :",
- choices = c(` Identifications` = "ident",
- ` Raw MSMS data` = "raw"),
- justified = TRUE),
- radioGroupButtons(ns("id"), "Select MS2Exp:", choices = "",
- selected = ""),
- br(),
-
- conditionalPanel("input.selectclass == 'ident'", ns = ns,
- radioGroupButtons(ns("selectplot"),
- choices = c(`Superspectra Plot` = "sup",
- `Superspectra Comparison` = "comp",
- `Compound matches` = "hits"), justified = TRUE
- ),
- conditionalPanel("input.selectplot == 'sup'", ns = ns,
- fluidRow(column(6, selectizeInput(ns("selectss"),
- label = "Select superspectrum to plot",
- choices = NULL, selected = NULL))),
- plotlyOutput(ns("ssplot"))),
- conditionalPanel("input.selectplot == 'hits'", ns = ns,
- fluidRow(
- column(6,
- selectizeInput(ns("selectident"),
- label = "Select the superspectra entry to check:",
- choices = NULL, selected = NULL)),
- column(6,
- pickerInput(ns("selecthits"),
- label = "Select which hits to check against:",
- choices = NULL, selected = NULL, multiple = TRUE,
- options = list(
- `actions-box` = TRUE))
- )
- ),
- plotlyOutput(ns("mirrorplot"))
- ),
-
- conditionalPanel("input.selectplot == 'comp'", ns = ns,
- fluidRow(
- column(6,
- selectizeInput(ns("selectident2"),
- label = "Select the superspectra entry to check:",
- choices = NULL, selected = NULL)),
- column(6,
- pickerInput(inputId = ns("otherss"),
- label = "Select which superspectra/s to compare with:",
- choices = NULL, selected = NULL, multiple = TRUE,
- options = list(`max-options` = 10))
- )
- ),
- plotlyOutput(ns("versusplot"))
- )
- ),
- conditionalPanel("input.selectclass == 'raw'", ns = ns,
- fluidRow(
- column(6,
- checkboxGroupButtons(
- inputId = ns("rawset"),
- label = "Select what to plot:",
- choices = c("Raw data plot", "Network", "Peak table"),
- checkIcon = list(
- yes = tags$i(class = "fa fa-check-square",
- style = "color: #4D4263"),
- no = tags$i(class = "fa fa-square-o",
- style = "color: #4D4263")),
- selected = c("Raw data plot", "Network", "Peak table")
- )
- )
- ),
- fluidRow(column(width = 6,
- selectizeInput(ns("selectILentry"),
- label = "Select the IL entry to check:", choices = NULL,
- selected = NULL
- )
- ),
- column(width = 6, tags$b("Select plot mode:"),
- switchInput(ns("bymz"), onLabel = "By m/z",
- offLabel = "By group", value = TRUE,
- labelWidth = "AUTO"))),
- fluidRow(
- conditionalPanel("input.rawset.includes('Raw data plot')",
- ns = ns,
- conditionalPanel("input.bymz", ns = ns,
- plotlyOutput(ns("rawMSMS_bymz"), height = "800")),
- conditionalPanel("!input.bymz", ns = ns,
- plotlyOutput(ns("rawMSMS_bygroup"), height = "800")),
- ),
- conditionalPanel("input.rawset.includes('Network')",
- ns = ns, visNetworkOutput(ns("rawss"))),
- conditionalPanel("input.rawset.includes('Peak table')",
- ns = ns,
- column(12, align="center",
- tableOutput(ns('rawpks'))))
- )
- ),
-
- )
-
-}
-
-MS2PlotServer <- function(id, struct) {
- moduleServer(id, function(input, output, session) {
- # observeEvent({},{}, ignoreNULL = TRUE, ignoreInit = TRUE)
-
- ####Updates to buttons, selections, etc.####
- observeEvent({
- struct$hasMS2
- struct$dataset@data@MS2Exp
- }, {
- if (struct$hasMS2) {
- #Determine which have ms2 data
- whichMS2 <- vapply(struct$dataset@data@MS2Exp,
- function(ms2) {
- return(length(ms2@MS2Data) != 0)
- }, logical(1))
- whichMS2 <- which(whichMS2)
-
- #Update accordingly
- updateRadioGroupButtons(session, "id", choices = whichMS2,
- selected = whichMS2[1])
-
- } else {
- #Hide panels again
- updateRadioGroupButtons(session, "id", choices = NULL,
- selected = NULL)
- }
- }, ignoreNULL = TRUE, ignoreInit = TRUE, priority = 100)
-
- observeEvent({
- input$id
- },
- {
- ms2 <- struct$dataset@data@MS2Exp[[as.numeric(input$id)]]
- sslist <- ms2@Ident[["MS2Features"]]
- with_hits <- which(vapply(sslist$results,
- function(x){is.data.frame(x)},
- logical(1)))
- original_IL <- unique(sslist$ILentry)
- updateSelectizeInput(session, "selectident",
- choices = as.character(with_hits), server = TRUE,
- selected = as.character(with_hits[1]),
- options = list(maxOptions = 50000))
- updateSelectizeInput(session, "selectILentry",
- choices = as.character(original_IL),
- selected = as.character(original_IL[1]),
- server = TRUE, options = list(maxOptions = 50000))
- updateSelectizeInput(session, "selectident2",
- choices = as.character(seq_len(nrow((sslist)[1]))), server = TRUE,
- selected = as.character(1),
- options = list(maxOptions = 50000))
- updateSelectizeInput(session, "selectss",
- choices = as.character(seq_len(nrow((sslist)[1]))), server = TRUE,
- selected = as.character(1),
- options = list(maxOptions = 50000))
-
- }, ignoreNULL = TRUE, ignoreInit = TRUE, priority = 50)
-
- observeEvent({input$selectident2},{
- ms2 <- struct$dataset@data@MS2Exp[[as.numeric(input$id)]]
- sslist <- ms2@Ident[["MS2Features"]]
-
- otherss <- seq_len(nrow(sslist))[-as.numeric(input$selectident2)]
-
- updatePickerInput(session, "otherss",
- choices = as.character(otherss),
- selected = as.character(otherss[1]))
- }, ignoreNULL = TRUE, ignoreInit = TRUE
- )
-
- #### Plots ####
- observeEvent({
- input$selectILentry
- input$id
- }, {
- if (input$selectILentry != "" & !is.na(input$selectILentry)) {
- tryCatch({
- rawplots <- plotRawMS2(struct$dataset,
- as.numeric(input$id), as.numeric(input$selectILentry))
- rtrange <- range(rawplots$p_bymz$data$rt)
-
- filtermz <- IL(struct$dataset, as.numeric(input$id))@ILParam@filtermz
- mzprec <- IL(struct$dataset, as.numeric(input$id))@IL$mass[as.numeric(input$selectILentry)]
- mzrange <- c(mzprec - filtermz, mzprec + filtermz)
-
- original_file <- SOI(struct$dataset,
- IL(struct$dataset, as.numeric(input$id))@SOInum)@filename
- original_PL <- which(vapply(struct$dataset@data@PL, function(x) {
- return(x@filename == original_file)
- }, logical(1)))[1]
- original_PL <- PL(struct$dataset, original_PL)
-
- annotated_scans <- filter(original_PL@peaklist,
- between(rt, rtrange[1], rtrange[2]) &
- between(mz, mzrange[1], mzrange[2]))
- raw_scans <- filter(original_PL@raw,
- between(rt, rtrange[1], rtrange[2]) &
- between(mz, mzrange[1], mzrange[2]))
- suppressWarnings({
- ms1plot <- ggplot() +
- geom_point(aes(x=rt, y=rtiv, mz = mz), data = raw_scans, color = "grey") +
- geom_point(aes(x=rt, y=rtiv, color = formv, mz = mz), data = annotated_scans) +
- labs(color = "Ion. Formula") +
- ggtitle("Above: continuous MS2 scans
Below: MS1 data within isolation window")+
- theme_minimal()
- })
-
- output$rawMSMS_bymz <- renderPlotly(
- subplot(rawplots[["p_bymz"]], ggplotly(ms1plot), nrows = 2,
- shareX = TRUE)
- )
- output$rawMSMS_bygroup <- renderPlotly(
- subplot(rawplots[["p_bygroup"]], ggplotly(ms1plot), nrows = 2,
- shareX = TRUE)
- )
-
- output$rawpks <- renderTable(rawplots[["pks"]])
- if (is(rawplots[["net"]], "visNetwork")) {
- output$rawss <- renderVisNetwork(rawplots[["net"]])
- }
- }, error = function(e){message("Raw MS2 plot failed")})
-
- }
- }, ignoreNULL = TRUE, ignoreInit = TRUE, priority = -1)
-
- observeEvent({
- input$selectident
- input$id
- },{
- tryCatch({
- ms2 <- struct$dataset@data@MS2Exp[[as.numeric(input$id)]]
- sslist <- ms2@Ident[["MS2Features"]]
- if(is.data.frame(sslist) & !is.na(as.numeric(input$selectident))){
- if(as.numeric(input$selectident) <= nrow(sslist)){
- cur <- sslist$results[[as.numeric(input$selectident)]]
- if(is.data.frame(cur)){
- updatePickerInput(session, "selecthits", choices = cur$formula,
- selected = cur$formula[[1]])
- }
- }
- }
- }, error = function(cond){})
- }, ignoreNULL = TRUE, ignoreInit = TRUE, priority = 50)
-
- #Identification plot (against MS2 DB hits)
- observeEvent({
- input$selectident
- input$selecthits
- input$id
- }, {
- if (input$selectident != "" & !is.na(input$selectident) &
- length(input$selecthits) != 0) {
- tryCatch({
- ms2 <- struct$dataset@data@MS2Exp[[as.numeric(input$id)]]
- sslist <- ms2@Ident[["MS2Features"]]
- with_hits <- which(vapply(sslist$results,
- function(x){is.data.frame(x)},
- logical(1)))
- if(as.numeric(input$selectident) %in% with_hits){
- identplots <- plotMirror(struct$dataset,
- as.numeric(input$id), as.numeric(input$selectident),
- input$selecthits, mode = "hits")
- output$mirrorplot <- renderPlotly(identplots)
- }
- }, error = function(cond){warning("Identity plot failed")})
- }
- }, ignoreNULL = TRUE, ignoreInit = TRUE, priority = -2)
-
- #Pairwise MS2 spectrum plot
- observeEvent({
- input$selectident2
- input$otherss
- input$id
- }, {
- if (input$selectident2 != "" & !is.na(input$selectident2) &
- length(input$otherss) != 0) {
- tryCatch({
- ms2 <- struct$dataset@data@MS2Exp[[as.numeric(input$id)]]
- sslist <- ms2@Ident[["MS2Features"]]
- identplots <- plotMirror(struct$dataset,
- as.numeric(input$id), as.numeric(input$selectident2),
- as.numeric(input$otherss), mode = "versus")
- output$versusplot <- renderPlotly(identplots)
- }, error = function(e){message("Mirrorplot failed")})
- }
- }, ignoreNULL = TRUE, ignoreInit = TRUE, priority = -2)
-
- #Single MS2 spectrum plot
- observeEvent({
- input$selectss
- input$id
- }, {
- if (!is.na(input$selectss) & input$selectss != "") {
- identplots <- plotSS(struct$dataset, as.numeric(input$id),
- as.numeric(input$selectss))
- output$ssplot <- renderPlotly(identplots)
- }
- }, ignoreNULL = TRUE, ignoreInit = TRUE, priority = -2)
- })
-}
-
-plotMirror <- function(struct, id, ssnumber, patform, mode = "hits") {
- entry <- struct@data@MS2Exp[[id]]@Ident$MS2Features[ssnumber,]
- query <- entry$ssdata[[1]]
- maxint <- max(query$int)
- query$int <- query$int/max(query$int) * 100
- bestdf <- query[query$int > 10, ]
- bestdf$mz <- round(bestdf$mz, 4)
- molecmass <- entry$precmass
- baseline <- 1000
- subtitle <- ""
- title <- ""
- baseline <- baseline/maxint * 100
-
- f <- list(
- family = "Open Sans",
- size = 16,
- color = "black"
- )
-
- if(mode == "hits"){
- ref <- struct@data@MS2Exp[[id]]@Ident$MS2_correspondance[[ssnumber]]
- pattern <- struct@data@MS2Exp[[id]]@Ident$DatabaseSpectra[ref]
- pattern <- unname(pattern) #Avoids "name.subname" when unlisting
- pattern <- unlist(pattern, recursive = FALSE, use.names = TRUE)
- }
-
- mirrplot <- lapply(patform, function(x){
- pl <- ggplot()
- if(mode == "hits"){
- index <- entry$results[[1]]$id[entry$results[[1]]$formula == x]
- if(length(index) == 0){
- refspec <- NULL
- } else {
- refspec <- pattern[[x]][[index]]
- spec_energy <- names(pattern[[x]])[index]
- comp_name <- strsplit(patform, split = "#")[[which(patform == x)[1]]][3]
- a <- list(
- text = paste(comp_name, spec_energy),
- font = f,
- xref = "paper",
- yref = "paper",
- yanchor = "bottom",
- xanchor = "center",
- align = "center",
- x = 0.5,
- y = 1,
- showarrow = FALSE
- )
- }
- if(is.null(refspec)){return(ggplotly(pl))}
- refspec <- as.data.frame(t(refspec))
- pl <- pl + scale_x_continuous(limits = c(min(c(refspec$mz,
- query$mz, molecmass)) - 20,
- max(c(refspec$mz, query$mz,
- molecmass)) + 20))
- }
- if(mode == "versus"){
- refmass<-struct@data@MS2Exp[[id]]@Ident$MS2Features$precmass[[x]]
- refspec <- struct@data@MS2Exp[[id]]@Ident$MS2Features$ssdata[[x]]
- if(is.null(refspec)){return(ggplotly(pl))}
-
- a <- list(
- text = paste("SS comparison between", ssnumber, "and", x),
- font = f,
- xref = "paper",
- yref = "paper",
- yanchor = "bottom",
- xanchor = "center",
- align = "center",
- x = 0.5,
- y = 1,
- showarrow = FALSE
- )
-
- refdf <- data.frame(mz = refmass)
- pl <- pl +
- geom_point(data = refdf, aes(x = .data$mz, y = 0), shape = 25,
- size = 4, color = "red", fill = "red") +
- scale_x_continuous(limits = c(min(c(refspec$mz, query$mz,
- molecmass, refmass)) - 20,
- max(c(refspec$mz, query$mz, molecmass,
- refmass)) + 20))
- }
- colnames(refspec) <- c("mz", "int")
- refspec$int <- refspec$int/max(refspec$int) * 100
-
- moldf <- data.frame(mz = molecmass)
- bldf <- data.frame(xmin = min(c(refspec$mz, query$mz,
- molecmass)) - 5,
- xmax = max(c(refspec$mz,query$mz,
- molecmass) + 5),
- y = baseline)
-
- pl <- pl + geom_segment(data = query, aes(x = .data$mz,
- xend = .data$mz, y = 0, yend = .data$int),
- color = "black") +
- geom_segment(data = refspec, aes(x = .data$mz,
- xend = .data$mz, y = 0, yend = -.data$int),
- color = "red") +
- geom_segment(data = bldf, aes(x = .data$xmin,
- xend = .data$xmax, y = .data$y, yend = .data$y),
- linetype = "dashed", color = "black", alpha = 0.3) +
- geom_segment(data = bldf, aes(x = .data$xmin,
- xend = .data$xmax, y = -.data$y, yend = -.data$y),
- linetype = "dashed", color = "red", alpha = 0.3) +
- geom_point(data = moldf, aes(x = .data$mz, y = 0),
- shape = 17, size = 2) +
- theme_minimal() + ylab("% Intensity") +
- theme(plot.margin = unit(c(1, 0.7, 1, 0.8), "cm"),
- text = element_text(size = 11,
- family = "Segoe UI Light"),
- plot.title = element_text(hjust = 0.5)) +
- geom_text(data = bestdf, aes(x = .data$mz,
- y = .data$int + 5,
- label = .data$mz),
- family = "Segoe UI Light", check_overlap = TRUE)
-
- base_height <- ifelse(length(patform)<5, 850/length(patform), 200)
- ggplotly(pl, height = base_height * length(patform)) %>%
- layout(annotations = a)
- })
-
- return(subplot(mirrplot, nrows = length(mirrplot), shareX = TRUE,
- which_layout = 1))
-}
-
+MS2PlotUI <- function(id) {
+ ns <- NS(id)
+ tagList(
+ tags$br(),
+
+ radioGroupButtons(inputId = ns("selectclass"), label = "Select a graph :",
+ choices = c(` Identifications` = "ident",
+ ` Raw MSMS data` = "raw"),
+ justified = TRUE),
+ radioGroupButtons(ns("id"), "Select MS2Exp:", choices = "",
+ selected = ""),
+ br(),
+
+ conditionalPanel("input.selectclass == 'ident'", ns = ns,
+ radioGroupButtons(ns("selectplot"),
+ choices = c(`Superspectra Plot` = "sup",
+ `Superspectra Comparison` = "comp",
+ `Compound matches` = "hits"), justified = TRUE
+ ),
+ conditionalPanel("input.selectplot == 'sup'", ns = ns,
+ fluidRow(column(6, selectizeInput(ns("selectss"),
+ label = "Select superspectrum to plot",
+ choices = NULL, selected = NULL))),
+ plotlyOutput(ns("ssplot"))),
+ conditionalPanel("input.selectplot == 'hits'", ns = ns,
+ fluidRow(
+ column(6,
+ selectizeInput(ns("selectident"),
+ label = "Select the superspectra entry to check:",
+ choices = NULL, selected = NULL)),
+ column(6,
+ pickerInput(ns("selecthits"),
+ label = "Select which hits to check against:",
+ choices = NULL, selected = NULL, multiple = TRUE,
+ options = list(
+ `actions-box` = TRUE))
+ )
+ ),
+ plotlyOutput(ns("mirrorplot"))
+ ),
+
+ conditionalPanel("input.selectplot == 'comp'", ns = ns,
+ fluidRow(
+ column(6,
+ selectizeInput(ns("selectident2"),
+ label = "Select the superspectra entry to check:",
+ choices = NULL, selected = NULL)),
+ column(6,
+ pickerInput(inputId = ns("otherss"),
+ label = "Select which superspectra/s to compare with:",
+ choices = NULL, selected = NULL, multiple = TRUE,
+ options = list(`max-options` = 10))
+ )
+ ),
+ plotlyOutput(ns("versusplot"))
+ )
+ ),
+ conditionalPanel("input.selectclass == 'raw'", ns = ns,
+ fluidRow(
+ column(6,
+ checkboxGroupButtons(
+ inputId = ns("rawset"),
+ label = "Select what to plot:",
+ choices = c("Raw data plot", "Network", "Peak table"),
+ checkIcon = list(
+ yes = tags$i(class = "fa fa-check-square",
+ style = "color: #4D4263"),
+ no = tags$i(class = "fa fa-square-o",
+ style = "color: #4D4263")),
+ selected = c("Raw data plot", "Network", "Peak table")
+ )
+ )
+ ),
+ fluidRow(column(width = 6,
+ selectizeInput(ns("selectILentry"),
+ label = "Select the IL entry to check:", choices = NULL,
+ selected = NULL
+ )
+ ),
+ column(width = 6, tags$b("Select plot mode:"),
+ switchInput(ns("bymz"), onLabel = "By m/z",
+ offLabel = "By group", value = TRUE,
+ labelWidth = "AUTO"))),
+ fluidRow(
+ conditionalPanel("input.rawset.includes('Raw data plot')",
+ ns = ns,
+ conditionalPanel("input.bymz", ns = ns,
+ plotlyOutput(ns("rawMSMS_bymz"), height = "800")),
+ conditionalPanel("!input.bymz", ns = ns,
+ plotlyOutput(ns("rawMSMS_bygroup"), height = "800")),
+ ),
+ conditionalPanel("input.rawset.includes('Network')",
+ ns = ns, visNetworkOutput(ns("rawss"))),
+ conditionalPanel("input.rawset.includes('Peak table')",
+ ns = ns,
+ column(12, align="center",
+ tableOutput(ns('rawpks'))))
+ )
+ ),
+
+ )
+
+}
+
+MS2PlotServer <- function(id, struct) {
+ moduleServer(id, function(input, output, session) {
+ # observeEvent({},{}, ignoreNULL = TRUE, ignoreInit = TRUE)
+
+ #### Updates to buttons, selections, etc. ####
+ observeEvent({
+ struct$hasMS2
+ struct$dataset@data@MS2Exp
+ }, {
+ if (struct$hasMS2) {
+ ## Determine which have ms2 data
+ whichMS2 <- vapply(struct$dataset@data@MS2Exp,
+ function(ms2) {
+ return(length(ms2@MS2Data) != 0)
+ }, logical(1))
+ whichMS2 <- which(whichMS2)
+
+ #Update accordingly
+ updateRadioGroupButtons(session, "id", choices = whichMS2,
+ selected = whichMS2[1])
+
+ } else {
+ #Hide panels again
+ updateRadioGroupButtons(session, "id", choices = NULL,
+ selected = NULL)
+ }
+ }, ignoreNULL = TRUE, ignoreInit = TRUE, priority = 100)
+
+ observeEvent({
+ input$id
+ },
+ {
+ ms2 <- struct$dataset@data@MS2Exp[[as.numeric(input$id)]]
+ sslist <- ms2@Ident[["MS2Features"]]
+
+
+ ## Identification against DB mirror plot selector
+ with_hits <- which(vapply(sslist$results,
+ function(x){is.data.frame(x)},
+ logical(1)))
+ updateSelectizeInput(session, "selectident",
+ choices = as.character(with_hits), server = TRUE,
+ selected = as.character(with_hits[1]),
+ options = list(maxOptions = 50000))
+
+ ## Raw MS2 plot selector
+ original_IL <- unique(sslist$ILentry)
+ ## Add some useful info to IL labels
+ entries_list <- as.list(as.character(original_IL))
+ if (length(original_IL != 0)){
+ labels <- lapply(original_IL, function(id){
+ entries <- sslist[sslist$ILentry == id, ]
+ paste(id,
+ "RT:", round(min(entries$start), 2), "-", round(max(entries$end),2),
+ "mz:", round(mean(entries$precmass), 4))
+ })
+ names(entries_list) <- labels
+ }
+ updateSelectizeInput(session, "selectILentry",
+ choices = entries_list,
+ selected = entries_list[1],
+ server = TRUE, options = list(maxOptions = 50000))
+
+
+
+ #MS2 spectra plotter and mirror plot among MS2 spectra
+ spectra_info <- paste(seq_len(nrow(sslist)),
+ "RT:", round(sslist$start, 2), round(sslist$apex, 2), round(sslist$end, 2),
+ "mz:", round(sslist$precmass, 4))
+ spectra_list <- as.list(seq_len(nrow(sslist)))
+ names(spectra_list) <- spectra_info
+
+
+ updateSelectizeInput(session, "selectident2",
+ choices = spectra_list,
+ server = TRUE,
+ selected = NULL,
+ options = list(maxOptions = 50000))
+ updateSelectizeInput(session, "selectss",
+ choices = spectra_list,
+ server = TRUE,
+ selected = NULL,
+ options = list(maxOptions = 50000))
+
+ }, ignoreNULL = TRUE, ignoreInit = TRUE, priority = 50)
+
+ observeEvent({input$selectident2},{
+ if(input$selectident2 != ""){
+ ms2 <- struct$dataset@data@MS2Exp[[as.numeric(input$id)]]
+ sslist <- ms2@Ident[["MS2Features"]]
+
+ spectra_info <- paste(seq_len(nrow(sslist)),
+ "RT:", round(sslist$start, 2), round(sslist$apex, 2), round(sslist$end, 2),
+ "mz:", round(sslist$precmass, 4))
+ spectra_list <- as.list(seq_len(nrow(sslist)))
+ names(spectra_list) <- spectra_info
+
+ #Remove picker1 selection from picker2's options
+ updatePickerInput(session, "otherss",
+ choices = spectra_list[-as.numeric(input$selectident2)],
+ selected = NULL)
+ }
+ }, ignoreNULL = TRUE, ignoreInit = TRUE
+ )
+
+ #### Plots ####
+ observeEvent({
+ input$selectILentry
+ input$id
+ }, {
+ if (input$selectILentry != "" & !is.na(input$selectILentry)) {
+ tryCatch({
+ rawplots <- plotRawMS2(struct$dataset,
+ as.numeric(input$id), as.numeric(input$selectILentry))
+ rtrange <- range(rawplots$p_bymz$data$rt)
+
+ filtermz <- IL(struct$dataset, as.numeric(input$id))@ILParam@filtermz
+ mzprec <- IL(struct$dataset, as.numeric(input$id))@IL$mass[as.numeric(input$selectILentry)]
+ mzrange <- c(mzprec - filtermz, mzprec + filtermz)
+
+ original_file <- SOI(struct$dataset,
+ IL(struct$dataset, as.numeric(input$id))@SOInum)@filename
+ original_PL <- which(vapply(struct$dataset@data@PL, function(x) {
+ return(x@filename == original_file)
+ }, logical(1)))[1]
+ original_PL <- PL(struct$dataset, original_PL)
+
+ annotated_scans <- dplyr::filter(original_PL@peaklist,
+ between(rt, rtrange[1], rtrange[2]) &
+ between(mz, mzrange[1], mzrange[2]))
+ suppressWarnings({
+ ms1plot <- ggplot() +
+ geom_point(aes(x=rt, y=rtiv, color = formv, mz = mz), data = annotated_scans) +
+ labs(color = "Ion. Formula") +
+ ggtitle("Above: continuous MS2 scans
Below: MS1 data within isolation window")+
+ theme_minimal()
+ })
+
+ raw_scans <- original_PL@raw
+ if(nrow(raw_scans) != 0){
+ raw_scans <- dplyr::filter(original_PL@raw,
+ between(rt, rtrange[1], rtrange[2]) &
+ between(mz, mzrange[1], mzrange[2]))
+ raw_scans <- dplyr::anti_join(raw_scans, annotated_scans)
+ ms1plot <- ms1plot +
+ geom_point(aes(x=rt, y=rtiv, mz = mz, color = "Unknown"), data = raw_scans)
+
+ }
+ output$rawMSMS_bymz <- renderPlotly(
+ subplot(rawplots[["p_bymz"]], ggplotly(ms1plot), nrows = 2,
+ shareX = TRUE)
+ )
+ output$rawMSMS_bygroup <- renderPlotly(
+ subplot(rawplots[["p_bygroup"]], ggplotly(ms1plot), nrows = 2,
+ shareX = TRUE)
+ )
+
+ output$rawpks <- renderTable(rawplots[["pks"]])
+ if (is(rawplots[["net"]], "visNetwork")) {
+ output$rawss <- renderVisNetwork(rawplots[["net"]])
+ }
+ }, error = function(e){
+ sendSweetAlert(session = session, title = "Error",
+ text = "Raw MS2 plot failed, meaning no enough points were acquired for this entry",
+ type = "warning")
+ message("Raw MS2 plot failed")
+ })
+
+ }
+ }, ignoreNULL = TRUE, ignoreInit = TRUE, priority = -1)
+
+ observeEvent({
+ input$selectident
+ input$id
+ },{
+ tryCatch({
+ ms2 <- struct$dataset@data@MS2Exp[[as.numeric(input$id)]]
+ sslist <- ms2@Ident[["MS2Features"]]
+ if(is.data.frame(sslist) & !is.na(as.numeric(input$selectident))){
+ if(as.numeric(input$selectident) <= nrow(sslist)){
+ cur <- sslist$results[[as.numeric(input$selectident)]]
+ if(is.data.frame(cur)){
+ updatePickerInput(session, "selecthits", choices = cur$formula,
+ selected = cur$formula[[1]])
+ }
+ }
+ }
+ }, error = function(cond){})
+ }, ignoreNULL = TRUE, ignoreInit = TRUE, priority = 50)
+
+ #Identification plot (against MS2 DB hits)
+ observeEvent({
+ input$selectident
+ input$selecthits
+ input$id
+ }, {
+ if (input$selectident != "" & !is.na(input$selectident) &
+ length(input$selecthits) != 0) {
+ tryCatch({
+ ms2 <- struct$dataset@data@MS2Exp[[as.numeric(input$id)]]
+ sslist <- ms2@Ident[["MS2Features"]]
+ with_hits <- which(vapply(sslist$results,
+ function(x){is.data.frame(x)},
+ logical(1)))
+ if(as.numeric(input$selectident) %in% with_hits){
+ identplots <- plotMirror(struct$dataset,
+ as.numeric(input$id), as.numeric(input$selectident),
+ input$selecthits, mode = "hits")
+ output$mirrorplot <- renderPlotly(identplots)
+ }
+ }, error = function(cond){warning("Identity plot failed")})
+ }
+ }, ignoreNULL = TRUE, ignoreInit = TRUE, priority = -2)
+
+ #Pairwise MS2 spectrum plot
+ observeEvent({
+ input$selectident2
+ input$otherss
+ input$id
+ }, {
+ if (input$selectident2 != "" & !is.na(input$selectident2) &
+ length(input$otherss) != 0) {
+ tryCatch({
+ ms2 <- struct$dataset@data@MS2Exp[[as.numeric(input$id)]]
+ sslist <- ms2@Ident[["MS2Features"]]
+ identplots <- plotMirror(struct$dataset,
+ as.numeric(input$id), as.numeric(input$selectident2),
+ as.numeric(input$otherss), mode = "versus")
+ output$versusplot <- renderPlotly(identplots)
+ }, error = function(e){message("Mirrorplot failed")})
+ }
+ }, ignoreNULL = TRUE, ignoreInit = TRUE, priority = -2)
+
+ #Single MS2 spectrum plot
+ observeEvent({
+ input$selectss
+ input$id
+ }, {
+ if (!is.na(input$selectss) & input$selectss != "") {
+ identplots <- plotSS(struct$dataset, as.numeric(input$id),
+ as.numeric(input$selectss))
+ output$ssplot <- renderPlotly(identplots)
+ }
+ }, ignoreNULL = TRUE, ignoreInit = TRUE, priority = -2)
+ })
+}
+
+plotMirror <- function(struct, id, ssnumber, patform, mode = "hits") {
+ entry <- struct@data@MS2Exp[[id]]@Ident$MS2Features[ssnumber,]
+ query <- entry$ssdata[[1]]
+ maxint <- max(query$int)
+ query$int <- query$int/max(query$int) * 100
+ bestdf <- query[query$int > 10, ]
+ bestdf$mz <- round(bestdf$mz, 4)
+ molecmass <- entry$precmass
+ baseline <- 1000
+ subtitle <- ""
+ title <- ""
+ baseline <- baseline/maxint * 100
+
+ f <- list(
+ family = "Open Sans",
+ size = 16,
+ color = "black"
+ )
+
+ if(mode == "hits"){
+ ref <- struct@data@MS2Exp[[id]]@Ident$MS2_correspondance[[ssnumber]]
+ pattern <- struct@data@MS2Exp[[id]]@Ident$DatabaseSpectra[ref]
+ pattern <- unname(pattern) #Avoids "name.subname" when unlisting
+ pattern <- unlist(pattern, recursive = FALSE, use.names = TRUE)
+ }
+
+ mirrplot <- lapply(patform, function(x){
+ pl <- ggplot()
+ if(mode == "hits"){
+ index <- entry$results[[1]]$id[entry$results[[1]]$formula == x]
+ if(length(index) == 0){
+ refspec <- NULL
+ } else {
+ refspec <- pattern[[x]][[index]]
+ spec_energy <- names(pattern[[x]])[index]
+ comp_name <- strsplit(patform, split = "#")[[which(patform == x)[1]]][3]
+ a <- list(
+ text = paste(comp_name, spec_energy),
+ font = f,
+ xref = "paper",
+ yref = "paper",
+ yanchor = "bottom",
+ xanchor = "center",
+ align = "center",
+ x = 0.5,
+ y = 1,
+ showarrow = FALSE
+ )
+ }
+ if(is.null(refspec)){return(ggplotly(pl))}
+ refspec <- as.data.frame(t(refspec))
+ pl <- pl + scale_x_continuous(limits = c(min(c(refspec$mz,
+ query$mz, molecmass)) - 20,
+ max(c(refspec$mz, query$mz,
+ molecmass)) + 20))
+ }
+ if(mode == "versus"){
+ refmass<-struct@data@MS2Exp[[id]]@Ident$MS2Features$precmass[[x]]
+ refspec <- struct@data@MS2Exp[[id]]@Ident$MS2Features$ssdata[[x]]
+ if(is.null(refspec)){return(ggplotly(pl))}
+
+ a <- list(
+ text = paste("SS comparison between", ssnumber, "and", x),
+ font = f,
+ xref = "paper",
+ yref = "paper",
+ yanchor = "bottom",
+ xanchor = "center",
+ align = "center",
+ x = 0.5,
+ y = 1,
+ showarrow = FALSE
+ )
+
+ refdf <- data.frame(mz = refmass)
+ pl <- pl +
+ geom_point(data = refdf, aes(x = .data$mz, y = 0), shape = 25,
+ size = 4, color = "red", fill = "red") +
+ scale_x_continuous(limits = c(min(c(refspec$mz, query$mz,
+ molecmass, refmass)) - 20,
+ max(c(refspec$mz, query$mz, molecmass,
+ refmass)) + 20))
+ }
+ colnames(refspec) <- c("mz", "int")
+ refspec$int <- refspec$int/max(refspec$int) * 100
+
+ moldf <- data.frame(mz = molecmass)
+ bldf <- data.frame(xmin = min(c(refspec$mz, query$mz,
+ molecmass)) - 5,
+ xmax = max(c(refspec$mz,query$mz,
+ molecmass) + 5),
+ y = baseline)
+
+ pl <- pl + geom_segment(data = query, aes(x = .data$mz,
+ xend = .data$mz, y = 0, yend = .data$int),
+ color = "black") +
+ geom_segment(data = refspec, aes(x = .data$mz,
+ xend = .data$mz, y = 0, yend = -.data$int),
+ color = "red") +
+ geom_segment(data = bldf, aes(x = .data$xmin,
+ xend = .data$xmax, y = .data$y, yend = .data$y),
+ linetype = "dashed", color = "black", alpha = 0.3) +
+ geom_segment(data = bldf, aes(x = .data$xmin,
+ xend = .data$xmax, y = -.data$y, yend = -.data$y),
+ linetype = "dashed", color = "red", alpha = 0.3) +
+ geom_point(data = moldf, aes(x = .data$mz, y = 0),
+ shape = 17, size = 2) +
+ theme_minimal() + ylab("% Intensity") +
+ theme(plot.margin = unit(c(1, 0.7, 1, 0.8), "cm"),
+ text = element_text(size = 11,
+ family = "Segoe UI Light"),
+ plot.title = element_text(hjust = 0.5)) +
+ geom_text(data = bestdf, aes(x = .data$mz,
+ y = .data$int + 5,
+ label = .data$mz),
+ family = "Segoe UI Light", check_overlap = TRUE)
+
+ base_height <- ifelse(length(patform)<5, 850/length(patform), 200)
+ ggplotly(pl, height = base_height * length(patform)) %>%
+ layout(annotations = a)
+ })
+
+ return(subplot(mirrplot, nrows = length(mirrplot), shareX = TRUE,
+ which_layout = 1))
+}
+
diff --git a/inst/app/PLPlotUI.R b/inst/app/PLPlotUI.R
index 039894a..48ba7a9 100644
--- a/inst/app/PLPlotUI.R
+++ b/inst/app/PLPlotUI.R
@@ -64,7 +64,8 @@ PLPlotUI <- function(id){
column(4, switchInput(ns("mzmetric"), "Use ppm?", value = TRUE, onLabel = "ppm", offLabel = "absolute")),
column(8, numericInput(ns("mztol"), "mz tolerance", value = 3, min = 0, max = 5000, step = 0.001)),
sliderInput(ns("RTinterval_raw"), label = "Select an RT interval:",
- min = 0, max = 1800, value = c(0,1800))
+ min = 0, max = 1800, value = c(0,1800)),
+ sliderInput(ns("Intensity_raw"), "Select a log10 intensity range:", min = 0, max = 10, step = 0.05, value=c(0,10))
)
), width = 12),
width = "100%"),
@@ -148,6 +149,7 @@ PLPlotServer <- function(id, struct){
input$mzmetric
input$mztol
input$PLfiles_raw
+ input$Intensity_raw
},{
if(struct$hasPL){
d <- struct$dataset@data@PL[[as.numeric(input$PLfiles_raw)]]@raw
@@ -159,13 +161,17 @@ PLPlotServer <- function(id, struct){
tol <- as.numeric(input$mztol)
}
d <- filter(d, between(mz, target - tol, target + tol) &
- between(rt, as.numeric(input$RTinterval_raw[[1]]),
- as.numeric(input$RTinterval_raw[[2]])))
+ between(rt,
+ as.numeric(input$RTinterval_raw[[1]]),
+ as.numeric(input$RTinterval_raw[[2]])),
+ between(log10(rtiv),
+ as.numeric(input$Intensity_raw[[1]]),
+ as.numeric(input$Intensity_raw[[2]])))
if(nrow(d) < 1e5){
p1 <- ggplotly(ggplot(d) +
geom_point(aes(x=rt, y=mz, color = log10(rtiv)))+
labs(color = "log10(Intensity)") +
- scale_colour_gradient(low = "#CFB7E5", high = "#15004D") +
+ scale_color_viridis_c(option = "inferno") +
xlab("Retention time (s)") +
ylab("m/z")
)
@@ -173,7 +179,7 @@ PLPlotServer <- function(id, struct){
p2 <- ggplotly(ggplot(d) +
geom_point(aes(x=rt, y=log10(rtiv), color = mz)) +
labs(color = "mz") +
- scale_colour_gradient(low = "#CFB7E5", high = "#15004D") +
+ scale_color_viridis_c(option = "inferno") +
xlab("Retention time (s)") +
ylab("Intensity")
)
diff --git a/inst/app/SOI_UI.R b/inst/app/SOI_UI.R
index 9d73c14..4d9c569 100644
--- a/inst/app/SOI_UI.R
+++ b/inst/app/SOI_UI.R
@@ -279,9 +279,7 @@ SOIServer <- function(id, struct){
tags$li(tags$b("Maximum SOI RT"), ": The algorithm will split long SOIs (larger than the selected value),
into smaller ones. Longer values take shorter (since there aren't as many SOI entries), but blank
substraction problems can arise and it's not really worth it. Better left as default."),
- tags$li(tags$b("Blank Substraction"), ": Whether to perform Blank Substraction (Optional but recommended).",
- tags$b("Important:"), "The blank substraction step requires setting up Keras and Tensorflow first.
- If you haven't done it please check the package Readme file to see how to do it.")
+ tags$li(tags$b("Blank Substraction"), ": Whether to perform Blank Substraction (Optional but recommended).")
),
tags$p("To generate the SOI list (or lists) you have to set up the desired parameters and click \"Add selected config\".
When you do so, you will see that the input parameters appear in the box below the button. You can either add more configs
diff --git a/inst/app/Settings_UI.R b/inst/app/Settings_UI.R
deleted file mode 100644
index 73a3aab..0000000
--- a/inst/app/Settings_UI.R
+++ /dev/null
@@ -1,57 +0,0 @@
-Settings_UI <- function(id){
- ns <- NS(id)
- tagList(
- sidebarPanel(
- fluidRow(
- column(selectInput(inputId = ns("partype"),
- label = "Select Parallelization type:",
- choices = c("serial", "snow"), selected = "snow"),
- width = 4),
- column(numericInput(inputId = ns("coreN"), label = "Number of cores",
- value = 1, min = 1,
- max = BiocParallel::bpworkers(),
- step = 1), width = 4),
- ),
- fluidRow(
- column(actionButton(ns("saveSet"), label = "Save Settings",
- icon = icon("save")), width = 4)
- ),
- width = 12)
- )
-}
-
-SettingsServer <- function(id, struct){
- moduleServer(id, function(input, output, session) {
-
- if(Sys.info()["sysname"] != "Windows"){
- updateSelectInput(session = session, inputId = "partype",
- choices = c(serial = "serial", snow = "snow",
- "multicore (FORK)" = "multicore"))
- }
-
- observeEvent({
- input$partype
- }, {
- if(input$partype == "serial"){updateNumericInput(session = session,
- inputId = "coreN",
- value = 1, max = 1)
- } else {updateNumericInput(session = session, inputId = "coreN",
- max = BiocParallel::bpworkers())}
- })
-
- toReturn <- reactiveValues(dataset = RHermesExp(), trigger = 0)
- observeEvent({
- input$saveSet
- }, {
- backend <- switch(input$partype,
- serial = BiocParallel::SerialParam(),
- snow = BiocParallel::SnowParam(workers = as.numeric(input$coreN)),
- multicore = BiocParallel::MulticoreParam(workers =
- as.numeric(input$coreN))
- )
- BiocParallel::register(backend)
- }, ignoreInit = TRUE, ignoreNULL = TRUE)
-
- return(toReturn)
- })
-}
diff --git a/inst/app/app.R b/inst/app/app.R
index e9e74b0..31bffb3 100644
--- a/inst/app/app.R
+++ b/inst/app/app.R
@@ -1,180 +1,171 @@
-for(i in list.files(system.file("app", package = "RHermes"), pattern = "UI",
- full.names = TRUE)){
- source(i, local = TRUE)
-}
-
-library(shiny)
-library(shinyFiles)
-library(shinydashboard)
-library(shinyWidgets)
-library(RHermes)
-library(data.table, quietly = TRUE)
-library(enviPat)
-library(igraph)
-require(mzR)
-require(magrittr)
-require(CHNOSZ)
-require(ggplot2)
-library(keras)
-library(plotly)
-library(visNetwork)
-library(KEGGREST)
-library(slickR)
-library(BiocParallel)
-library(DT)
-
-header <- dashboardHeader(
- title = p("RHermes", style = "font-family: Open Sans, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Arial; font-size: 22px"),
- dropdownMenuOutput(outputId = "dropdown_m")
- )
-
-sidebar <- dashboardSidebar(
- sidebarMenu(
- menuItem("Intro", tabName = "intro", icon = icon("info")),
- menuItem("From mzML to PL", tabName = "mz2PL", icon = icon("bolt")),
- menuItem("SOI detection", tabName = "SOIdet", icon = icon("barcode")),
- menuItem("Inclusion list generation", tabName = "IL", icon = icon("list")),
- menuItem("MSMS data processing", tabName = "MSMS", icon = icon("atom")),
- menuItem("Identifications", tabName = "ident", icon = icon("fingerprint")),
- menuItem("Plots", tabName = "Plots", icon = icon("chart-bar"),
- menuSubItem("PL Exploration", tabName = "PLplot"),
- menuSubItem("SOI Exploration", tabName = "SOIplot"),
- menuSubItem("MS2 Exploration", tabName = "MS2plot")
- ),
- menuItem("Tables", tabName = "extra", icon = icon("table")),
- menuItem("Settings", tabName = "sett", icon = icon("file-alt")),
- menuItem("Loading/Saving", tabName = "IO", icon = icon("save")),
- div(actionButton("shutdown", label="Shutdown app", icon = icon("power-off"),
- style ="background-color: #222d32; color: #b8c7ce; border-color: #b8c7ce; border-width:1px"),
- style = "margin-top:100%; width: 220px; display: inline-grid; position:fixed; bottom:0")
- )
-)
-
-body <- dashboardBody(
- tags$head(tags$link(rel="stylesheet", href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.0.0/animate.min.css")), ##Adds animate.css animations
- tags$script(HTML("$('body').addClass('fixed');")),
- includeCSS("./www/customStyle.css"),
- tabItems(
- # First tab content
- tabItem(tabName = "intro",
- titlePanel(
- div(class="animate__animated animate__pulse", h1(tags$b("RHermes"), align = "center"), style = "text-align: center;")),
- mainPanel(width = 20,
- HTML("RHermes is a broad-scoped targeted metabolomics software designed to identify compounds in biological and environmental samples.
- We invert the classical peak-first metabolite detection workflows by first annotating the LC-MS1 raw data points themselves
- using a database of plasusible formulas and adducts. This ultimately results in a very sample-specific inclusion list of ions to monitor in a MS2 experiment
- RHermes has shown that up to 90% of a typical data-dependent acquisition (DDA) MS2 experiment is wasted in redundant and non-biological ions, leading to fake positive
- identifications while missing the true compounds in the sample.
"),
- HTML(" We believe there's a better way to characterize the metabolites in our samples
- RHermes
"),
- HTML("You can find the molecular formula databases and sample mzML files in the paper in our Zenodo dataset
"),
- hr(),
- HTML("The Workflow
"),
- br(),
- tags$script(src = 'scroll.js'),
- HTML("
"),
- img(src = "step1.svg", width = "100%", class = "steps"),
- HTML("
"),
- img(src = "step2.svg", width = "100%", class = "steps"),
- HTML("
"),
- img(src = "step3.svg", width = "100%", class = "steps"),
- hr(),
- h2("Bug reports"),
- HTML("In case you find any abnormal behaviour (eg: app unexpectedly crashes, etc.) feel free to email
- the mantainer at roger.gine@estudiants.urv or open a Github issue.
- You should provide a detailed description about what happened, screenshots of the error and, desirably, a minimally reproducible example
"),
- h2("Citation"),
- HTML("Please cite this software as:
"),
- HTML(" HERMES: a molecular formula-oriented method to target the metabolome
- Roger Giné, Jordi Capellades, Josep M. Badia, Dennis Vughs, Michaela Schwaiger-Haber, Maria Vinaixa, Andrea M. Brunner, Gary J. Patti, Oscar Yanes
- bioRxiv 2021.03.08.434466; doi: https://doi.org/10.1101/2021.03.08.434466
"),
- style = "padding : 20px 50px 50px 50px")
- ),
-
- tabItem(tabName = "mz2PL", PL_UI("PL_UI")),
- tabItem(tabName = "SOIdet", SOI_UI("SOI_UI")),
- tabItem(tabName = "IL", IL_UI("IL_UI")),
- tabItem(tabName = "MSMS", MS2_UI("MS2_UI")),
- tabItem(tabName = "Plots", verticalLayout()),
- tabItem(tabName = "PLplot", PLPlotUI("PLPlotUI")),
- tabItem(tabName = "SOIplot", SOIPlotUI("SOIPlotUI")),
- tabItem(tabName = "MS2plot", MS2PlotUI("MS2PlotUI")),
- tabItem(tabName = "ident", Ident_UI("Identifications")),
- tabItem(tabName = "extra", ExtraInfo_UI("ExtraInfo_UI")),
- tabItem(tabName = "sett", Settings_UI("Settings_UI")),
- tabItem(tabName = "IO", IO_UI("IO_UI"))
- )
-)
-
-ui <- dashboardPage(header, sidebar, body, title = "RHermes")
-
-server <- function(input, output, session){
-
- struct <- reactiveValues(dataset=RHermesExp(), hasPL = FALSE, hasSOI = FALSE,
- hasIL = FALSE, hasMS2 = FALSE)
-
- observe({
- struct$hasPL <- ifelse(length(struct$dataset@data@PL)!=0, TRUE, FALSE)
- struct$hasSOI <- ifelse(length(struct$dataset@data@SOI)!=0, TRUE, FALSE)
- struct$hasIL <- ifelse(length(struct$dataset@data@MS2Exp)!=0, TRUE, FALSE)
- if(struct$hasIL){
- struct$hasMS2 <- any(vapply(struct$dataset@data@MS2Exp, function(x){
- length(x@Ident)!=0
- }, logical(1))) }
- })
-
- output$dropdown_m <- renderMenu({
- dropdownMenu(type = "tasks", badgeStatus = "primary",
- taskItem(value = ifelse(struct$hasPL, 100, 0), color = "green",
- "The object has PL/s"
- ),
- taskItem(value = ifelse(struct$hasSOI, 100, 0), color = "aqua",
- "The object has SOI list/s"
- ),
- taskItem(value = ifelse(struct$hasIL, 100, 0),color = "yellow",
- "The object has IL/s"
- ),
- taskItem(value = ifelse(struct$hasMS2, 100, 0), color = "red",
- "The object has MS2 data"
- )
- )})
-
- PLresults <- PLServer("PL_UI", struct = struct)
- observeEvent(PLresults$trigger, {
- struct$dataset <- PLresults$dataset
- }, ignoreNULL = TRUE, ignoreInit = TRUE)
-
- SOIresults <- SOIServer("SOI_UI", struct = struct)
- observeEvent(SOIresults$trigger, {
- struct$dataset <- SOIresults$dataset
- }, ignoreNULL = TRUE, ignoreInit = TRUE)
-
- ILresults <- ILServer("IL_UI", struct = struct)
- observeEvent(ILresults$trigger, {
- struct$dataset <- ILresults$dataset
- }, ignoreNULL = TRUE, ignoreInit = TRUE)
-
- MS2results <- MS2Server("MS2_UI", struct)
- observeEvent(MS2results$trigger, {
- struct$dataset <- MS2results$dataset
- }, ignoreNULL = TRUE, ignoreInit = TRUE)
-
- IOresults <- IOServer("IO_UI", struct = struct)
- observeEvent(IOresults$trigger, {
- struct$dataset <- IOresults$dataset
- }, ignoreNULL = TRUE, ignoreInit = TRUE)
-
- PLPlotServer("PLPlotUI", struct = struct)
- SOIPlotServer("SOIPlotUI", struct = struct)
- MS2PlotServer("MS2PlotUI", struct = struct)
- IdentServer("Identifications", struct = struct)
- ExtraInfoServer("ExtraInfo_UI", struct = struct)
-
- setResults <- SettingsServer("Settings_UI", struct = struct)
- observeEvent(setResults$trigger, {
- struct$dataset <- setResults$dataset
- }, ignoreNULL = TRUE, ignoreInit = TRUE)
-
- observeEvent(input$shutdown, {shiny::stopApp()})
-}
-
-shinyApp(ui, server)
+for(i in list.files(system.file("app", package = "RHermes"), pattern = "UI",
+ full.names = TRUE)){
+ source(i, local = TRUE)
+}
+
+library(shiny)
+library(shinyFiles)
+library(shinydashboard)
+library(shinyWidgets)
+library(RHermes)
+library(data.table, quietly = TRUE)
+library(enviPat)
+library(igraph)
+library(mzR)
+library(magrittr)
+library(CHNOSZ)
+library(ggplot2)
+library(plotly)
+library(visNetwork)
+library(KEGGREST)
+library(slickR)
+library(DT)
+
+header <- dashboardHeader(
+ title = p("RHermes", style = "font-family: Open Sans, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Arial; font-size: 22px"),
+ dropdownMenuOutput(outputId = "dropdown_m")
+ )
+
+sidebar <- dashboardSidebar(
+ sidebarMenu(
+ menuItem("Intro", tabName = "intro", icon = icon("info")),
+ menuItem("From mzML to PL", tabName = "mz2PL", icon = icon("bolt")),
+ menuItem("SOI detection", tabName = "SOIdet", icon = icon("barcode")),
+ menuItem("Inclusion list generation", tabName = "IL", icon = icon("list")),
+ menuItem("MSMS data processing", tabName = "MSMS", icon = icon("atom")),
+ menuItem("Identifications", tabName = "ident", icon = icon("fingerprint")),
+ menuItem("Plots", tabName = "Plots", icon = icon("chart-bar"),
+ menuSubItem("PL Exploration", tabName = "PLplot"),
+ menuSubItem("SOI Exploration", tabName = "SOIplot"),
+ menuSubItem("MS2 Exploration", tabName = "MS2plot")
+ ),
+ menuItem("Tables", tabName = "extra", icon = icon("table")),
+ menuItem("Loading/Saving", tabName = "IO", icon = icon("save")),
+ div(actionButton("shutdown", label="Shutdown app", icon = icon("power-off"),
+ style ="background-color: #222d32; color: #b8c7ce; border-color: #b8c7ce; border-width:1px"),
+ style = "margin-top:100%; width: 220px; display: inline-grid; position:fixed; bottom:0")
+ )
+)
+
+body <- dashboardBody(
+ tags$head(tags$link(rel="stylesheet", href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.0.0/animate.min.css")), ##Adds animate.css animations
+ tags$script(HTML("$('body').addClass('fixed');")),
+ includeCSS("./www/customStyle.css"),
+ tabItems(
+ # First tab content
+ tabItem(tabName = "intro",
+ titlePanel(
+ div(class="animate__animated animate__pulse", h1(tags$b("RHermes"), align = "center"), style = "text-align: center;")),
+ mainPanel(width = 20,
+ HTML("RHermes is a broad-scoped targeted metabolomics software designed to identify compounds in biological and environmental samples.
+ We invert the classical peak-first metabolite detection workflows by first annotating the LC-MS1 raw data points themselves
+ using a database of plasusible formulas and adducts. This ultimately results in a very sample-specific inclusion list of ions to monitor in a MS2 experiment
+ RHermes has shown that up to 90% of a typical data-dependent acquisition (DDA) MS2 experiment is wasted in redundant and non-biological ions, leading to fake positive
+ identifications while missing the true compounds in the sample.
"),
+ HTML(" We believe there's a better way to characterize the metabolites in our samples
- RHermes
"),
+ HTML("You can find the molecular formula databases and sample mzML files in the paper in our Zenodo dataset
"),
+ hr(),
+ HTML("The Workflow
"),
+ br(),
+ tags$script(src = 'scroll.js'),
+ HTML("
"),
+ img(src = "step1.svg", width = "100%", class = "steps"),
+ HTML("
"),
+ img(src = "step2.svg", width = "100%", class = "steps"),
+ HTML("
"),
+ img(src = "step3.svg", width = "100%", class = "steps"),
+ hr(),
+ h2("Bug reports"),
+ HTML("In case you find any abnormal behaviour (eg: app unexpectedly crashes, etc.) feel free to email
+ the mantainer at roger.gine@estudiants.urv or open a Github issue.
+ You should provide a detailed description about what happened, screenshots of the error and, desirably, a minimally reproducible example
"),
+ h2("Citation"),
+ HTML("Please cite this software as:
"),
+ HTML(" HERMES: a molecular formula-oriented method to target the metabolome
+ Roger Giné, Jordi Capellades, Josep M. Badia, Dennis Vughs, Michaela Schwaiger-Haber, Maria Vinaixa, Andrea M. Brunner, Gary J. Patti, Oscar Yanes
+ bioRxiv 2021.03.08.434466; doi: https://doi.org/10.1101/2021.03.08.434466
"),
+ style = "padding : 20px 50px 50px 50px")
+ ),
+
+ tabItem(tabName = "mz2PL", PL_UI("PL_UI")),
+ tabItem(tabName = "SOIdet", SOI_UI("SOI_UI")),
+ tabItem(tabName = "IL", IL_UI("IL_UI")),
+ tabItem(tabName = "MSMS", MS2_UI("MS2_UI")),
+ tabItem(tabName = "Plots", verticalLayout()),
+ tabItem(tabName = "PLplot", PLPlotUI("PLPlotUI")),
+ tabItem(tabName = "SOIplot", SOIPlotUI("SOIPlotUI")),
+ tabItem(tabName = "MS2plot", MS2PlotUI("MS2PlotUI")),
+ tabItem(tabName = "ident", Ident_UI("Identifications")),
+ tabItem(tabName = "extra", ExtraInfo_UI("ExtraInfo_UI")),
+ tabItem(tabName = "IO", IO_UI("IO_UI"))
+ )
+)
+
+ui <- dashboardPage(header, sidebar, body, title = "RHermes")
+
+server <- function(input, output, session){
+
+ struct <- reactiveValues(dataset=RHermesExp(), hasPL = FALSE, hasSOI = FALSE,
+ hasIL = FALSE, hasMS2 = FALSE)
+
+ observe({
+ struct$hasPL <- ifelse(length(struct$dataset@data@PL)!=0, TRUE, FALSE)
+ struct$hasSOI <- ifelse(length(struct$dataset@data@SOI)!=0, TRUE, FALSE)
+ struct$hasIL <- ifelse(length(struct$dataset@data@MS2Exp)!=0, TRUE, FALSE)
+ if(struct$hasIL){
+ struct$hasMS2 <- any(vapply(struct$dataset@data@MS2Exp, function(x){
+ length(x@Ident)!=0
+ }, logical(1))) }
+ })
+
+ output$dropdown_m <- renderMenu({
+ dropdownMenu(type = "tasks", badgeStatus = "primary",
+ taskItem(value = ifelse(struct$hasPL, 100, 0), color = "green",
+ "The object has PL/s"
+ ),
+ taskItem(value = ifelse(struct$hasSOI, 100, 0), color = "aqua",
+ "The object has SOI list/s"
+ ),
+ taskItem(value = ifelse(struct$hasIL, 100, 0),color = "yellow",
+ "The object has IL/s"
+ ),
+ taskItem(value = ifelse(struct$hasMS2, 100, 0), color = "red",
+ "The object has MS2 data"
+ )
+ )})
+
+ PLresults <- PLServer("PL_UI", struct = struct)
+ observeEvent(PLresults$trigger, {
+ struct$dataset <- PLresults$dataset
+ }, ignoreNULL = TRUE, ignoreInit = TRUE)
+
+ SOIresults <- SOIServer("SOI_UI", struct = struct)
+ observeEvent(SOIresults$trigger, {
+ struct$dataset <- SOIresults$dataset
+ }, ignoreNULL = TRUE, ignoreInit = TRUE)
+
+ ILresults <- ILServer("IL_UI", struct = struct)
+ observeEvent(ILresults$trigger, {
+ struct$dataset <- ILresults$dataset
+ }, ignoreNULL = TRUE, ignoreInit = TRUE)
+
+ MS2results <- MS2Server("MS2_UI", struct)
+ observeEvent(MS2results$trigger, {
+ struct$dataset <- MS2results$dataset
+ }, ignoreNULL = TRUE, ignoreInit = TRUE)
+
+ IOresults <- IOServer("IO_UI", struct = struct)
+ observeEvent(IOresults$trigger, {
+ struct$dataset <- IOresults$dataset
+ }, ignoreNULL = TRUE, ignoreInit = TRUE)
+
+ PLPlotServer("PLPlotUI", struct = struct)
+ SOIPlotServer("SOIPlotUI", struct = struct)
+ MS2PlotServer("MS2PlotUI", struct = struct)
+ IdentServer("Identifications", struct = struct)
+ ExtraInfoServer("ExtraInfo_UI", struct = struct)
+
+ observeEvent(input$shutdown, {shiny::stopApp()})
+}
+
+shinyApp(ui, server)
diff --git a/inst/extdata/ImprovedModel.h5 b/inst/extdata/ImprovedModel.h5
deleted file mode 100644
index 15896a3..0000000
Binary files a/inst/extdata/ImprovedModel.h5 and /dev/null differ
diff --git a/inst/extdata/exampleObject.rds b/inst/extdata/exampleObject.rds
index 911ae98..4a0e805 100644
Binary files a/inst/extdata/exampleObject.rds and b/inst/extdata/exampleObject.rds differ
diff --git a/man/exportIL.Rd b/man/exportIL.Rd
index d1fb3f2..d0cc9ff 100644
--- a/man/exportIL.Rd
+++ b/man/exportIL.Rd
@@ -12,7 +12,7 @@ exportIL(
mode = "both",
maxOver = 5,
defaultIT = 100,
- sepFiles = FALSE,
+ sepFiles = TRUE,
maxInjections = 9999
)
@@ -23,7 +23,7 @@ exportIL(
mode = "both",
maxOver = 5,
defaultIT = 100,
- sepFiles = FALSE,
+ sepFiles = TRUE,
maxInjections = 9999
)
}
@@ -53,8 +53,7 @@ aplicable in Orbitrap instruments and for "continuous" and "both" modes).
Defaults to 100ms.}
\item{sepFiles}{Logical, whether to generate a single csv file or multiple
-csvs, each corresponding to each injection/chromatographic run. From our
-experience with an Orbitrap Fusion, separate csvs will simplify the task.}
+csvs, each corresponding to each injection/chromatographic run.}
\item{maxInjections}{Numeric, the maximum number of planned injections to
export. Defaults to 9999 to export all of them.}
diff --git a/man/exportmzML.Rd b/man/exportmzML.Rd
index adec979..1102933 100644
--- a/man/exportmzML.Rd
+++ b/man/exportmzML.Rd
@@ -4,7 +4,7 @@
\alias{exportmzML}
\title{exportmzML}
\usage{
-exportmzML(struct, id, fname, whichSpec = NA)
+exportmzML(struct, id, fname, whichSpec = NA, collisionEnergy = 35)
}
\arguments{
\item{struct}{RHermesExp object}
@@ -14,6 +14,9 @@ exportmzML(struct, id, fname, whichSpec = NA)
\item{fname}{Name of the output file, without the .mzML termination}
\item{whichSpec}{Which entries to export. Defaults to all of them.}
+
+\item{collisionEnergy}{Numeric. Desired collision energy (in %NCE, eV, or any
+other unit)}
}
\value{
An .mzML file
diff --git a/man/getSOIpar.Rd b/man/getSOIpar.Rd
index 6f520d8..1f57b32 100644
--- a/man/getSOIpar.Rd
+++ b/man/getSOIpar.Rd
@@ -5,9 +5,9 @@
\alias{getSOIpar,ANY-method}
\title{getSOIpar}
\usage{
-getSOIpar(tag = "double")
+getSOIpar(tag = "double", mode = "regular", cwp = NA)
-\S4method{getSOIpar}{ANY}(tag = "double")
+\S4method{getSOIpar}{ANY}(tag = "double", mode = "regular", cwp = NA)
}
\arguments{
\item{tag}{A character string that tells which premade SOI parameter
@@ -17,6 +17,12 @@ chromatography experiments, 'single-x', 'double-x' and 'triple-x'.
These are all stored in /app/www/SOIFilterParams.csv, feel free to
locally change them or add new ones for your use (if you know what
you're doing).}
+
+\item{mode}{Whether SOI detection should use the regular density-based
+algorithm or xcms peak detection for defining the SOIs}
+
+\item{cwp}{A CentWaveParam object used for either SOI detection (xcms mode)
+or long SOI splitting (regular mode)}
}
\value{
A SoiParam object
diff --git a/man/plotFidelity.Rd b/man/plotFidelity.Rd
index 434a909..d35ae5d 100644
--- a/man/plotFidelity.Rd
+++ b/man/plotFidelity.Rd
@@ -33,7 +33,7 @@ Plots the selected SOI isotopic profile and a
\examples{
\dontshow{struct <- readRDS(system.file("extdata", "exampleObject.rds",
package = "RHermes"))}
-p <- plotFidelity(struct, 1, 9)
+p <- plotFidelity(struct, 1, 8)
}
\seealso{
Other plots:
diff --git a/man/setCluster.Rd b/man/setCluster.Rd
deleted file mode 100644
index 1576276..0000000
--- a/man/setCluster.Rd
+++ /dev/null
@@ -1,22 +0,0 @@
-% Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/Classes.R
-\name{setCluster}
-\alias{setCluster}
-\title{setCluster}
-\usage{
-setCluster()
-}
-\value{
-A BiocParallel backend
-}
-\description{
-Returns the most appropriate BiocParallel backend for RHermes
- according to your OS and RAM. It is entirely optional, but recommended
- nonetheless.
-}
-\examples{
-BiocParallel::register(setCluster()) #Registers the most appropriate backend
-}
-\author{
-Roger Gine
-}
diff --git a/tests/testthat/test-Methods.R b/tests/testthat/test-Methods.R
index 09182eb..f5e6472 100644
--- a/tests/testthat/test-Methods.R
+++ b/tests/testthat/test-Methods.R
@@ -18,7 +18,7 @@ test_that("RHermesExp methods work", {
toadd = "Cs")
expect_warning(addAd(myHermes, "M+Cs", deltam = 132.905, ch = 0, mult = 1,
toadd = "Cs"))
- remAd(myHermes, "M-H")
+ remAd(myHermes, "[M-H]-")
expect_warning(remAd(myHermes, "M+2Rb"))
})
diff --git a/tests/testthat/test-PL.R b/tests/testthat/test-PL.R
index 7fc34bd..96a0943 100644
--- a/tests/testthat/test-PL.R
+++ b/tests/testthat/test-PL.R
@@ -1,61 +1,59 @@
-context("Peaklist generation works fine")
-
-test_that("Raw data can be loaded",{
- ms1data <- RHermes:::import_and_filter(lf = system.file("extdata",
- "MS1TestData.mzML",
- package = "RHermes"))
- expect_length(ms1data, 3)
- expect_equal(nrow(ms1data[[1]]), 40040)
-})
-
-test_that("ScanSearch works",{
- BiocParallel::register(BiocParallel::SerialParam())
- myHermes <- readRDS(system.file("extdata",
- "exampleObject.rds",
- package = "RHermes"))
- myHermes <- processMS1(myHermes, system.file("extdata",
- "MS1TestData.mzML",
- package = "RHermes"))
- #Same result as precalculated version
- expect_equal(nrow(myHermes@data@PL[[2]]@peaklist),
- nrow(myHermes@data@PL[[1]]@peaklist))
-})
-
-test_that("Labelled proc works",{
- BiocParallel::register(BiocParallel::SerialParam())
- myHermes <- readRDS(system.file("extdata",
- "exampleObject.rds",
- package = "RHermes"))
- myHermes <- processMS1(myHermes,
- system.file("extdata",
- "MS1TestData.mzML",
- package = "RHermes"),
- labelled = TRUE)
-
- expect_equal(nrow(myHermes@data@PL[[2]]@peaklist), 1378)
-})
-
-test_that("PL plot works", {
- myHermes <- readRDS(system.file("extdata",
- "exampleObject.rds",
- package = "RHermes"))
-
- p <- RHermes::plotPL(myHermes, 1, "C3H7NO2", rtrange = c(0,1500),
- dynamicaxis = TRUE, ads = NA)
- expect_true(is(p, "plotly"))
-})
-
-
-test_that("Coverage plot works", {
- myHermes <- readRDS(system.file("extdata",
- "exampleObject.rds",
- package = "RHermes"))
- myHermes <- processMS1(myHermes,
- system.file("extdata",
- "MS1TestData.mzML",
- package = "RHermes"),
- labelled = TRUE)
- p <- RHermes:::plotCoverage(myHermes, 2)
- expect_true(is(p[[1]], "plotly") & is(p[[2]], "plotly"))
-})
-
+context("Peaklist generation works fine")
+
+test_that("Raw data can be loaded",{
+ ms1data <- RHermes:::import_and_filter(lf = system.file("extdata",
+ "MS1TestData.mzML",
+ package = "RHermes"))
+ expect_length(ms1data, 3)
+ expect_equal(nrow(ms1data[[1]]), 40040)
+})
+
+test_that("ScanSearch works",{
+ myHermes <- readRDS(system.file("extdata",
+ "exampleObject.rds",
+ package = "RHermes"))
+ myHermes <- processMS1(myHermes, system.file("extdata",
+ "MS1TestData.mzML",
+ package = "RHermes"))
+ #Same result as precalculated version
+ expect_equal(nrow(myHermes@data@PL[[2]]@peaklist),
+ nrow(myHermes@data@PL[[1]]@peaklist))
+})
+
+test_that("Labelled proc works",{
+ myHermes <- readRDS(system.file("extdata",
+ "exampleObject.rds",
+ package = "RHermes"))
+ myHermes <- processMS1(myHermes,
+ system.file("extdata",
+ "MS1TestData.mzML",
+ package = "RHermes"),
+ labelled = TRUE)
+
+ expect_equal(nrow(myHermes@data@PL[[2]]@peaklist), 1378)
+})
+
+test_that("PL plot works", {
+ myHermes <- readRDS(system.file("extdata",
+ "exampleObject.rds",
+ package = "RHermes"))
+
+ p <- RHermes::plotPL(myHermes, 1, "C3H7NO2", rtrange = c(0,1500),
+ dynamicaxis = TRUE, ads = NA)
+ expect_true(is(p, "plotly"))
+})
+
+
+test_that("Coverage plot works", {
+ myHermes <- readRDS(system.file("extdata",
+ "exampleObject.rds",
+ package = "RHermes"))
+ myHermes <- processMS1(myHermes,
+ system.file("extdata",
+ "MS1TestData.mzML",
+ package = "RHermes"),
+ labelled = TRUE)
+ p <- RHermes:::plotCoverage(myHermes, 2)
+ expect_true(is(p[[1]], "plotly") & is(p[[2]], "plotly"))
+})
+
diff --git a/tests/testthat/test-SOI.R b/tests/testthat/test-SOI.R
index 551e553..7b4e554 100644
--- a/tests/testthat/test-SOI.R
+++ b/tests/testthat/test-SOI.R
@@ -8,7 +8,6 @@ test_that("A SOI param class can be created",{
})
test_that("SOI generation works",{
- BiocParallel::register(BiocParallel::SerialParam())
myHermes <- readRDS(system.file("extdata",
"exampleObject.rds",
package = "RHermes"))
@@ -16,31 +15,13 @@ test_that("SOI generation works",{
expect_equal(nrow(myHermes@data@SOI[[2]]@SOIList), 11)
})
-test_that("Blank substraction is configured and works",{
- #Skip on bioconductor because this part requires that the user previously
- #configures Keras and Tensorflow.
- skip_on_bioc()
- library(reticulate)
- library(keras)
+test_that("Blank substraction is configured and works", {
library(data.table)
-
- #Has Python, Keras and Tensorflow
- skip_if(!py_available(initialize = TRUE))
- expect(py_module_available("keras"), failure_message = "No Keras")
- expect(py_module_available("tensorflow"), failure_message = "No TensorFlow")
-
- #Can load the model
- model <- load_model_hdf5(system.file("extdata",
- "ImprovedModel.h5",
- package = "RHermes"))
- expect(is(model, "python.builtin.object"),
- failure_message = "Model doesn't load")
-
set.seed(1234)
#Does the model work as intended?
blank <- data.table(rt = seq(0,20,0.2),
rtiv = rnorm(101, 10, 3),
- formv = "foo", isov = "M0")
+ formv = "foo", isov = "M0", mz = 100)
setkeyv(blank, "formv")
group <- dplyr::tibble(start = c(0,10), end = c(10,20),
peaks = list(
@@ -59,16 +40,6 @@ test_that("Blank substraction is configured and works",{
expect_false(RHermes:::firstCleaning(1, group, blank)) #Blank-like
expect_true(RHermes:::firstCleaning(2, group, blank)) #Totally different
- #Check that the interpolation works and the network generates the right
- #result (0, meaning sample and blank are the "same")
- organizeddata <- RHermes:::prepareNetInput(1, group, blank)
- organizeddata <- c(organizeddata[1, ], organizeddata[2, ])
- organizeddata <- rbind(organizeddata,organizeddata,organizeddata)
- organizeddata <- keras::array_reshape(organizeddata,
- c(nrow(organizeddata), 400),
- order = "C") #ANN input
- q <- model %>% predict(organizeddata) %>% k_argmax()
- expect_true(all(q$numpy() == 0))
})
test_that("SOI plot works", {
diff --git a/tests/testthat/test-prePL.R b/tests/testthat/test-prePL.R
index 72d696b..340a2ce 100644
--- a/tests/testthat/test-prePL.R
+++ b/tests/testthat/test-prePL.R
@@ -1,70 +1,64 @@
-context("Formula and adduct table functionality")
-test_that("Database importer works", {
- hmdb <- RHermes:::database_importer(template = "hmdb")
- expect_equal(nrow(hmdb), 59)
-
- norman <- RHermes:::database_importer(template = "norman")
- expect_equal(nrow(norman), 106)
-
- custom <- RHermes:::database_importer(
- template = "custom", filename = system.file("extdata", "hmdb.csv",
- package = "RHermes"))
- expect_equal(nrow(custom), 59)
-
- custom2 <- RHermes:::database_importer(
- template = "custom", filename = system.file("extdata", "norman.xlsx",
- package = "RHermes"))
- expect_equal(nrow(custom2), 106)
-
- skip_if_offline()
- kegg <- RHermes:::database_importer(template = "kegg_p",
- keggpath = "hsa00010")
- expect_equal(nrow(kegg), 24)
-})
-
-test_that("Adduct tables generate successfully",{
- ad <- RHermes:::adductTables(1,1)
- expect_equal(nrow(ad[[1]]), 10)
- expect_equal(nrow(ad[[2]]), 14)
- expect_equal(ad[[2]][1,"adduct"], "M+H")
-})
-
-
-context("Ionic formulas")
-test_that("Ionic formulas generate correctly", {
- BiocParallel::register(BiocParallel::SerialParam())
- hmdb <- RHermes:::database_importer(template = "hmdb")
- ad <- RHermes:::adductTables(1,1)
- colnames(hmdb)[c(2,3)] <- c("m","fms")
- ionf <- RHermes:::IonicForm(hmdb[1:5,], ad[[2]])
- expect_length(ionf, 2)
- expect_equal(nrow(ionf[[1]]), 70)
-})
-
-
-context("Isotopic distribution calculation")
-test_that("Isotopes generate nicely", {
- BiocParallel::register(BiocParallel::SerialParam())
- ppm <- 2
- minmass <- 80
- maxmass <- 1050
- noiselevel <- 1e3
- FWHM <- 120000
- ion <- "+"
- par <- ExpParam(ppm = ppm, res = FWHM, nthr = noiselevel,
- minmz = minmass, maxmz = maxmass, ion = ion)
- hmdb <- RHermes:::database_importer(template = "hmdb", minmass = 50,
- maxmass = 100)
- ad <- RHermes:::adductTables(1,1)
- colnames(hmdb)[c(2,3)] <- c("m","fms")
- test <- RHermes:::IonicForm(hmdb[1:5,], ad[[2]][1:5, ])
- IC <- RHermes:::IsoCalc(test[[1]], FWHM = par@res, intTHR = 0.2, kTHR = 1)
- expect_length(IC, 2)
- expect_length(IC[[1]], 25)
- expect_equal(nrow(IC[[2]]), 5)
-})
-
-context("Parallel backend selection")
-test_that("setCluster works", {
- RHermes:::setCluster()
-})
+context("Formula and adduct table functionality")
+test_that("Database importer works", {
+ hmdb <- RHermes:::database_importer(template = "hmdb")
+ expect_equal(nrow(hmdb), 59)
+
+ norman <- RHermes:::database_importer(template = "norman")
+ expect_equal(nrow(norman), 118)
+
+ custom <- RHermes:::database_importer(
+ template = "custom", filename = system.file("extdata", "hmdb.csv",
+ package = "RHermes"))
+ expect_equal(nrow(custom), 59)
+
+ custom2 <- RHermes:::database_importer(
+ template = "custom", filename = system.file("extdata", "norman.xlsx",
+ package = "RHermes"))
+ expect_equal(nrow(custom2), 118)
+
+ skip_if_offline()
+ kegg <- RHermes:::database_importer(template = "kegg_p",
+ keggpath = "hsa00010")
+ expect_equal(nrow(kegg), 26)
+})
+
+test_that("Adduct tables generate successfully",{
+ ad <- RHermes:::adductTables(1,1)
+ expect_equal(nrow(ad[[1]]), 11)
+ expect_equal(nrow(ad[[2]]), 21)
+ expect_equal(ad[[2]][1,"adduct"], "[M+H]+")
+})
+
+
+context("Ionic formulas")
+test_that("Ionic formulas generate correctly", {
+ hmdb <- RHermes:::database_importer(template = "hmdb")
+ ad <- RHermes:::adductTables(1,1)
+ colnames(hmdb)[c(2,3)] <- c("m","fms")
+ ionf <- RHermes:::IonicForm(hmdb[1:5,], ad[[2]][1:5,])
+ expect_length(ionf, 2)
+ expect_equal(nrow(ionf[[1]]), 24)
+})
+
+
+context("Isotopic distribution calculation")
+test_that("Isotopes generate nicely", {
+ ppm <- 2
+ minmass <- 80
+ maxmass <- 1050
+ noiselevel <- 1e3
+ FWHM <- 120000
+ ion <- "+"
+ par <- ExpParam(ppm = ppm, res = FWHM, nthr = noiselevel,
+ minmz = minmass, maxmz = maxmass, ion = ion)
+ hmdb <- RHermes:::database_importer(template = "hmdb", minmass = 50,
+ maxmass = 100)
+ ad <- RHermes:::adductTables(1,1)
+ colnames(hmdb)[c(2,3)] <- c("m","fms")
+ test <- RHermes:::IonicForm(hmdb[1:5,], ad[[2]][1:5, ])
+ IC <- RHermes:::IsoCalc(test[[1]], FWHM = par@res, intTHR = 0.2, kTHR = 1)
+ expect_length(IC, 2)
+ expect_length(IC[[1]], 24)
+ expect_equal(nrow(IC[[2]]), 6)
+})
+
diff --git a/vignettes/RHermes_UserGuide.Rmd b/vignettes/RHermes_UserGuide.Rmd
index e787108..076f0c0 100644
--- a/vignettes/RHermes_UserGuide.Rmd
+++ b/vignettes/RHermes_UserGuide.Rmd
@@ -14,7 +14,6 @@ vignette: |
---
```{r setup, include=FALSE}
-BiocParallel::register(BiocParallel::SerialParam())
knitr::opts_chunk$set(echo = TRUE, warning=FALSE, message = FALSE)
knitr::opts_chunk$set(collapse = TRUE)
library(plotly)
@@ -28,11 +27,6 @@ This document will guide you through the package functions and show you what a
typical RHermes workflow looks like.
## Installation
-The recommended specs for RHermes are:
-
- - At least a 4 core processor
- - 16 GB of RAM or more
- - An internet connection to perform KEGG queries
You can download the development version from
[GitHub](https://github.com/RogerGinBer/RHermes) with:
@@ -45,6 +39,7 @@ devtools::install_github("RogerGinBer/RHermes")
## MS1 workflow
### Setting up the RHermesExp object
+
All the information generated by RHermes is stored in a single
RHermesExp object.
To generate it, start with:
@@ -99,7 +94,7 @@ multiplicity <= 2 (for instance [2M+H]+, [M+2H]2+ and so on).
You may also just select a subset of adducts using with `adlist` param:
```{r}
myHermes <- setDB(myHermes, db = "hmdb", admult = 2, adcharge = 2,
- adlist = c("M+H", "M+Na", "M+K", "M+2H", "2M+H"))
+ adlist = c("[M+H]+", "[M+Na]+", "[M+K]+", "[M+NH4]+", "[2M+H]+"))
```
@@ -112,16 +107,18 @@ new adduct profiles with addAd() and remove them with remAd():
```{r}
#We will manually add the "M+2H" adduct
-myHermes <- addAd(myHermes, name = "M+2H", deltam = 2*1.00727600, ch = 2,
+myHermes <- addAd(myHermes, name = "[M+2H]2+", deltam = 2*1.00727600, ch = 2,
mult = 1, toadd = "H2")
#For instance, remove adducts of unused solvents
myHermes <- remAd(myHermes, c("M+DMSO+H", "M+IsoProp+H"))
```
+
```{r eval=FALSE}
adlist(myHermes)
```
+
```{r echo=FALSE}
knitr::kable(adlist(myHermes))
```
@@ -324,21 +321,6 @@ RHermesGUI()
```
And the app should start in your default browser.
-## Advanced functionality
-### Parallelization
-Another parameter you want to set up (especially if you're dealing with
-many formulas and adducts - say >10K formulas) is a custom parallel
-backend.
-
-RHermes functions use your default backend (bpparam()), but you can set any
-backend you like with register(). You can use setCluster to automatically
-select an appropiate backend based on your OS and RAM.
-
-```{r}
-BiocParallel::register(setCluster())
-```
-
-
## Session Info
```{r}