网上很多教程都在讲Y叔的clusterprofile富集分析的教程,但是查阅了官方文档后才知道,这个包真的不仅仅只有这个功能,其他功能也很强大。

做ID转换

ID转换应该是基因下游分析的敲门砖了,因为一般注释用的是ENSMEBL ID,但是这个ID是人类无法识别的一串数字,下游分析功能都需要转换成基因名称或者基因ID,有这个bitr功能就方便了很多。

  1. x <- c("GPX3", "GLRX", "LBP", "CRYAB", "DEFB1", "HCLS1", "SOD2", "HSPA2",
  2. "ORM1", "IGFBP1", "PTHLH", "GPC3", "IGFBP3","TOB1", "MITF", "NDRG1",
  3. "NR1H4", "FGFR3", "PVR", "IL6", "PTPRM", "ERBB2", "NID2", "LAMB1",
  4. "COMP", "PLS3", "MCAM", "SPP1", "LAMC1", "COL4A2", "COL4A1", "MYOC",
  5. "ANXA4", "TFPI2", "CST6", "SLPI", "TIMP2", "CPM", "GGT1", "NNMT",
  6. "MAL", "EEF1A2", "HGD", "TCN2", "CDA", "PCCA", "CRYM", "PDXK",
  7. "STC1", "WARS", "HMOX1", "FXYD2", "RBP4", "SLC6A12", "KDELR3", "ITM2B")
  8. eg = bitr(x, fromType="SYMBOL", toType="ENTREZID", OrgDb="org.Hs.eg.db")
  9. head(eg)
  1. ## SYMBOL ENTREZID
  2. ## 1 GPX3 2878
  3. ## 2 GLRX 2745
  4. ## 3 LBP 3929
  5. ## 4 CRYAB 1410
  6. ## 5 DEFB1 1672
  7. ## 6 HCLS1 3059

想知道你可以进行哪些ID 转换?

  1. library(org.Hs.eg.db)
  2. keytypes(org.Hs.eg.db)
  1. ## [1] "ACCNUM" "ALIAS" "ENSEMBL"
  2. ## [4] "ENSEMBLPROT" "ENSEMBLTRANS" "ENTREZID"
  3. ## [7] "ENZYME" "EVIDENCE" "EVIDENCEALL"
  4. ## [10] "GENENAME" "GO" "GOALL"
  5. ## [13] "IPI" "MAP" "OMIM"
  6. ## [16] "ONTOLOGY" "ONTOLOGYALL" "PATH"
  7. ## [19] "PFAM" "PMID" "PROSITE"
  8. ## [22] "REFSEQ" "SYMBOL" "UCSCKG"
  9. ## [25] "UNIGENE" "UNIPROT"

Note:虽然GO分析支持很多ID,例如symbol完全可以直接运行,但还是建议都转换为ENTREZID,毕竟,我们很少直接得到symbol啊。

GSEA分析

还在使用官方的GSEA java包进行富集分析吗,你需要准备gct文件(表达矩阵),要转换为symbol或者entrezid,还要准备cls文件(样本特征),还要下载好gmt文件,最后出来的分析结果,各种图片都是不好看的,准确说不够灵活,用R包呢?

GSEA_GO

  1. ego3 <- gseGO(geneList = geneList,
  2. OrgDb = org.Hs.eg.db,
  3. ont = "CC",
  4. nPerm = 1000,
  5. minGSSize = 100,
  6. maxGSSize = 500,
  7. pvalueCutoff = 0.05,
  8. verbose = FALSE)

geneList 是什么?

类似于做富集(过表达)分析,geneList是一列基因id,而GSEA分析一般需要基因表达量来衡量富集分数,但是从原理上来讲,还是根据表达量计算Fordchange,然后给他排序,看这个排序在基因集中的富集程度。这样就不会因为传统分析中先筛选差异基因而过滤掉的低差异基因信息(详情参考GSEA的原理),所以,这个基因列表是指一列排序后的以基因名称为名字的log2FC值向量

假设你有一个两列的文件,第一列为名字,第二列为logFC,你可以这样:

  1. d <- read.csv(your_csv_file)
  2. ##第一列为基因ID
  3. ##第二列为差异值
  4. ## 获取log2FC
  5. geneList <- d[,2]
  6. ## 命名
  7. names(geneList) <- as.character(d[,1])
  8. ## 降序
  9. geneList <- sort(geneList, decreasing = TRUE)
  10. head(geneList)

剩余都是一些限制参数,请执行?clusterProfiler::gseGO

  1. ## 4312 8318 10874 55143 55388 991
  2. ## 4.572613 4.514594 4.418218 4.144075 3.876258 3.677857

GSEA-KEGG

  1. kk2 <- gseKEGG(geneList = geneList,
  2. organism = 'hsa',
  3. nPerm = 1000,
  4. minGSSize = 120,
  5. pvalueCutoff = 0.05,
  6. verbose = FALSE)
  7. head(kk2)
  1. ## ID Description setSize
  2. ## hsa04510 hsa04510 Focal adhesion 188
  3. ## hsa04151 hsa04151 PI3K-Akt signaling pathway 322
  4. ## hsa03013 hsa03013 RNA transport 131
  5. ## hsa05152 hsa05152 Tuberculosis 162
  6. ## hsa04062 hsa04062 Chemokine signaling pathway 165
  7. ## hsa04218 hsa04218 Cellular senescence 143
  8. ## enrichmentScore NES pvalue p.adjust
  9. ## hsa04510 -0.4188582 -1.706291 0.001430615 0.02322097
  10. ## hsa04151 -0.3482755 -1.497042 0.002614379 0.02322097
  11. ## hsa03013 0.4116488 1.735751 0.003095975 0.02322097
  12. ## hsa05152 0.3745153 1.630500 0.003154574 0.02322097
  13. ## hsa04062 0.3754101 1.633635 0.003184713 0.02322097
  14. ## hsa04218 0.4153718 1.772207 0.003194888 0.02322097
  15. ## qvalues rank leading_edge
  16. ## hsa04510 0.01576976 2183 tags=27%, list=17%, signal=23%
  17. ## hsa04151 0.01576976 1997 tags=23%, list=16%, signal=20%
  18. ## hsa03013 0.01576976 3383 tags=40%, list=27%, signal=29%
  19. ## hsa05152 0.01576976 2823 tags=34%, list=23%, signal=27%
  20. ## hsa04062 0.01576976 1298 tags=21%, list=10%, signal=19%
  21. ## hsa04218 0.01576976 1155 tags=17%, list=9%, signal=16%
  22. ## core_enrichment
  23. ## hsa04510 5595/5228/7424/1499/4636/83660/7059/5295/1288/23396/3910/3371/3082/1291/394/3791/7450/596/3685/1280/3675/595/2318/3912/1793/1278/1277/1293/10398/55742/2317/7058/25759/56034/3693/3480/5159/857/1292/3908/3909/63923/3913/1287/3679/7060/3479/10451/80310/1311/1101
  24. ## hsa04151 627/2252/7059/92579/5563/5295/6794/1288/7010/3910/3371/3082/1291/4602/3791/1027/90993/3441/3643/1129/2322/1975/7450/596/3685/1942/2149/1280/4804/3675/595/2261/7248/2246/4803/3912/1902/1278/1277/2846/2057/1293/2247/55970/5618/7058/10161/56034/3693/4254/3480/4908/5159/1292/3908/2690/3909/8817/9223/4915/3551/2791/63923/3913/9863/3667/1287/3679/7060/3479/80310/1311/5105/2066/1101
  25. ## hsa03013 10460/1978/55110/54913/9688/8894/11260/10799/9631/4116/5042/8761/6396/23165/8662/10248/55706/79833/9775/29107/23636/5905/9513/5901/10775/10557/4927/79902/1981/26986/11171/10762/8480/8891/11097/26019/10940/4686/9972/81929/10556/3646/9470/387082/1977/57122/8563/7514/79023/3837/9818/56000
  26. ## hsa05152 820/51806/6772/64581/3126/3112/8767/3654/1054/1051/3458/1520/11151/1594/50617/54205/91860/8877/3329/637/3689/7096/2207/3929/4360/5603/929/533/3452/6850/7124/1509/3569/7097/1378/8772/64170/3119/843/2213/8625/3920/2215/3587/5594/3593/9103/3592/6300/9114/10333/3109/3108/1432/3552
  27. ## hsa04062 3627/10563/6373/4283/6362/6355/2921/6364/3576/6352/10663/1230/6772/6347/6351/3055/1237/1236/4067/6354/114/3702/6361/1794/1234/6367/6375/6374/2919/409/4793/2792/6360/5880
  28. ## hsa04218

结果里面包含了所有GSEA计算的结果数值

setSize:基因集的大小
enrichmentScore:富集打分
NES:标准化后的富集打分
pvalue,p.ajust.qvalues:各种显著性检验
rank:log2FC的排序位置

根据官方提供的gmt文件或者自己做gmt文件进行分析

假设你从官网下载了Hallmark基因集

  1. wp2gene <- read.gmt("h.all.v7.0.entrez.gmt")
  2. em2 <- GSEA(geneList, TERM2GENE = wp2gene)

这样就可以直接得到富集分析的结果,非常方便

另外,也可以通过msigdbr包直接获取基因集信息,但是感觉灵活性不高。

对GSEA的结果可视化

  1. anno <- edo2[1, c("NES", "pvalue", "p.adjust")]
  2. lab <- paste0(names(anno), "=", round(anno, 3), collapse="\n")
  3. gseaplot2(edo2, geneSetID = 1, title = edo2$Description[1])+annotate("text", 0.7, edo2[i, "enrichmentScore"] * .9, label = lab, hjust=0, vjust=0)

ClusterProfiler:真的不只是富集分析 - 图1

  1. pp <- lapply(1:3, function(i) {
  2. anno <- edo2[i, c("NES", "pvalue", "p.adjust")]
  3. lab <- paste0(names(anno), "=", round(anno, 3), collapse="\n")
  4. gsearank(edo2, i, edo2[i, 2]) + xlab(NULL) +ylab(NULL) +
  5. annotate("text", 0, edo2[i, "enrichmentScore"] * .9, label = lab, hjust=0, vjust=0)
  6. })
  7. plot_grid(plotlist=pp, ncol=1)

ClusterProfiler:真的不只是富集分析 - 图2

使结果可读性提升

针对分析结果,GO富集可以设置参数readable = TRUE,但是对KEGG无法使用,因此,可以使用setReadable

  1. library(org.Hs.eg.db)
  2. library(clusterProfiler)
  3. data(geneList, package="DOSE")
  4. de <- names(geneList)[1:100]
  5. x <- enrichKEGG(de)
  6. ## The geneID column is ENTREZID
  7. head(x, 3)
  1. ## ID Description GeneRatio BgRatio
  2. ## hsa04110 hsa04110 Cell cycle 8/48 124/7932
  3. ## hsa04218 hsa04218 Cellular senescence 7/48 160/7932
  4. ## hsa04114 hsa04114 Oocyte meiosis 6/48 128/7932
  5. ## pvalue p.adjust qvalue
  6. ## hsa04110 6.356283e-07 7.182599e-05 6.490099e-05
  7. ## hsa04218 4.377944e-05 2.473538e-03 2.235055e-03
  8. ## hsa04114 1.105828e-04 4.165285e-03 3.763695e-03
  9. ## geneID Count
  10. ## hsa04110 8318/991/9133/890/983/4085/7272/1111 8
  11. ## hsa04218 2305/4605/9133/890/983/51806/1111 7
  12. ## hsa04114 991/9133/983/4085/51806/6790 6
  1. y <- setReadable(x, OrgDb = org.Hs.eg.db, keyType="ENTREZID")
  2. ## The geneID column is translated to symbol
  3. head(y, 3)
  1. ## ID Description GeneRatio BgRatio
  2. ## hsa04110 hsa04110 Cell cycle 8/48 124/7932
  3. ## hsa04218 hsa04218 Cellular senescence 7/48 160/7932
  4. ## hsa04114 hsa04114 Oocyte meiosis 6/48 128/7932
  5. ## pvalue p.adjust qvalue
  6. ## hsa04110 6.356283e-07 7.182599e-05 6.490099e-05
  7. ## hsa04218 4.377944e-05 2.473538e-03 2.235055e-03
  8. ## hsa04114 1.105828e-04 4.165285e-03 3.763695e-03
  9. ## geneID
  10. ## hsa04110 CDC45/CDC20/CCNB2/CCNA2/CDK1/MAD2L1/TTK/CHEK1
  11. ## hsa04218 FOXM1/MYBL2/CCNB2/CCNA2/CDK1/CALML5/CHEK1
  12. ## hsa04114 CDC20/CCNB2/CDK1/MAD2L1/CALML5/AURKA
  13. ## Count
  14. ## hsa04110 8
  15. ## hsa04218 7
  16. ## hsa04114 6

你甚至可以用它来对单细胞聚类结果进行注释

如果我们有一个大的细胞marker库,然后我们有显著差异的基因marker,那寻找细胞类型就和过表达分析是一种情况了,都是采用超几何分布计算概率,所以:

  1. cell_markers <- vroom::vroom('http://bio-bigdata.hrbmu.edu.cn/CellMarker/download/Human_cell_markers.txt') %>%
  2. tidyr::unite("cellMarker", tissueType, cancerType, cellName, sep=", ") %>%
  3. dplyr::select(cellMarker, geneID) %>%
  4. dplyr::mutate(geneID = strsplit(geneID, ', '))
  5. cell_markers

你甚至可以从cellmarker官网直接下载所有的细胞marker

  1. ## # A tibble: 2,868 x 2
  2. ## cellMarker geneID
  3. ## <chr> <list>
  4. ## 1 Kidney, Normal, Proximal tubular cell <chr [1…
  5. ## 2 Liver, Normal, Ito cell (hepatic stellate cell) <chr [1…
  6. ## 3 Endometrium, Normal, Trophoblast cell <chr [1…
  7. ## 4 Germ, Normal, Primordial germ cell <chr [1…
  8. ## 5 Corneal epithelium, Normal, Epithelial cell <chr [1…
  9. ## 6 Placenta, Normal, Cytotrophoblast <chr [1…
  10. ## 7 Periosteum, Normal, Periosteum-derived progenit… <chr [4…
  11. ## 8 Amniotic membrane, Normal, Amnion epithelial ce… <chr [2…
  12. ## 9 Primitive streak, Normal, Primitive streak cell <chr [2…
  13. ## 10 Adipose tissue, Normal, Stromal vascular fracti… <chr [1…
  14. ## # … with 2,858 more rows
  1. y <- enricher(gene, TERM2GENE=cell_markers, minGSSize=1)
  2. DT::datatable(as.data.frame(y))

这样就找到了细胞类型,你可以过滤占比最高,且p值显著的结果。