go和kegg通路富集分析
go和kegg通路富集分析视频教程
go和kegg富集分析函数构建
go_kegg_enrich
if(!dir.exists( save.dir)){
dir.create( save.dir,recursive=T) #如果save.dir路径不存在,就创建该路径
}
#keytypes( org.Hs.eg.db) #查看org.Hs.eg.db数据库中各种数据类型
#将gene_symbol转换成entrenzid
gene.trans
#head( gene.trans)
#1 GO分析
All
#head( All,1)
if( nrow( All)>0){
All1
#dim( All1)
all.go.file
all.go.file1
saveRDS(All,file=all.go.file1)
write.csv( All1,file=all.go.file)
#save(All,file = 'All.rda')
#All
#如果要单独绘制BP,CC,MF,把ont="ALL"修改成自己想要的类型即可
#top.number
for(top.number in show.top.number.list){
if( top.number
width=12/1.5
height=10/1.5
}else{
width=12*( top.number/20)
height=10*( top.number/20)
}
#2 画图,气泡图
#2.1 气泡图,显示前n项,标题为“Enrichment GO Up-Gene”
all.go.dotplot.pdf
all.go.dotplot.png
plot.title
p
#scale_color_gradient(low = "red", high = "blue")+
#theme_bw()
ggsave(all.go.dotplot.pdf,plot=p,width = width,height = height)
ggsave(all.go.dotplot.png,plot=p,width = width,height = height,dpi=300)
#2.2 柱状图,显示前20项,标题为“Enrichment GO Top20”
#save.dir
all.go.barplot.pdf
all.go.barplot.png
plot.title
p1
#scale_color_gradient(low = "red", high = "blue")+
#theme_bw()
ggsave(all.go.barplot.pdf,plot=p1,width = width,height = height)
ggsave(all.go.barplot.png,plot=p1,width = width,height = height,dpi=300)
# 2.3 BP,MF,CC分别分面显示(要加载DOSE包)
all.go.facet.dotplot.pdf
all.go.facet.dotplot.png
plot.title
p1
theme_bw()
p1
ggsave(all.go.facet.dotplot.pdf,p1,width = width,height = height)
ggsave(all.go.facet.dotplot.png,p1,width = width,height = height,dpi=300)
}
#三个单独出图
id
go.types
#go.type
for(go.type in go.types){
sub.go
if( nrow( sub.go)>0){
sub.go.file
write.csv(as.data.frame(sub.go),file=sub.go.file)
#write.csv(as.data.frame(sub.go),file="target_genes",go.type,"enrich_go_res.csv",sep=",")
for(top.number in show.top.number.list){
if( top.number
width=12/1.5
height=10/1.5
}else{
width=12*( top.number/20)
height=10*( top.number/20)
}
plot.title
p10
scale_color_gradient(low = "red", high = "blue")+
theme_bw()
sub.go.pdf
sub.go.png
ggsave(sub.go.pdf,p10,width = width,height = height)
ggsave(sub.go.png,p10,width = width,height = height,dpi=300)
}
}else{
print(paste0("No gene has been enriched in GO ",go.type," enrich analysis"))
}
}
}else{
print("No gene has been enriched in GO enrich analysis")
}
####kegg分析####
#1KEGG分析
id
KEGG
if(!is.null(KEGG)){
if( nrow( KEGG)>0){
#2 画图,第一种做法,气泡图,设置字体大小
#3 画图,第二种做法,柱状图
#4 画图,第三种做法,泡泡图
#dotplot(color="pvalue",KEGG,showCategory=10,title="Enrichment KEGG Top10")
kegg.res.file
write.csv(as.data.frame(KEGG),file=kegg.res.file)
all.kegg.file1
saveRDS( KEGG,file=all.kegg.file1)
#4.1 调节标题,字体,泡泡大小
for(top.number in show.top.number.list){
if( top.number
width=12/1.5
height=10/1.5
}else{
width=12*( top.number/20)
height=10*( top.number/20)
}
plot.title
p2
scale_color_gradient(low = "red", high = "blue")+
theme_bw()
kegg.dotplot.pdf
kegg.dotplot.png
ggsave(kegg.dotplot.pdf,p2,width = width,height = height)
ggsave(kegg.dotplot.png,p2,width = width,height = height,dpi=300)
}
}
}else{
print("No gene has been enriched in KEGG enrich analysis")
}
}
利用构建的go和Kegg函数进行通路富集分析
go.kegg.enrich.analysis=T
if(go.kegg.enrich.analysis){
diff.res.file
diff.res
gene.symbol.list
save.name.prefix
show.top.number.list
go_kegg_enrich(gene.symbol.list=gene.symbol.list,save.dir=data.dir,go.org=go.org,kegg.org=kegg.org,save.name.prefix=save.name.prefix,show.top.number.list)
}
领取专属 10元无门槛券
私享最新 技术干货