在做完KEGG通路富集之后光绕,紛繁復(fù)雜的通路映入眼簾女嘲,略微有些雜亂無章,缺乏一個有序的排列诞帐,因此欣尼,本推送依據(jù)KEGG一級類目,將不同的通路歸納總結(jié)停蕉,分類排列愕鼓,使結(jié)果更加規(guī)整,幫助后續(xù)進(jìn)一步分析與研究
1. 準(zhǔn)備工作
1.1 R包安裝
library("clusterProfiler")
library("org.Hs.eg.db")
library("dplyr")
library("ggsci")
library("ggplot2")
ggsci的教程可以查看昨天的推送慧起,現(xiàn)學(xué)現(xiàn)用~[ggsci | 一行代碼擁有Sci級配色]
1.2 環(huán)境配置
關(guān)于為什么要進(jìn)行環(huán)境配置可以查看既往推送[KEGG數(shù)據(jù)庫報(bào)錯及解決]菇晃,避免KEGG富集分析中報(bào)錯。
options(clusterProfiler.download.method = "wininet")
1.3 文件準(zhǔn)備
一共需要準(zhǔn)備2個文件蚓挤,一個是差異分析結(jié)果diffSig.xls
磺送,另一個是通路關(guān)系文件KEGG_relation.xls
,本推送已整理好KEGG_relation.xls
灿意,文末有免費(fèi)獲取方式
# 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. 通路關(guān)系文件
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. 分析步驟
將差異分析結(jié)果(如1.3中的diffSig.xls)放入file
文件夾中估灿,全選運(yùn)行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可設(shè)置條形圖寬度
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)
當(dāng)然,此處輸出的是所有P<0.05
的結(jié)果缤剧,如果想要指定KEGG條目
的話馅袁,可以查看推送[如何篩選感興趣的GO和KEGG進(jìn)行繪圖~]
最終呈現(xiàn)效果
感謝觀看,如果有用還請點(diǎn)贊鞭执,關(guān)注司顿,在看,轉(zhuǎn)發(fā)兄纺!