clusterProfiler 做 GO 和 KEGG 的富集分析
软件版本
- R版本:4.1.0
- R包版本:clusterProfiler 4.0.5
R包安装
如果你的R版本比较新,可以先试试直接安装clusterProfiler。
当前在用的服务器上的R版本是3.6.0,算比较旧的,装R包经常报错。
然后虽然Bioconductor的clusterProfiler写着依赖R >= 3.5.0,但是很多依赖包都会要求更高的R版本,我都懒得逐个包查哪个版本适配了,所以直接搭个最新版本的R的docker容器算了。
- 从docker registry获取r-base作为基础镜像
docker pull r-base
如需指定4.1.0版本则用docker pull r-base:4.1.0
- 搭建clusterProfiler的容器
- 容器搭建
1
2
3
4
5
6# Shell
#!/bin/sh
local_path=/xxx/clusterProfiler
# 需要--privileged参数,否则后面安装clusterProfiler包会报错
docker run -tid --privileged --name clusterProfiler_Test --restart=always -v $local_path:/Test r-base:4.1.0 /bin/bash - 进入容器
1
2
3# 命令行
docker exec -ti clusterProfiler_Test /bin/bash - 容器内安装clusterProfiler
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18# 命令行,安装依赖
apt-get update
apt install curl libcurl4-openssl-dev libssl-dev libxml2-dev
# 命令行,进入R
R
# 进入R后,安装包
# org.Hs.eg.db是人的基因注释数据库;如果是别的物种,这里下载和后面调用的数据库名称,以及物种名称是hsa的,都要换成对应物种的
# OrgDb的19个物种数据库:http://bioconductor.org/packages/release/BiocViews.html#___OrgDb
# pathview、enrichplot、ggplot2都是用来画图的
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager")
BiocManager::install("clusterProfiler")
BiocManager::install("org.Hs.eg.db")
BiocManager::install("pathview")
BiocManager::install("enrichplot")
BiocManager::install("ggplot2") - GO、KEGG富集分析
1
见后面的[分析脚本]部分
- 退出容器
1
2# 键盘操作
# Ctrl + p + q - 容器的后续处理
- 搭建容器时用了–restart=always,容器会保持启动状态,随时可以进入容器分析
- 如果暂时不需要用了,可以先将容器导出成镜像文件,再删除容器
1
2
3
4
5
6# 命令行,导出镜像文件
docker export clusterProfiler_Test -o clusterProfiler.tar
# 命令行,停止和删除容器
docker stop clusterProfiler_Test
docker rm clusterProfiler_Test
- 容器搭建
分析脚本
脚本参考clusterProfiler官方文档中Part II: Enrichment analysis的6 GO enrichment analysis和7 KEGG enrichment analysis。
Over Representation Analysis (ORA, 过表达分析)和Gene Set Enrichment Analysis (GSEA, 基因富集分析)两种分析方法,分别写了两个脚本。
GO和KEGG都在同一个脚本里,有哪部分不需要的话,直接注释就行。
Shell调用Rscript
1 | # ORA |
ORA脚本
clusterProfiler_ORA.R
1 | library("clusterProfiler") |
ORA.list
1 | AP5Z1 |
ORA_Result
1 | ORA_Result |
GO
- ORA.BP.bar.png
- ORA.BP.png
- ORA.BP.xls
- ORA.BP.bar.png
KEGG
- ORA.hsa00531.png
- ORA.KEGG.png
- ORA.KEGG.xls
- ORA.hsa00531.png
GSEA脚本
clusterProfiler_GSEA.R
1 | library("clusterProfiler") |
GSEA.list
1 | S100A11 0.695631395 |
GSEA_Result
1 | GSEA_Result |
GO
- GSEA.CC.GO_1902494.png
- GSEA.CC.xls
- GSEA.CC.GO_1902494.png
KEGG
- GSEA.hsa05170.png
- GSEA.KEGG.xls
- GSEA.hsa05170.png
参考资料
- clusterProfiler Github https://github.com/YuLab-SMU/clusterProfiler
- clusterProfiler 官方文档 https://yulab-smu.top/biomedical-knowledge-mining-book/index.html
- 富集分析:(一)概述 https://zhuanlan.zhihu.com/p/534016487