###R code for the enrichment analysis of differential gene library(clusterProfiler) library(enrichplot) library(org.Mm.eg.db) library(org.Hs.eg.db) #GO and KEGG enrichment analysis ########main parameters: #pvalueCutoff: Adjusted pvalue cutoff on enrichment tests to report. #qvalueCutoff: Qvalue cutoff on enrichment tests to report as significant. #setReadable: Mapping ENTREZID to gene Symbol #DEGs: differentially expressed genes #resultdir: output path #GO_TERM2GENE: Mapping relationship between go_term and gene saved in Rdata format. ######## orgDb = c('org.Hs.eg.db','org.Mm.eg.db') enrich_GO_plot = function(DEGs,studyid,GO_TERM2GENE,orgDb){ go_result <- clusterProfiler::enricher(DEGs,TERM2GENE = GO_TERM2GENE,pvalueCutoff = 1,qvalueCutoff = 1) go_result = clusterProfiler::setReadable(x,orgDb,keyType="ENTREZID") GOenrich_result = go_result@result write_tsv(GOenrich_result,paste0(resultdir,studyid,'/',studyid,"_GO.tsv")) } ########main parameters: #pvalueCutoff: Adjusted pvalue cutoff on enrichment tests to report. #qvalueCutoff: Qvalue cutoff on enrichment tests to report as significant. #KEGG_TERM2GENE: Mapping relationship between KEGG_term and gene saved in Rdata format. #setReadable: Mapping ENTREZID to gene Symbol ######## enrich_KEGG_plot = function(DEGs,studyid,KEGG_TERM2GENE,orgDb){ kegg_result <- clusterProfiler::enricher(DEGs,TERM2GENE = KEGG_TERM2GENE,pvalueCutoff =1,qvalueCutoff = 1) kegg_result = clusterProfiler::setReadable(x,orgDb,keyType="ENTREZID") KEGGenrich_result = kegg_result@result write_tsv(KEGGenrich_result,paste0(resultdir,studyid,'/',studyid,"_KEGG.tsv")) }