2020-02-08 根据DAVID结果做图GOterm分析

##根据DAVID结果做图GOterm分析,数据格式从DAVID中下载,先保存至txt,后用excel打开,再保存为CSV格式

x<-read.csv(file = "C:\\Users\\zhouwenqing789\\Desktop\\乳腺癌TCGA数据库20191226\\test\\GOTerm.csv",stringsAsFactor=F,header=T)

head(x)

x<-x[x$PValue<0.05,]

x_go<-x[,1:5]

xbp<-x_go[grep("BP",x_go$Category),]

xcc<-x_go[grep("CC",x_go$Category),]

xmf<-x_go[grep("MF",x_go$Category),]

xkegg<-x_go[grep("KEGG",x_go$Category),]

##通过正则表达式将Term格式整理一下

xbp$Term<-gsub(".*\\~","",xbp$Term)

xcc$Term<-gsub(".*\\~","",xcc$Term)

xmf$Term<-gsub(".*\\~","",xmf$Term)

xkegg$Term<-gsub(".*\\:","",xkegg$Term)

library(ggplot2)

make_GO_bubble<-function(go_data,term_name){

  #选择TOP10的数据(count)

  GO_DATA<-go_data[order(go_data$Count,decreasing = T),]

  GO_DATA<-head(GO_DATA,10)

  #思维数据的展示

  p<-ggplot(GO_DATA,aes(X.,Term))

  bubble<-p+geom_point(aes(size=Count,color=-log(PValue)))

  #自定义渐变颜色

  bubble<-bubble+scale_color_gradient(low = "green",high = "red")

  #改变图片的样式(主题)

  pr<-bubble+theme_test(base_size = 16,base_rect_size = 1)

  pr<-pr+labs(x="Rich factor",y=term_name,title = "Enrichment of DEGS")

  return(pr)

}

#BP

make_GO_bubble(xbp,term_name = "Biological Process")

make_GO_bubble(xcc,term_name = "Cell Component")

make_GO_bubble(xmf,term_name = "Molecular Function")

make_GO_bubble(xkegg,term_name = "KEGG pathway")

你可能感兴趣的:(2020-02-08 根据DAVID结果做图GOterm分析)