row.names=FALSE 行名不輸出
或者
col.names=NA
readable= TRUE #gene ID 轉(zhuǎn)換為gene symbol
############################################################################################
#若第一次使用請先安裝clusterprofile包,若已安裝請忽略此條
# install.packages("BiocManager") ##首先安裝BiocManager,若已安裝忽略此條
#
# library(BiocManager) ##加載安裝包
#
# BiocManager::install("clusterProfiler") ##用BiocManager安裝clusterprofiler
#
# BiocManager::install("org.Mm.eg.db") ##安裝注釋文件舔箭,此為小鼠的罩缴,其他物種見后文
#
# BiocManager::install("Rgraphviz") ## 安裝作圖包
#
# BiocManager::install("topGO") ##安裝topGO
#
# BiocManager::install("pathview") ##安裝pathview
#除注釋外,所有符號必須是半角限嫌,即英文輸入靴庆,包括括號、引號等怒医,要不然會報(bào)錯
#流程:設(shè)置工作路徑----->讀取數(shù)據(jù)------->作圖-------->調(diào)整參數(shù)------>輸出圖片/數(shù)據(jù)
############################################################################################
setwd("C:/Users/zxg/Desktop/for_zyc") #設(shè)置工作目錄炉抒,可在頂部Session--set working directory---choose..
library(clusterProfiler) #加載R包
library(org.Rn.eg.db) #加載注釋包,根據(jù)物種選擇安裝并加載
library(Rgraphviz) #加載作圖包
library(topGO) #加載GO包
library(pathview) #加載pathway包
x<- read.table("brain.txt",head=FALSE) #讀取基因列表稚叹,基因ID暫定ENSEMBLE_ID,若更換類型需修改后續(xù)
genelist <- bitr(x[,1],fromType="SYMBOL", toType=c("ENTREZID"), OrgDb="org.Rn.eg.db") # id coversion
entrezid <- genelist$ENTREZID #extract entrezid
go <- enrichGO(entrezid , #gene list(entrez_id)
OrgDb = org.Rn.eg.db, #注釋信息
ont='ALL', #注釋方式
pAdjustMethod = 'BH', #富集方式
pvalueCutoff = 0.05, #p值設(shè)定
qvalueCutoff = 0.2, #q值設(shè)定
keyType = 'ENTREZID', #基因ID類型
readable= TRUE) #gene ID 轉(zhuǎn)換為gene symbol
write.table(go,file="go_AD_up.xls",sep="\t",row.names = FALSE,col.names = )
pdf("AD_up.pdf")
barplot(go,showCategory=20,drop=T,main="whole") #整體作圖焰薄,柱圖拿诸,顯示前20,前方數(shù)字可修改
dotplot(go,showCategory=20,title="whole") #整體作圖塞茅,點(diǎn)圖亩码,顯示前10,前方數(shù)字可修改
go.BP <- enrichGO(entrezid, OrgDb = org.Rn.eg.db, ont='BP', #僅BP-Biological process 富集
pAdjustMethod = 'BH',pvalueCutoff = 0.05, qvalueCutoff = 0.2,keyType = 'ENTREZID')
go.MF <- enrichGO(entrezid, OrgDb = org.Rn.eg.db, ont='MF', #僅MF-Molecular function富集
pAdjustMethod = 'BH',pvalueCutoff = 0.05, qvalueCutoff = 0.2,keyType = 'ENTREZID')
go.CC <- enrichGO(entrezid, OrgDb = org.Rn.eg.db, ont='CC', #僅CC-cell component富集
pAdjustMethod = 'BH',pvalueCutoff = 0.05, qvalueCutoff = 0.2,keyType = 'ENTREZID')
write.table(go.BP,file="BP.xls",sep="\t") #BP富集信息寫入表格野瘦,用制表符分隔描沟,文件名字file=“”可修改
write.table(go.MF,file="MF.xls",sep="\t") #MF富集信息寫入表格,用制表符分隔鞭光,文件名字file=“”可修改
write.table(go.CC,file="CC.xls",sep="\t") #CC富集信息寫入表格吏廉,用制表符分隔,文件名字file=“”可修改
barplot(go.BP,showCategory=50,drop=T,title="BP") #BP 柱圖
dotplot(go.BP,showCategory=10,title="BP") #BP 點(diǎn)圖
plotGOgraph(go.BP) #BP 無向環(huán)圖
barplot(go.MF,showCategory=10,drop=T,title="MF") #MF 柱圖
dotplot(go.MF,showCategory=10,title="MF") #MF 點(diǎn)圖
plotGOgraph(go.MF) #MF 無向環(huán)圖
barplot(go.CC,showCategory=10,drop=T,title="CC") #CC 柱圖
dotplot(go.CC,showCategory=10,title="CC") #CC 點(diǎn)圖
plotGOgraph(go.CC) #CC 無向環(huán)圖
kegg <- enrichKEGG(entrezid , #基因 entrezID
organism = 'mmu', #物種名稱,去KEGG網(wǎng)站查詢惰许,人hsa席覆,大鼠rno,小鼠mmu
#https://www.kegg.jp/kegg/catalog/org_list.html
keyType = 'kegg', #富集類型one of "kegg", 'ncbi-geneid', 'ncib-proteinid' and 'uniprot'
pvalueCutoff= 0.05, #設(shè)定p值pvalue cutoff on enrichment tests to report
qvalueCutoff = 0.05, #設(shè)定q值qvalue cutoff on enrichment tests to report as significant.
pAdjustMethod = 'BH', #富集方式one of "holm", "hochberg", "hommel", "bonferroni", "BH", "BY", "fdr", "none"
minGSSize = 10, #minimal size of genes annotated by Ontology term for testing
maxGSSize = 500, #maximal size of genes annotated for testing
use_internal_data = FALSE) #logical, use KEGG.db or latest online KEGG data
barplot(kegg,showCategory=10,drop=T) #KEGG 柱圖
dotplot(kegg,showCategory=10) #KEGG 點(diǎn)圖
plotGOgraph(kegg) #KEGG 無向環(huán)圖
dev.off()
gsecc <- gseGO(geneList=geneList, ont="CC", OrgDb=org.Mm.eg.db, verbose=F)
gseaplot(gsecc, geneSetID="GO:0000779")
pathview(gene.data=entrezid, #either vector (single sample) or a matrix-like data (multiple sample).
pathway.id = 'rno03030', #the KEGG pathway ID(s), usually 5 digit, include the 3 letter KEGG species code
species="rno", # kegg code, scientific name or the common name
limit=list(gene=max(abs(entrezid)), #a list of two numeric elements with "gene" and "cpd" as the names.
cpd=1))
#######################################################################
#物種及對應(yīng)注釋包
#packages organism
#org.Ag.eg.db Anopheles
#org.At.tair.db Arabidopsis
#org.Bt.eg.db Bovine
#org.Ce.eg.db Worm
#org.Cf.eg.db Canine
#org.Dm.eg.db Fly
#org.Dr.eg.db Zebrafish
#org.EcK12.eg.db E coli strain K12
#org.EcSakai.eg.db E coli strain Sakai
#org.Gg.eg.db Chicken
#org.Hs.eg.db Human
#org.Mm.eg.db Mouse
#org.Mmu.eg.db Rhesus
#org.Pf.plasmo.db Malaria
#org.Pt.eg.db Chimp
#org.Rn.eg.db Rat
#org.Sc.sgd.db Yeast
#org.Ss.eg.db Pig
#org.Xl.eg.db Xenopus