Last active
June 5, 2019 21:11
-
-
Save kozo2/4cab436b74a7ae60283cadf07bca6c79 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# This is a Shiny web application. You can run the application by clicking | |
# the 'Run App' button above. | |
# | |
# Find out more about building applications with Shiny here: | |
# | |
# http://shiny.rstudio.com/ | |
# | |
library(shiny) | |
library(MSEApdata) | |
data(kusano) | |
data(mset_SMPDB_format_KEGG) | |
ui = fluidPage( | |
titlePanel("MSEAp Shiny"), | |
sidebarLayout( | |
sidebarPanel( | |
#textAreaInput("caption", "Caption", paste(kusano, collapse = "\n"), width = "1000px", resize = "both"), | |
textAreaInput(inputId="caption", label="Put your metabolite IDs here", width="100%", height="400px", value=paste(kusano, collapse = "\n"), placeholder = "Placeholder"), | |
radioButtons("pathway", "Pathway Database:", | |
c("KEGG" = "kegg", | |
"SMPDB" = "smpdb")) | |
), | |
mainPanel( | |
tabsetPanel(type = "tabs", | |
tabPanel("ID Table", DT::dataTableOutput("value")), | |
tabPanel("MSEAp results", DT::dataTableOutput("mseatable"), plotOutput("plot"), plotOutput("plot2")) | |
) | |
) | |
) | |
) | |
server = function(input, output) { | |
library(BridgeDbR) | |
mapper <- loadDatabase("./metabolites_20190207.bridge") | |
observeEvent(input$caption, { | |
mids <- strsplit(input$caption, "\n") | |
kegg <- c() | |
cas <- c() | |
chebi <- c() | |
knapsack <- c() | |
hmdb <- c() | |
pubchem <- c() | |
for(mid in mids[[1]]){ | |
# CAS | |
tmp <- map(mapper, mid, source = "Ck", target = "Ca") | |
cas <- c(cas, paste(tmp, collapse = " ")) | |
# CHEBI | |
tmp <- map(mapper, mid, source = "Ck", target = "Ce") | |
tmp <- unique(gsub("CHEBI:", "", tmp)) | |
tmp <- paste0('<a href="https://www.ebi.ac.uk/chebi/searchId.do?chebiId=CHEBI:', tmp, '" target="_blank">', tmp, "</a>") | |
chebi <- c(chebi, paste(tmp, collapse = " ")) | |
# KNAPSACK | |
tmp <- map(mapper, mid, source = "Ck", target = "Cks") | |
tmp <- paste0('<a href="http://www.knapsackfamily.com/knapsack_jsp/information.jsp?sname=C_ID&word=', tmp, '" target="_blank">', tmp, "</a>") | |
knapsack <- c(knapsack, paste(tmp, collapse = " ")) | |
# HMDB | |
tmp <- map(mapper, mid, source = "Ck", target = "Ch") | |
tmp <- paste0('<a href="http://www.hmdb.ca/metabolites/', tmp, '" target="_blank">', tmp, "</a>") | |
hmdb <- c(hmdb, paste(tmp, collapse = " ")) | |
# PUBCHEM | |
tmp <- map(mapper, mid, source = "Ck", target = "Cpc") | |
tmp <- paste0('<a href="https://pubchem.ncbi.nlm.nih.gov/compound/', tmp, '" target="_blank">', tmp, "</a>") | |
pubchem <- c(pubchem, paste(tmp, collapse = " ")) | |
# KEGG | |
kegg <- c(kegg, paste0('<a href="https://www.genome.jp/dbget-bin/www_bget?cpd:', mid, '" target="_blank">', mid, "</a>")) | |
} | |
x <- data.frame("KEGG" = kegg, "CAS" = cas, "CHEBI" = chebi, "KNAPSACK" = knapsack, "HMDB" = hmdb, "PUBCHEM" = pubchem) | |
output$value <- DT::renderDataTable(x, escape=FALSE) | |
library(clusterProfiler) | |
library(tibble) | |
pathway <- character(0) | |
cids <- list() | |
for(i in 1:length(mset_SMPDB_format_KEGG)) { | |
row = mset_SMPDB_format_KEGG[[i]] | |
pathway <- c(pathway, row[[2]]) | |
cids[[i]] <- row[[3]] | |
} | |
tb <- tibble(pathway=pathway, cID=cids) | |
y <- enricher(kusano, pvalueCutoff=0.5, TERM2GENE=tb, minGSSize=1, qvalueCutoff = 0.5) | |
output$mseatable <- DT::renderDataTable({ | |
as.data.frame(y) | |
}) | |
output$plot <- renderPlot({ | |
dotplot(y) | |
}) | |
output$plot2 <- renderPlot({ | |
barplot(y) | |
}) | |
}) | |
} | |
# Run the application | |
shinyApp(ui = ui, server = server) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment