1. 程式人生 > >10、差異基因topGO富集

10、差異基因topGO富集

fir result classic packages return tsig png algorithm func

參考:http://www.biotrainee.com/thread-558-1-1.html

http://bioconductor.org/packages/3.7/bioc/

http://www.bioconductor.org/packages/release/bioc/html/topGO.html

topGO使用: 首先,我們制作準備文件,CC、BP、MF三個註釋文件,格式為:基因ID\t GO:xxx,GO:yyy(topGO.map) 然後準備我們的差異基因列表,兩列差異基因ID\t FDR。(topGO.list)

library("topGO")
geneID2GO<-readMappings(choose.files())  ##讀取所有基因註釋信息
geneNames<- names(geneID2GO)

data<-read.table(choose.files(), row.names = 1, header=TRUE,check.names =F)  ##讀取差異基因的ID
geneList<-data[,1]
names(geneList) <- rownames(data)
topDiffGenes<-function(allScore){return(allScore<0.05)}
###BP
sampleGOdata <- new("topGOdata",nodeSize = 6,ontology="BP", allGenes = geneList,annot = annFUN.gene2GO, gene2GO = geneID2GO,geneSel=topDiffGenes)
resultKS.elim <- runTest(sampleGOdata, algorithm = "elim", statistic = "ks")
allRes <- GenTable(sampleGOdata,KS = resultKS.elim,ranksOf = "classic", topNodes = attributes(resultKS.elim)$geneData[4])
write.table(allRes, file="T01_vs_T02.topGO_BP.xls", sep="\t", quote=FALSE, col.names=TRUE, row.names=FALSE)

pdf("T01_vs_T02.topGO_BP.pdf")
showSigOfNodes(sampleGOdata, score(resultKS.elim), firstSigNodes = 10, useInfo = "all")
dev.off()

png("T01_vs_T02.topGO_BP.png")
showSigOfNodes(sampleGOdata, score(resultKS.elim), firstSigNodes = 10, useInfo = "all")
dev.off()
##MF
sampleGOdata <- new("topGOdata",nodeSize = 6,ontology="MF", allGenes = geneList, annot = annFUN.gene2GO, gene2GO = geneID2GO,geneSel=topDiffGenes)
resultKS.elim <- runTest(sampleGOdata, algorithm = "elim", statistic = "ks")
allRes <- GenTable(sampleGOdata,KS = resultKS.elim,ranksOf = "classic", topNodes = attributes(resultKS.elim)$geneData[4])
write.table(allRes, file="T01_vs_T02.topGO_MF.xls", sep="\t", quote=FALSE, col.names=TRUE, row.names=FALSE)
pdf("T01_vs_T02.topGO_MF.pdf")
showSigOfNodes(sampleGOdata, score(resultKS.elim), firstSigNodes = 10, useInfo = "all")
dev.off()

png("T01_vs_T02.topGO_MF.png")
showSigOfNodes(sampleGOdata, score(resultKS.elim), firstSigNodes = 10, useInfo = "all")
dev.off()
##CC
sampleGOdata <- new("topGOdata",nodeSize = 6,ontology="CC", allGenes = geneList, annot = annFUN.gene2GO, gene2GO = geneID2GO,geneSel=topDiffGenes)
resultKS.elim <- runTest(sampleGOdata, algorithm = "elim", statistic = "ks")
allRes <- GenTable(sampleGOdata,KS = resultKS.elim,ranksOf = "classic", topNodes = attributes(resultKS.elim)$geneData[4])
write.table(allRes, file="T01_vs_T02.topGO_CC.xls", sep="\t", quote=FALSE, col.names=TRUE, row.names=FALSE)
pdf("T01_vs_T02.topGO_CC.pdf")
showSigOfNodes(sampleGOdata, score(resultKS.elim), firstSigNodes = 10, useInfo = "all")
dev.off()

png("T01_vs_T02.topGO_CC.png")
showSigOfNodes(sampleGOdata, score(resultKS.elim), firstSigNodes = 10, useInfo = "all")
dev.off()

10、差異基因topGO富集