问小白 wenxiaobai
资讯
历史
科技
环境与自然
成长
游戏
财经
文学与艺术
美食
健康
家居
文化
情感
汽车
三农
军事
旅行
运动
教育
生活
星座命理

R语言:KEGG富集、可视化教程,附代码

创作时间:
作者:
@小白创作中心

R语言:KEGG富集、可视化教程,附代码

引用
1
来源
1.
https://www.cnblogs.com/wuzhixiake/p/18248138

KEGG(Kyoto Encyclopedia of Genes and Genomes)富集分析是生物信息学中常用的一种功能富集分析方法,主要用于分析基因组学数据在代谢通路中的富集情况。本文将详细介绍如何使用R语言进行KEGG富集分析,并对结果进行可视化展示。

1. 安装所需包

首先需要安装一些必要的R包:

install.packages("colorspace")
install.packages("stringi")
source("https://bioconductor.org/biocLite.R")
biocLite("DOSE")
biocLite("clusterProfiler")
biocLite("pathview")

2. 加载所需包

安装完成后,加载这些包:

library("colorspace")
library("stringi")
library("DOSE")
library("clusterProfiler")
library("org.Hs.eg.db")
library("enrichplot")
library("ggplot2")

3. 设置工作路径并加载“clusterProfiler”包

setwd("C:\\Users\\31791\\Desktop\\KEGG")
library("clusterProfiler")

4. 导入id.txt文件

假设你已经有一个包含基因ID的id.txt文件,运行以下代码:

rt=read.table("id.txt",sep="\t",header=T,check.names=F)
rt=rt[is.na(rt[,"entrezID"])==F,]
geneFC=rt$logFC
gene=rt$entrezID
names(geneFC)=gene

5. 进行KEGG富集分析

kk <- enrichKEGG(gene = gene, organism = "hsa", pvalueCutoff =0.05, qvalueCutoff =0.05)
write.table(kk, file="KEGG.txt",sep="\t",quote=F,row.names = F)

6. 可视化绘制气泡图和柱状图

# 柱状图
tiff(file="barplot.tiff",width = 20, height = 20, units ="cm",compression="lzw",bg="white",res=600)
barplot(kk, drop = TRUE, showCategory = 20)
dev.off()

# 点图
tiff(file="dotplot.tiff",width = 20, height = 20, units ="cm",compression="lzw",bg="white",res=600)
dotplot(kk, showCategory = 20)
dev.off()

7. 通路图

利用pathview查阅代谢通路图并导出:

library("pathview")
keggxls=read.table("KEGG.txt",sep="\t",header=T)
for(i in keggxls$ID){
  pv.out <- pathview(gene.data = geneFC, pathway.id = i, species = "hsa", out.suffix = "pathview")
}

8. 结果展示

以下是部分可视化结果:


© 2023 北京元石科技有限公司 ◎ 京公网安备 11010802042949号