富集分析圈圈图
2020-09-13 本文已影响0人
刘小泽
0.需求解读
这是富集分析比较常见的一个图,左图右表。
图的最外层是GOterm的编号,中间灰色背景层表示基因的logFC分布,可以看到每个term对应到的市上调基因还是下调基因。最里面的一层市z-score值。这个值的计算方法在帮助文档中有明确指出,就是(up-down)/count。up、down、count是每个term富集到的上调、下调、所有基因的个数。
1.所需R包和数据
library(clusterProfiler)
library(org.Hs.eg.db)
library(GOplot)
library(stringr)
这个数据是简单的芯片差异分析得到的表格,在生信星球公众号回复“富集输入”即可获得。我只取了其中的100个差异基因来做富集分析。
load("step4output.Rdata")
head(deg)
## logFC AveExpr t P.Value adj.P.Val B probe_id
## 1 5.780170 7.370282 82.94833 3.495205e-12 1.163798e-07 16.32898 8133876
## 2 -4.212683 9.106625 -68.40113 1.437468e-11 2.393169e-07 15.71739 7965335
## 3 5.633027 8.763220 57.61985 5.053466e-11 4.431880e-07 15.04752 7972259
## 4 -3.801663 9.726468 -57.21112 5.324059e-11 4.431880e-07 15.01709 7972217
## 5 3.263063 10.171635 50.51733 1.324638e-10 8.821294e-07 14.45166 8129573
## 6 -3.843247 9.667077 -45.87910 2.681063e-10 1.487856e-06 13.97123 8015806
## symbol change ENTREZID
## 1 CD36 up 948
## 2 DUSP6 down 1848
## 3 DCT up 1638
## 4 SPRY2 down 10253
## 5 MOXD1 up 26002
## 6 ETV4 down 2118
deg = deg[deg$change!="stable",]
deg = deg[1:100,]
gene_diff = deg$symbol
2.富集分析
ego_BP <- enrichGO(gene = gene_diff,
keyType = "SYMBOL",
OrgDb= org.Hs.eg.db,
ont = "BP",
pAdjustMethod = "BH",
minGSSize = 1,
pvalueCutoff = 0.05,
qvalueCutoff = 0.05)
class(ego_BP)
## [1] "enrichResult"
## attr(,"package")
## [1] "DOSE"
3.转换成图的输入数据
ego <- data.frame(ego_BP)
colnames(ego)
## [1] "ID" "Description" "GeneRatio" "BgRatio" "pvalue"
## [6] "p.adjust" "qvalue" "geneID" "Count"
ego <- ego[1:10,c(1,2,8,6)]
ego$geneID <- str_replace_all(ego$geneID,"/",",")
names(ego)=c("ID","Term","Genes","adj_pval")
ego$Category = "BP"
head(ego)
## ID Term
## GO:0050730 GO:0050730 regulation of peptidyl-tyrosine phosphorylation
## GO:0018108 GO:0018108 peptidyl-tyrosine phosphorylation
## GO:0018212 GO:0018212 peptidyl-tyrosine modification
## GO:0048732 GO:0048732 gland development
## GO:0014033 GO:0014033 neural crest cell differentiation
## GO:0050673 GO:0050673 epithelial cell proliferation
## Genes
## GO:0050730 CD36,AREG,TGFA,CD24,SFRP1,ITGB3,MIR221,SH2B3,CNTN1,INPP5F,MVP
## GO:0018108 CD36,AREG,TGFA,CD24,SFRP1,ITGB3,MIR221,EPHA5,SH2B3,CNTN1,INPP5F,MVP
## GO:0018212 CD36,AREG,TGFA,CD24,SFRP1,ITGB3,MIR221,EPHA5,SH2B3,CNTN1,INPP5F,MVP
## GO:0048732 ETV5,CCND1,AREG,SERPINF1,SFRP1,IGFBP5,JUN,SEMA3C,SOX2,SNAI2,PBX1,E2F7
## GO:0014033 SFRP1,SEMA3C,SNAI2,ZEB2,MEF2C,FOLR1
## GO:0050673 NUPR1,CCND1,AREG,SERPINF1,TGFA,SFRP1,IGFBP5,JUN,ITGB3,SOX2,SNAI2,MEF2C
## adj_pval Category
## GO:0050730 0.0001118840 BP
## GO:0018108 0.0001609363 BP
## GO:0018212 0.0001609363 BP
## GO:0048732 0.0006502891 BP
## GO:0014033 0.0006502891 BP
## GO:0050673 0.0006502891 BP
genes = data.frame(ID=deg$symbol,
logFC=deg$logFC)
head(genes)
## ID logFC
## 1 CD36 5.780170
## 2 DUSP6 -4.212683
## 3 DCT 5.633027
## 4 SPRY2 -3.801663
## 5 MOXD1 3.263063
## 6 ETV4 -3.843247
circ <- circle_dat(ego,genes);head(circ)
## category ID term count
## 1 BP GO:0050730 regulation of peptidyl-tyrosine phosphorylation 11
## 2 BP GO:0050730 regulation of peptidyl-tyrosine phosphorylation 11
## 3 BP GO:0050730 regulation of peptidyl-tyrosine phosphorylation 11
## 4 BP GO:0050730 regulation of peptidyl-tyrosine phosphorylation 11
## 5 BP GO:0050730 regulation of peptidyl-tyrosine phosphorylation 11
## 6 BP GO:0050730 regulation of peptidyl-tyrosine phosphorylation 11
## genes logFC adj_pval zscore
## 1 CD36 5.780170 0.000111884 -0.904534
## 2 AREG -3.095910 0.000111884 -0.904534
## 3 TGFA -2.518930 0.000111884 -0.904534
## 4 CD24 3.322533 0.000111884 -0.904534
## 5 SFRP1 -2.103767 0.000111884 -0.904534
## 6 ITGB3 -3.162000 0.000111884 -0.904534
4.出图的代码其实很简单的
GOCircle(circ)
image.png
关于zscore,可以来个验证,理解更深一点:
ego$ID[1]
## [1] "GO:0050730"
circ$zscore[1]
## [1] -0.904534
gs = str_split(ego$Genes[1],
",")[[1]]
table(deg$change[deg$symbol %in% gs])
##
## down up
## 7 4
(4-7)/sqrt(11)
## [1] -0.904534