row.names=FALSE 行名不輸出
或者
col.names=NA
readable= TRUE #gene ID 轉換為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
#除注釋外,所有符號必須是半角,即英文輸入,包括括號、引號等,要不然會報錯
#流程:設置工作路徑----->讀取數據------->作圖-------->調整參數------>輸出圖片/數據
############################################################################################
setwd("C:/Users/zxg/Desktop/for_zyc") #設置工作目錄,可在頂部Session--set working directory---choose..
library(clusterProfiler) #加載R包
library(org.Rn.eg.db) #加載注釋包,根據物種選擇安裝并加載
library(Rgraphviz) #加載作圖包
library(topGO) #加載GO包
library(pathview) #加載pathway包
x<- read.table("brain.txt",head=FALSE) #讀取基因列表,基因ID暫定ENSEMBLE_ID,若更換類型需修改后續
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值設定
qvalueCutoff = 0.2, #q值設定
keyType = 'ENTREZID', #基因ID類型
readable= TRUE) #gene ID 轉換為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,前方數字可修改
dotplot(go,showCategory=20,title="whole") #整體作圖,點圖,顯示前10,前方數字可修改
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 點圖
plotGOgraph(go.BP) #BP 無向環圖
barplot(go.MF,showCategory=10,drop=T,title="MF") #MF 柱圖
dotplot(go.MF,showCategory=10,title="MF") #MF 點圖
plotGOgraph(go.MF) #MF 無向環圖
barplot(go.CC,showCategory=10,drop=T,title="CC") #CC 柱圖
dotplot(go.CC,showCategory=10,title="CC") #CC 點圖
plotGOgraph(go.CC) #CC 無向環圖
kegg <- enrichKEGG(entrezid , #基因 entrezID
organism = 'mmu', #物種名稱,去KEGG網站查詢,人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, #設定p值pvalue cutoff on enrichment tests to report
qvalueCutoff = 0.05, #設定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 點圖
plotGOgraph(kegg) #KEGG 無向環圖
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))
#######################################################################
#物種及對應注釋包
#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