zoukankan      html  css  js  c++  java
  • 10、差异基因topGO富集

    参考: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

    https://www.jianshu.com/p/9e21f2196178

    https://rpubs.com/aemoore62/TopGo_colMap_Func_Troubleshoot

    构建topGOdata对象的3个数据

    1. 基因某种ID的列表(可以有另一个对应的分数值,如p值或t统计量,或者是差异表达值)
    2. 基因的这种ID与GO的映射表,在ID为芯片的探针ID时,可以直接使用bioconductor的芯片注释包如hgu95av2.db
    3. GO的层次关系数据,这个结果可以从GO.db包获得,topGO也只支持GO.db包定义的层次结
    topGO使用:
    首先,我们制作准备文件,CC、BP、MF三个注释文件,格式为:基因ID GO:xxx,GO:yyy(topGO.map)
    然后准备我们的差异基因列表,两列差异基因ID 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)}
    1.1、###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=" ", 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()
    1.2、##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=" ", 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()
    1.3、##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=" ", 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()

    1.4、##输出每个go的基因以及注释到这个go的差异基因[可以不做这个]

    allGO =usedGO(object = sampleGOdata)

    for (gos in allGO){

    goID <-gos;

    gene.universe <- genes(sampleGOdata);

    go.genes <- genesInTerm(sampleGOdata,goID)[[1]];

    sig.genes <- sigGenes(sampleGOdata);

    file1=paste("GO-TMP_BP_sig_",gos,sep="");

    write.table(sig.genes,file=file1);

    file2=paste("GO-TMP_BP_go_",gos,sep="");

    write.table(go.genes,file=file2);

    }

    2、来自生信技能树

    ###BP
    sampleGOdata <- new("topGOdata",nodeSize = 6,ontology="BP", allGenes = geneList,annot = annFUN.gene2GO, gene2GO = geneID2GO,geneSel=topDiffGenes)

    allGO =usedGO(object = sampleGOdata)

    resultCFis<-runTest(sampleGOdata,algorithm="classic",statistic="fisher")

    gtFis<-GenTable(sampleGOdata,classicFisher=resultCFis,orderBy="classic",ranksOf="classicFisher",topNodes=length(allGO))

    fdr<-p.adjust(p=gtFis[,"classicFisher"],method="fdr")

    r <-cbind(gtFis,fdr)

    write.table(r,file="topGO_BP.xls",sep=" ")

    showSigOfNodes(GOdata,score(resultCFis),firstSigNodes= 5, useInfo = "all")

  • 相关阅读:
    堆排序算法
    二叉树的创建、遍历(递归和非递归实现)、交换左右子数、求高度(c++实现)
    hdoj1010 奇偶剪枝+DFS
    常见排序算法c++总结
    B
    C
    D
    E
    G
    F
  • 原文地址:https://www.cnblogs.com/renping/p/9502514.html
Copyright © 2011-2022 走看看