GEO数据挖掘之使用clusterProfiler进行GO/KEGG富集分析

clusterProfiler是一个功能强大的R包,同时支持GO和KEGG的富集分析,是生信技能树[生信爆款入门课程]GEO数据挖掘的重点。为拓展课堂所学知识,现在找一个数据集对他们做下练习总结。

 library(clusterProfiler)
> library(dplyr)
> library(ggplot2)
> library(stringr)
Warning message:
程辑包‘stringr’是用R版本4.0.3 来建造的 
> library(enrichplot)
Warning message:
程辑包‘enrichplot’是用R版本4.0.3 来建造的 

(1)准备输入数据

> gene_up = deg[deg$change == 'up','ENTREZID']
> gene_down = deg[deg$change == 'down','ENTREZID']
> gene_diff = c(gene_up,gene_down)
> gene_all = deg[,'ENTREZID']

(2)富集可视化

> if(!file.exists(paste0(gse_number,"_GO.Rdata"))){
+   ego <- enrichGO(gene = gene_diff,
+                   OrgDb= org.Hs.eg.db,
+                   ont = "ALL",
+                   readable = TRUE)
+   #ont参数:One of "BP", "MF", and "CC" subontologies, or "ALL" for all three.
+   save(ego,file = paste0(gse_number,"_GO.Rdata"))
+ }
> load(paste0(gse_number,"_GO.Rdata"))

条带图

> barplot(ego)
image.png

气泡图

> dotplot(ego)
image.png
wrong orderBy parameter; set to default `orderBy = "x"`
> dotplot(ego, split = "ONTOLOGY", font.size = 10, 
+         showCategory = 5) + facet_grid(ONTOLOGY ~ ., scale = "free") + 
+   scale_y_discrete(labels = function(x) str_wrap(x, width = 45))
wrong orderBy parameter; set to default `orderBy = "x"`
Scale for 'y' is already present. Adding another scale for 'y', which will replace the
existing scale.
> #geneList 用于设置下面图的颜色
> geneList = deg$logFC
> names(geneList)=deg$ENTREZID
> geneList = sort(geneList,decreasing = T)
image.png

(3)展示top通路的共同基因,要放大看。

> #Gene-Concept Network
> cnetplot(ego,categorySize="pvalue", foldChange=geneList,colorEdge = TRUE)
Warning message:
ggrepel: 235 unlabeled data points (too many overlaps). Consider increasing max.overlaps 
> cnetplot(ego, showCategory = 3,foldChange=geneList, circular = TRUE, colorEdge = TRUE)
Warning messages:
1: ggrepel: 235 unlabeled data points (too many overlaps). Consider increasing max.overlaps 
2: ggrepel: 235 unlabeled data points (too many overlaps). Consider increasing max.overlaps 
3: ggrepel: 149 unlabeled data points (too many overlaps). Consider increasing max.overlaps 
image.png
> Biobase::package.version("enrichplot")
[1] "1.10.1"
> emapplot(pairwise_termsim(ego)) #新版本
image.png
Warning messages:
1: ggrepel: 149 unlabeled data points (too many overlaps). Consider increasing max.overlaps 
2: ggrepel: 149 unlabeled data points (too many overlaps). Consider increasing max.overlaps 
> #(5)Heatmap-like functional classification
> heatplot(ego,foldChange = geneList,showCategory = 8)
image.png

2.KEGG pathway analysis----

(1)输入数据

上调、下调、差异、所有基因

> gene_up = deg[deg$change == 'up','ENTREZID']
> gene_down = deg[deg$change == 'down','ENTREZID']
> gene_diff = c(gene_up,gene_down)
> gene_all = deg[,'ENTREZID']
> if(!file.exists(paste0(gse_number,"_KEGG.Rdata"))){
+   kk.up <- enrichKEGG(gene         = gene_up,
+                       organism     = 'hsa')
+   kk.down <- enrichKEGG(gene         =  gene_down,
+                         organism     = 'hsa')
+   kk.diff <- enrichKEGG(gene         = gene_diff,
+                         organism     = 'hsa')
+   save(kk.diff,kk.down,kk.up,file = paste0(gse_number,"_KEGG.Rdata"))
+ }
> load(paste0(gse_number,"_KEGG.Rdata"))
> #(3)看看富集到了吗?https://mp.weixin.qq.com/s/NglawJgVgrMJ0QfD-YRBQg
> table(kk.diff@result$p.adjust<0.05)

FALSE  TRUE 
  280    22 
> table(kk.up@result$p.adjust<0.05)

FALSE  TRUE 
  239    35 
> table(kk.down@result$p.adjust<0.05)

FALSE  TRUE 
  230    20 
> (4)按照pvalue筛选通路
> down_kegg <- kk.down@result %>%
+   filter(pvalue<0.05) %>% #筛选行
+   mutate(group=-1) #新增列
> up_kegg <- kk.up@result %>%
+   filter(pvalue<0.05) %>%
+   mutate(group=1)

(2)可视化

> source("kegg_plot_function.R")
> g_kegg <- kegg_plot(up_kegg,down_kegg)
> g_kegg
> #g_kegg +scale_y_continuous(labels = c(4,2,0,2,4))
> ggsave(g_kegg,filename = 'kegg_up_down.png')
Saving 6.4 x 3.77 in image
> #(1)查看示例数据
> data(geneList, package="DOSE")
> #(2)将我们的数据转换成示例数据的格式
> geneList=deg$logFC
> names(geneList)=deg$ENTREZID
> geneList=sort(geneList,decreasing = T)
> #(3)富集分析
> kk_gse <- gseKEGG(geneList     = geneList,
+                   organism     = 'hsa',
+                   verbose      = FALSE)
Reading KEGG annotation online:

down_kegg<-kk_gse[kk_gse$pvalue<0.05 & kk_gse$enrichmentScore < 0,];down_kegg$group=-1
up_kegg<-kk_gse[kk_gse$pvalue<0.05 & kk_gse$enrichmentScore > 0,];up_kegg$group=1
#(4)可视化
g2
image.png

你可能感兴趣的:(GEO数据挖掘之使用clusterProfiler进行GO/KEGG富集分析)