前往小程序,Get更优阅读体验!
立即前往
发布
社区首页 >专栏 >R语言shiny~实现简单的GO富集分析

R语言shiny~实现简单的GO富集分析

作者头像
用户7010445
发布2020-05-24 14:48:53
发布2020-05-24 14:48:53
1.9K00
代码可运行
举报
运行总次数:0
代码可运行

模仿的是 https://github.com/sk-sahu/sig-bio-shiny

基本功能是用户输入

  • gene id
  • pvalue
  • qvalue

然后分别把

  • BP
  • CC
  • MF

以表格输出,

  • 汇总结果下载(压缩文件)
  • go富集结果的dotplot
代码

代码中 cc和mf结果表格输出的逻辑没有写,和bp是完全一样的

代码语言:javascript
代码运行次数:0
复制
library(shiny)
ui<-navbarPage("Pomegranate",
               tabPanel("Gene Ontology",
                        sidebarLayout(sidebarPanel(width=2,
                                                   textAreaInput("text_area_list",
                                                                 label = "Please input protein id, one per line",
                                                                 height = "200px",
                                                                 width="180px",
                                                                 value="Pg00001\nPg00002"),
                                      selectInput("id_type",label = "Input gene-id Type",
                                                  selected = "ensembl",
                                                  choices = c('ensembl','refseq','entrezid')),
                                      helpText("Please"),
                                      numericInput('pval_cutoff',label="pvalue-Cutoff",
                                                   value = 1,min=0.001,max=1,step=0.001),
                                      numericInput("qval_cutoff",label="qvalue-Cutoff",
                                                   value=1,min=0.001,max=1,step=0.001),
                                      actionButton('submit',label = 'Submit',
                                                   icon=icon('angle-double-right')),
                                      tags$hr()),
                                      mainPanel(helpText("ABC"),
                                                downloadButton('download_plot',label = "Download results plot"),
                                                downloadButton('download_table',label="Download result table"),
                                                textOutput("gene_number_info"),
                                                tags$br(),
                                                tags$br(),
                                                tabsetPanel(
                                                  tabPanel("Biological Process",DT::dataTableOutput(outputId="table_go_bp")),
                                                  tabPanel("Cellular Component",DT::dataTableOutput(outputId = "table_go_cc")),
                                                  tabPanel("Molecular Functions",DT::dataTableOutput(outputId = 'table_go_mf')),
                                                  tabPanel("dotplot",plotOutput('dot_plot_go'))
                                                )))))
server<-function(input,output){
  observeEvent(input$submit,{
    withProgress(message = 'Steps:',value=0,{
      incProgress(1/7,detail = "A")
      text_area_input<-input$text_area_list
      print(text_area_input)
      df<-as.data.frame(matrix(unlist(stringr::str_split(text_area_input,"\n")),ncol=1))
      colnames(df)<-"protein_id"
      print(dim(df))
      input_gene_number<-dim(df)[1]
      output$gene_number_info<-renderText({
        paste("Done!","Total Number of Input genes:",input_gene_number,sep="\n")
      })
      incProgress(2/7,detail = "B")
      library(clusterProfiler)
      enrichGO_res<-enrichGO(gene=df$protein_id,
                             OrgDb = 'org.Hs.eg.db',
                             ont="all",
                             pvalueCutoff = input$pval_cutoff,
                             qvalueCutoff = input$qval_cutoff)
      go_enricher_res<-enrichGO_res@result
      go_bp<-go_enricher_res[go_enricher_res$ONTOLOGY == "BP",]
      output$table_go_bp<-DT::renderDataTable({
        go_bp
      })
      incProgress(3/7,detail="plot")
      output$dot_plot_go<-renderPlot({
        p1<-dotplot(enrichGO_res)
        print(p1)
      })
      incProgress(4/7,detail = "OK")
      go_plot_download<-reactive({
        dotplot(enrichGO_res)
      }
      )
      output$download_plot<-downloadHandler(
        filename = function(){
          paste("go_dot_plot.png",sep='')
        },
        content = function(file){
          ggplot2::ggsave(file,plot=go_plot_download(),device = 'png',width=12,height = 10)
        }
      )
      output$download_table<-downloadHandler(
        filename = function(){
          paste0("ABC.zip")
        },
        content = function(file){
          fs<-c('go_results.tsv')
          write.table(go_enricher_res,file="go_results.tsv",sep="\t",row.names = F)
          zip(zipfile = file,files=fs)
        },
        contentType = "application/zip"
      )
    })
  })
  }

shinyApp(ui,server)
界面是这样子的

image.png

用于做测试的 id (人)
代码语言:javascript
代码运行次数:0
复制
4312
8318
10874
55143
55388
991
6280
2305
9493
1062
3868
4605
9833
9133
6279
10403
8685
597
7153
23397
6278
79733
259266
1381
3627
27074
6241
55165
9787
7368
11065
55355
9582
220134
55872
51203
3669
83461
22974
10460
10563
4751
6373
8140
79019
820
10635
1844
4283
27299
结果

image.png

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2020-05-22,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 小明的数据分析笔记本 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 代码
  • 界面是这样子的
  • 用于做测试的 id (人)
  • 结果
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档