knitr::opts_chunk$set(echo = F)

Inputs

Data format

knitr::include_graphics('https://yufree.github.io/presentation/figure/demomzrt.png')

The uploaded file should be one csv file. The first column should be peak ID. The second column should be mass to charge ratio of peaks. The third column should be retention time in seconds. The other column should be peaks intensities in each samples. The header should be 'mz', 'rt', and sample names. The second row should include group information of each sample. Such file could be output by getcsv function for a 'mzrt' object from enviGCMS package. However, it's also easy to manually write one csv file as shown above. Here is the demo csv file.

Parameters

library(pmd)
inputPanel(
  fileInput('file',label = 'Upload csv file with m/z, retention time, peaklist and group info',accept = c('.csv')),
  sliderInput("rtcutoff", label = "Cutoff for retention time cluster analysis:",
              min = 1, max = 20, value = 9, step = 1),
  sliderInput("ng", label = "Cutoff of PMD (within RT cluster)'s retention time group numbers:",
              min = 5, max = 200, value = 10, step = 1),
  sliderInput("freqcutoff", label = "Cutoff of PMD (cross RT clusters) freqency  for structures or reactions:",
              min = 1, max = 200, value = 10, step = 1),
  checkboxInput("cor", label = 'Use intensity',value = F),
  sliderInput("corcutoff", label = "Cutoff for the correlation coefficient",
              min = 0, max = 1, value = 0.6, step = 0.1),
  sliderInput("digits", label = "Digits of mass to charge ratio",
              min = 1, max = 10, value = 2, step = 1),
  sliderInput("accuracy", label = "Measured mass or mass to charge ratio in digits",
              min = 1, max = 10, value = 4, step = 1)
)

Outputs

datainput <- reactive({
                if (!is.null(input$file)){
                        dataraw <- read.csv(input$file$datapath,skip = 1)
                        mz <- dataraw[,2]
                        rt <- dataraw[,3]
                        data <- dataraw[,-c(1:3)]
                        group <- data.frame(t(read.csv(input$file$datapath,nrows = 1)[-(1:3)]))
                        colnames(group) <- c(1:ncol(group))
                        colnames(data) <- rownames(group)
                        rownames(data) <- dataraw[,1]
                        return(list(data=data,mz=mz,rt=rt,group=group))
                }else{
                        return(NULL)
                }
        })
datastd <- reactive({
        list <- datainput()
        if(!is.null(list)){
          if(input$cor){
            list <- globalstd(list,input$rtcutoff,input$ng,digits=input$digits,accuracy = input$accuracy, freqcutoff=input$freqcutoff, corcutoff=input$corcutoff)
          }else{
            list <- globalstd(list,input$rtcutoff,input$ng,digits=input$digits,accuracy = input$accuracy, freqcutoff=input$freqcutoff, corcutoff=NULL)
          }

        }
        return(list)
})

stdcsv <- reactive({
        list <- datastd()
        data <- cbind(mz = list$mz[list$stdmassindex], rt = list$rt[list$stdmassindex], list$data[list$stdmassindex,])
        data <- t(cbind(group = t(cbind(mz = 'mz',rt = 'rt',t(list$group))), t(data)))
        return(data)
})

isocsv <- reactive({
        list <- datastd()

        return(list$iso)
})
ionscsv <- reactive({
        list <- datastd()

        return(list$multi)
})
sdacsv <- reactive({
        list <- datastd()

        return(list$sda)
})

Show the retention time groups

diffcsv <- reactive({
        list <- datastd()
        return(list$diff)
})
paircsv <- reactive({
        list <- datastd()

        return(list$paired)
})
renderPlot({
        list <- datastd()
        if(!is.null(list)){
                if(sum(list$pairedindex)>0){
                plotrtg(list)
                }else{
                plot(1,1,type = 'n')

        }
        }else{
                plot(1,1,type = 'n')

        }
})

Show the Global in-group PMDs distribution

renderPlot({
        list <- datastd()
        if(!is.null(list)){
                if(sum(list$pairedindex)>0){
                plotpaired(list) 
                }else{
                plot(1,1,type = 'n')

        }

        }else{
                plot(1,1,type = 'n')

        }
})

Show the paired mass distances table

renderDataTable({
  list <- datastd()
        if(!is.null(list)&sum(list$diffindex)>0){
          list$diff
          }
})
# show the download
downloadHandler('diff.csv', outputArgs = list(label="in-group peaks' PMDs"), content = function(file) {
                data <- diffcsv()
                write.csv(data, file)
        })

Show the high freqency paired mass distances table

renderDataTable({
  list <- datastd()
        if(!is.null(list)&sum(list$pairedindex)>0){
          list$paired
          }
})
# show the download
downloadHandler('paired.csv', outputArgs = list(label="High frequency in-group peaks' PMDs"), content = function(file) {
                data <- paircsv()
                write.csv(data, file)
        })

Show the isotope related in-group peaks' PMDs table

renderDataTable({
  list <- datastd()
        if(!is.null(list)&sum(list$isoindex)>0){
          list$iso
          }
})
# show the download
downloadHandler('iso.csv', outputArgs = list(label="Isotope related in-group peaks' PMDs"), content = function(file) {
                data <- isocsv()
                write.csv(data, file)
        })

Show the multiple charged ions related in-group peaks' PMDs table

renderDataTable({
  list <- datastd()
        if(!is.null(list)&sum(list$multiindex)>0){
          list$multi
          }
})
# show the download
downloadHandler('multi.csv', outputArgs = list(label="Multiple charged ions related in-group peaks' PMDs"), content = function(file) {
                data <- ionscsv()
                write.csv(data, file)
        })

Show the Global cross-group PMDs distribution

renderPlot({
        list <- datastd()
        if(!is.null(list)){
                if(sum(list$stdmassindex)>0){
                plotstdsda(list)
                }else{
                plot(1,1,type = 'n')

        }

        }else{
                plot(1,1,type = 'n')

        }
})

Structure/reaction directed analysis results table

renderDataTable({
  list <- datastd()
        if(!is.null(list)&sum(list$multiindex)>0){
          list$sda
          }
})
# show the download
downloadHandler('sda.csv', outputArgs = list(label="Structure/reaction directed analysis results"), content = function(file) {
                data <- sdacsv()
                write.csv(data, file)
        })

Show the globalstd peaks and all peaks

renderPlot({
        list <- datastd()
        if(!is.null(list)){
                if(sum(list$pairedindex)>0){
                plotstd(list)
                }else{
                plot(1,1,type = 'n')

        }

        }else{
                plot(1,1,type = 'n')

        }
})

Download GlobalStd peaks list

# show the download
downloadHandler('globalstd.csv', outputArgs = list(label='GlobalStd peaks'), content = function(file) {
                data <- stdcsv()
                write.csv(data, file)
        })


yufree/pmd documentation built on April 19, 2024, 9:31 a.m.