R语言shiny如何实现简单的GO富集分析
这篇文章主要介绍“R语言shiny如何实现简单的GO富集分析”,在日常操作中,相信很多人在R语言shiny如何实现简单的GO富集分析问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”R语言shiny如何实现简单的GO富集分析”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
模仿的是 https://github.com/sk-sahu/sig-bio-shiny
基本功能是用户输入
gene id pvalue qvalue
然后分别把
BP CC MF
以表格输出,
汇总结果下载(压缩文件) go富集结果的dotplot
代码中 cc和mf结果表格输出的逻辑没有写,和bp是完全一样的
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)
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
到此,关于“R语言shiny如何实现简单的GO富集分析”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注网站,小编会继续努力为大家带来更多实用的文章!