2021-10-10
rm(list = ls())
setwd("D:/R/R-4.0.5/bin/project_writing/LIM/GO")
#BiocManager::install("clusterProfiler")
library(clusterProfiler)
##
## clusterProfiler v4.0.5 For help: https://yulab-smu.top/biomedical-knowledge-mining-book/
##
## If you use clusterProfiler in published research, please cite:
## T Wu, E Hu, S Xu, M Chen, P Guo, Z Dai, T Feng, L Zhou, W Tang, L Zhan, X Fu, S Liu, X Bo, and G Yu. clusterProfiler 4.0: A universal enrichment tool for interpreting omics data. The Innovation. 2021, 2(3):100141. doi: 10.1016/j.xinn.2021.100141
##
## 载入程辑包:'clusterProfiler'
## The following object is masked from 'package:stats':
##
## filter
library(ggplot2)
library(enrichplot)
library(GOplot)
## 载入需要的程辑包:ggdendro
## 载入需要的程辑包:gridExtra
## 载入需要的程辑包:RColorBrewer
library(stringr)
#只要输入基因列表即可
glist <-read.table("glist62.txt",header = F)
glist <- glist$V1
#转化为'ENTREZID'
gene <- bitr(glist,fromType = 'SYMBOL',toType = 'ENTREZID',OrgDb = 'org.Hs.eg.db')
## 载入需要的程辑包:org.Hs.eg.db
## 载入需要的程辑包:AnnotationDbi
## 载入需要的程辑包:stats4
## 载入需要的程辑包:BiocGenerics
## 载入需要的程辑包:parallel
##
## 载入程辑包:'BiocGenerics'
## The following objects are masked from 'package:parallel':
##
## clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
## clusterExport, clusterMap, parApply, parCapply, parLapply,
## parLapplyLB, parRapply, parSapply, parSapplyLB
## The following object is masked from 'package:gridExtra':
##
## combine
## The following objects are masked from 'package:stats':
##
## IQR, mad, sd, var, xtabs
## The following objects are masked from 'package:base':
##
## anyDuplicated, append, as.data.frame, basename, cbind, colnames,
## dirname, do.call, duplicated, eval, evalq, Filter, Find, get, grep,
## grepl, intersect, is.unsorted, lapply, Map, mapply, match, mget,
## order, paste, pmax, pmax.int, pmin, pmin.int, Position, rank,
## rbind, Reduce, rownames, sapply, setdiff, sort, table, tapply,
## union, unique, unsplit, which.max, which.min
## 载入需要的程辑包:Biobase
## Welcome to Bioconductor
##
## Vignettes contain introductory material; view with
## 'browseVignettes()'. To cite Bioconductor, see
## 'citation("Biobase")', and for packages 'citation("pkgname")'.
## 载入需要的程辑包:IRanges
## 载入需要的程辑包:S4Vectors
##
## 载入程辑包:'S4Vectors'
## The following object is masked from 'package:clusterProfiler':
##
## rename
## The following object is masked from 'package:base':
##
## expand.grid
##
## 载入程辑包:'IRanges'
## The following object is masked from 'package:clusterProfiler':
##
## slice
## The following object is masked from 'package:grDevices':
##
## windows
##
## 载入程辑包:'AnnotationDbi'
## The following object is masked from 'package:clusterProfiler':
##
## select
##
## 'select()' returned 1:1 mapping between keys and columns
#GO富集
GO <- enrichGO(
gene$ENTREZID,
OrgDb = 'org.Hs.eg.db',
keyType = "ENTREZID",
ont = "ALL",
pvalueCutoff = 0.05,
pAdjustMethod = "BH",
qvalueCutoff = 0.05,
minGSSize = 10,
maxGSSize = 500,
readable = TRUE
)
#KEGG富集
KEGG <- enrichKEGG(
gene$ENTREZID,
organism = "hsa",#用到是数据是人的组织数据
keyType = "kegg",
pvalueCutoff = 0.05,
pAdjustMethod = "BH",
minGSSize = 5,
maxGSSize = 500,
qvalueCutoff = 0.2,
use_internal_data = FALSE)
## Reading KEGG annotation online:
## Reading KEGG annotation online:
#绘图
#GO聚类条形图
barplot(GO, split="ONTOLOGY")+
facet_grid(ONTOLOGY~., scales = "free")

#GO聚类气泡图
dotplot(GO, split="ONTOLOGY")+
facet_grid(ONTOLOGY~., scales ="free")

#KEGG聚类条形图
barplot(KEGG,showCategory = 40,title = 'KEGG Pathway')

#网络图
#GO通路-基因网络图
enrichplot::cnetplot(GO,circular=TRUE,colorEdge = TRUE)

#KEGG通路-基因网络图
enrichplot::cnetplot(KEGG,circular=TRUE,colorEdge = TRUE)
