美文网首页功能注释生物信息学绘图技巧
GO/KEGG富集分析及R包绘图(气泡图/条形图)

GO/KEGG富集分析及R包绘图(气泡图/条形图)

作者: walnutoil | 来源:发表于2021-11-24 10:15 被阅读0次

    导读

    利用富集分析,我们可以把很多看着杂乱的差异基因总结出一个比较整体反应事件发生的概述性的句子。

    例如:TP53信号通路和胃癌的发生有关。而不是说BAX、BID、ABL1、ATM、BCL2、BOK、CDKN1A这7个基因和胃癌的发生有关系。


    TP53通路及其相关基因

    GO和KEGG就是基于不同的分类思想而储存的基因相关功能的数据库。

    GO数据库:全称是Gene Ontology(基因本体),他们把基因的功能分成了三个部分分别是:细胞组分(cellular component, CC)、分子功能(molecular function, MF)、生物过程(biological process, BP)。利用GO数据库,我们就可以得到我们的目标基因在CC, MF和BP三个层面上,主要和什么有关。

    KEGG数据库:除了对基因本身功能的注释,我们也知道基因会参与人体的各个通路,基于人体通路而形成的数据库就是通路相关的数据库。

    一、DAVID网站做富集分析

    DAVID官网:https://david.ncifcrf.gov/

    第一步:点击红框部分
    第二步:按要求上传DEGs
    第三步:勾选需要的富集分析结果
    第四步:下载结果

    二、整理数据

    DAVID富集分析结果可保存为.txt文件,然后用excel打开整理。

    富集分析结果

    其中%列代表 Gene ratio


    对结果进行排序

    经过排序筛选后,复制需要绘图的数据(你所关注的通路),粘贴至新建的KEGG.txt文件和GO.txt中并保存。

    三、ggplot包绘制KEGG气泡图

    #########################################
    ###        KEGG Pathway Plot         ### 
    ##           2021.11.17              ##
    ######################################
    
    library(dplyr)
    library(ggplot2)
    library(ggrepel)
    setwd("D:/Your/Working/Directory/")
    #载入数据
    KEGG_dataset <- read.table(file ="KEGG.txt",
                               header = TRUE, sep = "\t")
    
    #按照PValue从低到高排序[升序]
    KEGG_dataset <- arrange(KEGG_dataset,KEGG_dataset[,4])
    #Pathway列最好转化成因子型,否则作图时ggplot2会将所有Pathway按字母顺序重排序
    #将Pathway列转化为因子型
    KEGG_dataset$Term <- factor(KEGG_dataset$Term,levels = rev(KEGG_dataset$Term))
    
    #图片背景设定
    mytheme <- theme(axis.title=element_text(face="bold", size=14,colour = 'black'), #坐标轴标题
                     axis.text=element_text(face="bold", size=14,colour = 'black'), #坐标轴标签
                     axis.line = element_line(size=0.5, colour = 'black'), #轴线
                     panel.background = element_rect(color='black'), #绘图区边框
                     legend.key = element_blank() #关闭图例边框
    )
    
    #绘制KEGG气泡图
    p <- ggplot(KEGG_dataset,aes(x=Gene.ratio,y=Term,colour=-1*log10(PValue),size=Count))+
      geom_point()+
      scale_size(range=c(2, 8))+
      scale_colour_gradient(low = "blue",high = "red")+
      theme_bw()+
      ylab("KEGG Pathway Terms")+
      xlab("Gene Ratio")+
      labs(color=expression(-log[10](PValue)))+
      theme(legend.title=element_text(size=14), legend.text = element_text(size=14))+
      theme(axis.title.y = element_text(margin = margin(r = 50)),axis.title.x = element_text(margin = margin(t = 20)))+
      theme(axis.text.x = element_text(face ="bold",color="black",angle=0,vjust=1))
    plot <- p+mytheme
    plot
    #保存图片
    ggsave(plot,filename = "KEGG.pdf",width = 10,height = 6,dpi=300)
    ggsave(plot,filename = "KEGG.png",width = 10,height = 6,dpi=300)
    
    
    KEGG气泡图

    三、ggplot包绘制GO条形图

    #########################################
    ###        GO Pathway Plot           ### 
    ##           2021.11.24              ##
    ######################################
    
    setwd("D:/Your/Working/Directory/")
    getwd()
    
    dat = read.table("GO.txt",header = T,sep = "\t")
    library(ggplot2)#没有自己安装 install.package("ggplot2")
    p <- ggplot(dat,aes(y=Gene.ratio,x=Term,fill=PValue)) + 
          geom_bar(stat="identity",position = "dodge") +
          facet_grid(Category~.,scales = "free",space = "free") + 
          coord_flip() + 
          theme_bw() +
          theme(plot.title = element_text(hjust = 0.5),
                strip.text.y = element_text(size = 14),
                legend.position="right",
                legend.title = element_text(size=18),
                legend.text = element_text(size=14),
                axis.text.x = element_text(size=14),
                axis.text.y = element_text(size=18),
                axis.title.x = element_text(size=14),
                axis.title.y = element_text(size=14))
    p
    ggsave(p,filename = "GO.pdf",width = 10,height = 7,dpi=300)
    ggsave(p,filename = "GO.jpg",width = 10,height = 7,dpi=300)
    
    
    GO条形图

    相关文章

      网友评论

        本文标题:GO/KEGG富集分析及R包绘图(气泡图/条形图)

        本文链接:https://www.haomeiwen.com/subject/jtkntrtx.html