在做完KEGG通路富集之后,纷繁复杂的通路映入眼帘,略微有些杂乱无章,缺乏一个有序的排列,因此,本推送依据KEGG一级类目,将不同的通路归纳总结,分类排列,使结果更加规整,帮助后续进一步分析与研究
1. 准备工作
1.1 R包安装
library("clusterProfiler")
library("org.Hs.eg.db")
library("dplyr")
library("ggsci")
library("ggplot2")
ggsci的教程可以查看昨天的推送,现学现用~[ggsci | 一行代码拥有Sci级配色]
1.2 环境配置
关于为什么要进行环境配置可以查看既往推送[KEGG数据库报错及解决],避免KEGG富集分析中报错。
options(clusterProfiler.download.method = "wininet")
1.3 文件准备
一共需要准备2个文件,一个是差异分析结果diffSig.xls
,另一个是通路关系文件KEGG_relation.xls
,本推送已整理好KEGG_relation.xls
,文末有免费获取方式
# 1. 差异分析文件
diff <- read.table("./input/diffSig.xls",sep = "\t",header = T)
> head(diff)
genes logFC
1 C4orf19 1.85
2 C3orf80 2.12
3 C2orf81 5.18
4 C17orf50 1.53
5 C11orf24 1.95
6 C9orf64 1.66
# 2. 通路关系文件
KEGG_relation <- read.table("./file/KEGG_relation.xls",sep = "\t",header = T)
> head(KEGG_relation)
Class1 terms
1 Cellular Processes Adherens junction
2 Cellular Processes Apoptosis
3 Cellular Processes Apoptosis - fly
4 Cellular Processes Apoptosis - multiple species
5 Cellular Processes Autophagy - animal
6 Cellular Processes Autophagy - other
2. 分析步骤
将差异分析结果(如1.3中的diffSig.xls)放入file
文件夹中,全选运行code.R
即可
library("clusterProfiler")
library("org.Hs.eg.db")
library("dplyr")
library("ggsci")
library("ggplot2")
options(clusterProfiler.download.method = "wininet")
diff <- read.table("./input/diffSig.xls",sep = "\t",header = T)
KEGG_relation <- read.table("./file/KEGG_relation.xls",sep = "\t",header = T)
genes=as.vector(diff[,1])
entrezIDs <- mget(genes, org.Hs.egSYMBOL2EG, ifnotfound=NA) %>%as.character(.)
kk <- enrichKEGG(gene = entrezIDs, organism = "hsa", pvalueCutoff = 0.05, qvalueCutoff = 2)
enrich_results <- subset(kk@result,pvalue < 0.05)
enrich_intersect <- inner_join(KEGG_relation,enrich_results,by=c("terms"="Description"))
enrich_intersect$Class1 <- factor(enrich_intersect$Class1,levels = unique(enrich_intersect$Class1))
KEGG_results <- ggplot(enrich_intersect, aes(x=terms, y=Count,fill=Class1)) +
geom_bar(stat="identity", width=0.8) + # width可设置条形图宽度
coord_flip() +
xlab("") +
theme_bw()+
scale_fill_lancet(name = "Type")+
scale_x_discrete(limits = factor(enrich_intersect$terms))+
guides(fill = guide_legend(reverse=T))+
theme_bw()+
theme(panel.grid=element_blank())+
theme(axis.title = element_text(size = 15,face = "bold",colour = "black"),
axis.text = element_text(size=10,face = "bold",colour = "black"),
panel.border = element_rect(fill=NA,color="black", linewidth =3, linetype="solid"),
axis.ticks = element_line(size = 2),
legend.text = element_text(size = 10,face="bold"),
legend.title = element_text(size = 10,face = "bold"))
KEGG_results
ggsave("KEGG_classification.PDF",plot = KEGG_results,width = 10,height = 8)
当然,此处输出的是所有P<0.05
的结果,如果想要指定KEGG条目
的话,可以查看推送[如何筛选感兴趣的GO和KEGG进行绘图~]
最终呈现效果
image感谢观看,如果有用还请点赞,关注,在看,转发!
网友评论