最近做这些富集分析实在太烦了,我就自己写了2
个函数,run_enrichment_all()
和plot_enrichment_all()。
😂
这2
个函数可以轻松完成GO
和KEGG
的富集分析和可视化,具体大家看一下。😜
当然也参考了别人的代码,深表感谢哈!~😆
library(clusterProfiler)
library(AnnotationDbi)
library(dplyr)
library(ggplot2)
library(tibble)
library(tidyr)
library(ggprism)
library(gground)
输入文件可以是SYMBOL
也可以是ENTREZID
。😘
我这里以ENTREZID
为例。🙊
data(geneList, package="DOSE")
gene <- names(geneList)[abs(geneList) > 2]
gene
dir.create("./enrichment")
这里第一个函数,是基于clusterProfiler
的,可以轻松完成所有的G0
(包括BP
,CC
,MF
)和KEGG
分析。🧐
如果你懒得改参数,这里我都有默认好的。😘
res <- run_enrichment_all(gene,
species = "human", # "human", "mouse", "rat"
id_type = "ENTREZID", # "ENTREZID", "SYMBOL"
pvalueCutoff = 0.05,
qvalueCutoff = 0.05,
minGSSize = 5,
maxGSSize = 500,
readable = T
)
write.csv(res$BP, "./enrichment/enrichment_all_result_BP.csv")
write.csv(res$CC, "./enrichment/enrichment_all_result_CC.csv")
write.csv(res$MF, "./enrichment/enrichment_all_result_.csv")
write.csv(res$KEGG, "./enrichment/enrichment_all_result_KEGG.csv")
这里默认参数也是做好的。😘
当然你也可以按需更改。😂
plot_enrichment_all(res, top_n = 5)
plot_enrichment_all(res, top_n = 5, gene_show_num = 10)
plot_enrichment_all(res,
top_n = 5, # default 5
gene_show_num = 10, # default 5
color_palette = c("#640D5F", "#D91656", "#EB5B00", "#FFB200")
)