GO/KEGG富集分析(仅需基因列表)
发布时间
阅读量:
阅读量
输入文件:

#安装
BiocManager::install("org.Gg.eg.db") #鸡全基因组注释R包
BiocManager::install("clusterProfiler")
BiocManager::install("enrichplot")
install.packages("ggplot2")
#加载所需要的包
library("clusterProfiler")
library("org.Gg.eg.db")
library("enrichplot")
library("ggplot2")
#文件预处理
##输入文件
setwd("C:\ Users\ 64151\ Desktop\ GO")
inputFile="down_GO.txt"
rt=read.table(inputFile,sep="\t",check.names = F,header=F)
##获取基因列表
genes=as.vector(rt[,1])
##找基因对应的id
entrezIDs <- mget(genes, org.Gg.egSYMBOL2EG,ifnotfound = NA)
entrezIDs <- as.character(entrezIDs)
##输出基因+id文件
out=cbind(rt,entrezID=entrezIDs)
colnames(out)[1]="Gene"
write.table(out,file="id.txt",sep = "\t",quote= F,row.names = F)
R

输出文件:

##读取id.txt文件
rt=read.table("id.txt",sep="\t",header=T,check.names=F)
##去除基因id为NA的基因
rt=rt[is.na(rt[,"entrezID"])==F,]
gene=rt$entrezID
#GO分析
kk <- enrichGO(gene = gene,
OrgDb = org.Gg.eg.db, # 参考基因组
pvalueCutoff =0.5, # P值阈值
qvalueCutoff =1, # qvalue是P值的校正值
ont="all", # 分三个层面来阐述基因功能,生物学过程(BP),细胞组分(CC),分子功能(MF)
readable =T) # 是否将基因id转换为基因名
write.table(kk,file="GO_result.txt",sep="\t",quote=F,row.names = F) #保存富集结果
#做图
##柱状图
pdf(file="GO_barplot.pdf",width = 10,height = 13)
barplot(kk, drop = TRUE, showCategory =10,label_format=50,split="ONTOLOGY") + facet_grid(ONTOLOGY~., scale='free')
dev.off()
##气泡图
pdf(file="GO_bubble.pdf",width = 10,height = 13)
dotplot(kk,showCategory = 10,label_format=50,split="ONTOLOGY",orderBy = "GeneRatio") + facet_grid(ONTOLOGY~., scale='free')
dev.off()
#KEGG分析
kk <- enrichKEGG(gene = gene,
organism = "gga",
pvalueCutoff =0.05,
qvalueCutoff =1)
write.table(kk,file="KEGG_result.txt",sep="\t",quote=F,row.names = F) #保存富集结果
#做图
##柱状图
pdf(file="KEGG_barplot.pdf",width = 10,height = 13)
barplot(kk, drop = TRUE, showCategory = 30)
dev.off()
##气泡图
pdf(file="KEGG_bubble.pdf",width = 10,height = 5)
dotplot(kk, showCategory = 30,label_format=50,orderBy = "GeneRatio")
dev.off()
R

全部评论 (0)
还没有任何评论哟~
