前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >基因功能富集分析-R语言

基因功能富集分析-R语言

原创
作者头像
oriRNA
修改2018-06-26 23:51:12
5.7K6
修改2018-06-26 23:51:12
举报
文章被收录于专栏:R语言___生物信息
代码语言:text
复制
##安装bioconductor上的包;
source(“http://bioconductor.org/biocLite.R”)
biocLite(“clusterprofiler”)
biocLite("org.Hs.eg.db")#人基因名称等信息包;
##加载clusterprofiler包到当前工作路径;
library(clusterprofiler)#基因富集分析用;
library(org.Hs.eg.db)
#读入需要分析的数据,包含一列基因名称的列表;
a <- read.table(file.choose(),header = F,colClasses = "character")
#a <- read.table(file.choose(),header = F,colClasses = c("V1"= "character")),只设置第一列值为字符型;
###选取基因列的所有行
b <- a[,1]
###利用bitr函数将基因名称转换为ENTREZID号;物种是人org.Hs.eg.db;
eg = bitr(b,fromType = "SYMBOL",toType = "ENTREZID",OrgDb = "org.Hs.eg.db")
#可能会有部分基因对应不到ENTREZID,0.4% of input gene IDs are fail to map...
###转换后的基因名称保存为文档;
write.table(eg,file = "test_id.txt")
gene <- eg[,2]
###进行GO和KEGG分析;
library(clusterProfiler)
library(org.Hs.eg.db)
a <- read.table(file.choose(),header = F,colClasses = c("V1"= "character"))
b <- a[,1]
eg <- bitr(b,fromType = "SYMBOL",toType = "ENTREZID",OrgDb = "org.Hs.eg.db")
gene <- eg[,2]
ego_CC <- enrichGO(gene = gene,
                   OrgDb=org.Hs.eg.db,
                   ont = "CC",
                   pAdjustMethod = "BH",
                   minGSSize = 1,
                   pvalueCutoff = 0.01,
                   qvalueCutoff = 0.01,
                   readable = TRUE)
write.csv(as.data.frame(ego_CC),row.names = F, file = "ego_CC.csv")
barplot(ego_CC,drop = TRUE,title = "enrichment_CC",showCategory = 12)

ego_BP <- enrichGO(gene = gene,
                   OrgDb=org.Hs.eg.db,
                   ont = "BP",
                   pAdjustMethod = "BH",
                   minGSSize = 1,
                   pvalueCutoff = 0.01,
                   qvalueCutoff = 0.01,
                   readable = TRUE)
write.csv(as.data.frame(ego_BP),row.names = F, file = "ego_BP.csv")
barplot(ego_BP,drop = TRUE,title = "enrichment_BP",showCategory = 12)

ego_MF <- enrichGO(gene = gene,
                   OrgDb=org.Hs.eg.db,
                   ont = "MF",
                   pAdjustMethod = "BH",
                   minGSSize = 1,
                   pvalueCutoff = 0.01,
                   qvalueCutoff = 0.01,
                   readable = TRUE)
write.csv(as.data.frame(ego_MF),row.names = F, file = "ego_MF.csv")
barplot(ego_MF,drop = TRUE,title = "enrichment_MF",showCategory = 12)

kk <- enrichKEGG(gene = gene,
                 organism ="hsa",
                 pvalueCutoff = 0.01,
                 qvalueCutoff = 0.01,
                 minGSSize = 1,
                 #readable = TRUE ,
                 use_internal_data = FALSE)
write.csv(as.data.frame(kk),row.names = F, file = "kk.csv")
barplot(kk,drop = TRUE,title = "enrichment_kegg",showCategory = 12)

###DisGeNET4 is an integrative and comprehensive resources of gene-disease associations from several public data sources and the literature. It contains gene-disease associations and snp-gene-disease associations.
###The enrichment analysis of disease-gene associations is supported by the enrichDGN function and analysis of snp-gene-disease associations is supported by the enrichDGNv function.
dgn <- enrichDGN(gene = gene,
                 pAdjustMethod = "BH",
                 pvalueCutoff = 0.05,
                 qvalueCutoff = 0.05,
                 readable = TRUE)
head(dgn)

write.csv(as.data.frame(dgn),row.names = F, file = "dgn.csv")
barplot(dgn,drop = TRUE,title = "enrichment_disease",showCategory = 12)

###条行图,按p值从小到大排列;
barplot(ego_CC,showCategory = 24,title = "EnrichmentGO_CC")
###点状图,按富集数从大到小进行排列;
dotplot(ego_CC,title = "EnrichenmentGo_CC")

Gene Ontology富集分析结果表格。

GO ID: Gene Ontology数据库中唯一的标号信息

Description :Gene Ontology功能的描述信息

GeneRatio:输入基因中与该Term相关的基因数与整个输入基因总数的比值

BgRation:所有background基因中与该Term相关的基因数与所有background基因的比值

pvalue: 富集分析统计学显著水平,一般情况下, P-value < 0.05 该功能为富集项

p.adjust 矫正后的P-Value

qvalue:对p值进行统计学检验的q值

Count:差异基因中与该Term相关的基因数

http://scu.zju.edu.cn/redir.php?catalog_id=58400&object_id=203725

http://www.bioconductor.org/packages/release/bioc/vignettes/clusterProfiler/inst/doc/clusterProfiler.html

http://www.bio-info-trainee.com/370.html

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档