作者:吖鸟集团总公司 | 来源:互联网 | 2023-08-20 10:08
##Time:2017-10-8
##Author:Feng Shengyu
#—————————————————-
#一、安装必须的R包(推荐使用的R版本3.2.2)
#必须要安装的包:
# 1、clusterprofilter
# source(“http://bioconductor.org/biocLite.R”)
# biocLite(“clusterprofilter”)
# 2、org.Mm.eg.db/org.Hs.eg.db(对应需要研究的物种-小鼠/人)
# biocLite(“org.Mm.eg.db”)/biocLite(“org.Hs.eg.db”)
# 3、DOSE
# biocLite(DOSE)
library(clusterProfiler)
library(DOSE)
library(org.Mm.eg.db)
#二 change the type of gene
#使用的上游数据是RNA-seq做完的差异表达的基因列表
#example:
# 15431
# 244091
# 15430
# 319158
# 13871
# 109663
# 735269
# 378431
# 21384
# 105247262
#读取gene list
gene <- read.table(&#8220;C:\\Users\\Feng\\Desktop\\up_regulate_symbolGene.txt&#8221;)
geneSymbol <- gene[,1]
geneSymbol
#转化基因类型,一般用cufflinks做的结果是symbol,此时需要转化为entrzid
geneEntrezID <- bitr(geneSymbol, fromType=&#8221;SYMBOL&#8221;, toType=&#8221;ENTREZID&#8221;, OrgDb=&#8221;org.Mm.eg.db&#8221;)
#可以同时转为多个类型的基因
#geneEntrezID <- bitr(geneSymbol, fromType=&#8221;SYMBOL&#8221;, toType=c(&#8220;ENTREZID&#8221;,&#8221;UNIPROT&#8221;), OrgDb=&#8221;org.Mm.eg.db&#8221;,)
#三、enrichment analysis
#GO富集分析
ego_cc <- enrichGO(gene = geneEntrezID[,2], #使用entrezID作为输入
OrgDb=org.Mm.eg.db,
Ont= &#8220;CC&#8221;,
pAdjustMethod = &#8220;BH&#8221;,
minGSSize = 1,
pvalueCutoff = 0.05,
qvalueCutoff = 0.05,
readable = TRUE
)
setwd(&#8220;F:\\生信工具大全\\R&#8221;)
write.table(as.data.frame(ego_cc@result),file=&#8221;test_CC.txt&#8221;,sep=&#8221;\t&#8221;)
#KEGG富集分析
kk <- enrichKEGG(gene = geneEntrezID[,2],
organism =&#8221;mouse&#8221;,
pvalueCutoff = 0.05,
qvalueCutoff = 0.01,
minGSSize = 1,
use_internal_data =FALSE
)
write.table(as.data.frame(kk@result), file=&#8221;test_kk.txt&#8221;,sep=&#8221;\t&#8221;)
#作图展示结果
barplot(ego_cc, showCategory=15, title=&#8221;EnrichmentGO_CC&#8221;) #条状图,按p从小到大排的
dotplot(ego_BP,title=&#8221;EnrichmentGO_CC_dot&#8221;) #点图,按富集的数从大到小的
#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;核心代码&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;
setwd(&#8220;F:\\硕士生\\GO和KEGG富集分析&#8221;)
library(clusterProfiler)
library(DOSE)
library(org.Mm.eg.db)
gene <- read.table(&#8220;C:\\Users\\Feng\\Desktop\\up_regulate.gene&#8221;)
geneSymbol <- gene[,1]
geneEntrezID <- bitr(geneSymbol, fromType=&#8221;SYMBOL&#8221;, toType=&#8221;ENTREZID&#8221;, OrgDb=&#8221;org.Mm.eg.db&#8221;)
ego_cc <- enrichGO(gene = geneEntrezID[,2], #使用entrezID作为输入
OrgDb=org.Mm.eg.db,
Ont= &#8220;CC&#8221;,
pAdjustMethod = &#8220;BH&#8221;,
minGSSize = 1,
pvalueCutoff = 0.01,
qvalueCutoff = 0.01,
readable = TRUE
)
write.table(as.data.frame(ego_cc@result),file=&#8221;haimati_M_up_enrich_GO.txt&#8221;,sep=&#8221;\t&#8221;)
barplot(ego_cc, showCategory=15, title=&#8221;GO_Enrichment&#8221;) #条状图,按p从小到大排的
ego_BP <- enrichKEGG(gene = geneEntrezID[,2],
organism =&#8221;mouse&#8221;, #http://www.genome.jp/kegg/catalog/org_list.html(species names)
pvalueCutoff = 0.05,
qvalueCutoff = 0.01,
minGSSize = 1,
use_internal_data =FALSE
)
write.table(as.data.frame(ego_BP@result), file=&#8221;haimati_M_up_enrich_KEGG.txt&#8221;,sep=&#8221;\t&#8221;)
dotplot(ego_BP,title=&#8221;EnrichmentGO_CC_dot&#8221;) #点图,按富集的数从大到小的