富集分析圈圈圖

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)

關於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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章