在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))
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!