topGO报错

在r包topgo里面绘制node图的函数是showSigOfNodes(),其中提供的第二个参数不能有0,否则会报错: showSigOfNodes()拆分之后是: sampleGOdata和score(resultKS.elim)是提供给函数的       ...

在r包topgo里面绘制node图的函数是showSigOfNodes(),其中提供的第二个参数不能有0,否则会报错:


showSigOfNodes(sampleGOdata, score(resultKS.elim), firstSigNodes = 10, useInfo = "all") 
Error in if ((n <- as.integer(n[1L])) > 0) { : 
          missing value where TRUE/FALSE needed


showSigOfNodes()拆分之后是:

##sampleGOdata和score(resultKS.elim)是提供给函数的
        GOdata <- sampleGOdata
        
       # resultKS.elim <- runTest(sampleGOdata, algorithm = "elim", statistic = "ks")
        termsP.value <- score(resultKS.elim)
        tt <- sort(termsP.value)
        sigTerms <- tt[1:10]
        ###此处存在0因此后续会产生报错###
       
        baseNodes <- names(sigTerms)
        dag <- inducedGraph(graph(GOdata), baseNodes)
        dag <- reverseArch(dag)
        termCounts <- termStat(GOdata, nodes(dag))
        pval.info <- function(whichNodes) {
          ret.val <- format.pval(termsP.value[whichNodes], digits = 3, eps = 1e-20)
          names(ret.val) <- whichNodes
          return(ret.val)
        }
        library("DBI")
        .getTermsDefinition <- function(whichTerms, ontology, numChar = 20, multipLines = FALSE) {
          
          qTerms <- paste(paste("'", whichTerms, "'", sep = ""), collapse = ",")
          retVal <- dbGetQuery(GO_dbconn(), 
                               paste("SELECT term, go_id FROM go_term WHERE ontology IN",
                                                  "('", ontology, "') AND go_id IN (", qTerms, ");",
                                     sep = ""))
          
          termsNames <- retVal$term
          names(termsNames) <- retVal$go_id
          
          if(!multipLines)
            shortNames <- paste(substr(termsNames, 1, numChar),
                                ifelse(nchar(termsNames) > numChar, '...', ''), sep = '')
          else
            shortNames <- sapply(termsNames,
                                 function(x) {
                                   a <- strwrap(x, numChar)
                                   return(paste(a, sep = "", collapse = "\\\n"))
                                 })
          
          names(shortNames) <- names(termsNames)
          
          ## return NAs for the terms that are not found in the DB and make sure the 'names' attribute is as specified
          shortNames <- shortNames[whichTerms]
          names(shortNames) <- whichTerms
          
          return(shortNames)
        }

        .pval = pval.info(nodes(dag))
        .NO.CHAR=20
        .def = .getTermsDefinition(whichTerms = nodes(dag), ontology(GOdata), numChar = .NO.CHAR)
        .counts = apply(termCounts[, c("Significant", "Annotated")], 1, paste, collapse = " / ")
        nodeInfo <- paste(.def, .pval, .counts, sep = '\\\n')
        sigNodes <- sigTerms
        wantedNodes <- names(sigTerms)
        plotFunction = GOplot
        library("Rgraphviz")
        complete.dag <- plotFunction(dag, sigNodes = sigNodes, genNodes = names(sigTerms),
                                     wantedNodes = wantedNodes, showEdges = TRUE,
                                     useFullNames = T, oldSigNodes = NULL,
                                     nodeInfo = nodeInfo)
        # 绘图
        print(complete.dag)


修改之后:

 f <- function(x) {ifelse(x > 1e-17, x, 1e-17)} # 小于e-17都改成e-17
 showSigOfNodes(sampleGOdata, f(score(resultKS.elim)), firstSigNodes = 10, useInfo = "all")#计算的时候第二个参数改成f(score(resultKS.elim))

  • 发表于 2024-01-22 11:51
  • 阅读 ( 580 )
  • 分类:R

你可能感兴趣的文章

相关问题

0 条评论

请先 登录 后评论
Ti Amo
Ti Amo

40 篇文章

作家榜 »

  1. omicsgene 680 文章
  2. 安生水 336 文章
  3. Daitoue 167 文章
  4. 生物女学霸 120 文章
  5. 红橙子 78 文章
  6. xun 74 文章
  7. CORNERSTONE 72 文章
  8. rzx 71 文章