0.需求解读
左边是几个GO term,右边是基因。每个term一个颜色,基因的颜色按照logFC渐变。基因与term之间有连线,就是他们之间有从属关系。
1.数据和R包准备
library(clusterProfiler)
library(org.Hs.eg.db)
library(GOplot)
library(stringr)
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
这个数据是简单的芯片差异分析得到的表格,在生信星球公众号回复“富集输入”即可获得。我只取了其中的100个差异基因来做富集分析。
deg = deg[deg$change!="stable",]
deg = deg[1:100,]
gene_diff = deg$symbol
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"
clusterprofiler富集分析得到的结果是对象,先把他变成弦图的输入数据:
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
还需要提供一个由基因和logFC组成的数据框
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)
chord <- chord_dat(data=circ, genes=genes,process = ego$Term) #
GOChord(chord, space = 0.02, gene.order = 'logFC', gene.space = 0.25, gene.size = 5)
其实clusterprofiler里也有类似的图
cnetplot(ego_BP, categorySize="pvalue",colorEdge = TRUE,circular = TRUE)
参考:https://cran.r-project.org/web/packages/GOplot/vignettes/GOplot_vignette.html
https://www.jianshu.com/p/48ac98098760