R:外部循环功能不起作用

时间:2011-05-18 08:12:38

标签: function r loops

我在R工作,用topGO包分析我的数据。 我想重写函数genTable来生成我自己的表。 要获得GO术语的描述,将在函数中使用此代码:

shortNames <- .getTermsDefinition(whichTerms, ontology(sampleGOdata),numChar = 40)

看起来很正常但是如果我在循环外运行它,则找不到函数getTermDefinition。有没有人知道为什么这个函数在循环之外是未知的?我想也许是因为。在功能之前。我不知道在哪里代表。

感谢您的帮助,

Lisanne

PS:这是整个功能

allRes <- GenTable(sampleGOdata, classicFisher = resultFisher, orderBy = "fisher", ranksOf = "classicFisher",topNodes = 10)

getMethod("GenTable","topGOdata")                             
function (object, ...) 
{                      
.local <- function (object, ..., orderBy = 1, ranksOf = 2, 
    topNodes = 10, numChar = 40, format.FUN = format.pval, 
    decreasing = FALSE, useLevels = FALSE)                 
{                                                          
    resList <- list(resultFisher)  
    #checkt of de resList een topGOresult is. Zo nietm stopt de functie.                                 
    if (!all(sapply(resList, is, "topGOresult")))          
        stop("Use: topGOdata, topGOresult_1, topGOresult_2, ..., \"parameters\".")
    if (is.null(names(resList)))                                                  
        names(resList) <- paste("result", 1:length(resList),                      
            sep = "")      
    #geeft lijst met alle scores (0 en 1 omdat het een factor is)                                                        
    resList <- lapply(resList, score)                                             
    if (length(resList) == 1) {                                                   
        orderBy <- ranksOf <- 1 
        #dataframe van alle gebruikte GO terms met bijbehorende score                                                  
        l <- data.frame(resList)                                                  
        names(l) <- ifelse(is.null(names(resList)), "", names(resList))
    }
    else {
        l <- .sigAllMethods(resList)
    }
    index <- order(l[, orderBy], decreasing = FALSE)
    l <- l[index, , drop = FALSE]
    if (FALSE)
        rr <- rank(-l[, ranksOf], ties = "first")
    else rr <- rank(l[, ranksOf], ties = "first")
    #selecteer de 10 meest significante nodes.
    whichTerms <- rownames(l)[1:10]
    # top 10 combinatie GO nummer en p waarden
    l <- l[whichTerms, , drop = FALSE]
    # De getallen worden geselecteerd van de 10 nodes met een interessante pwaarden
    rr <- as.integer(rr[1:10])
    # getTermsDefinition geeft de beschrijving van de 10 nodes
    shortNames <- .getTermsDefinition(whichTerms, ontology(sampleGOdata),
        numChar = 40)
    infoMat <- data.frame(`GO ID` = whichTerms, #Term = shortNames,
        stringsAsFactors = FALSE)
    if (useLevels) {
        nodeLevel <- buildLevels(graph(sampleGOdata), leafs2root = TRUE)
        #geeft aan hoeveel genes of probes er tot differentiale expressie komen voor de GO term
        nodeLevel <- unlist(mget(whichTerms, envir = nodeLevel$nodes2level))
        #dataframe met GO.ID en levels
        infoMat <- data.frame(infoMat, Level = as.integer(nodeLevel))
    }
    #annoStat geeft een dataframe met de GO.ID, annotated genes(aantal), significant(aantal) en exprected(aantal)
    annoStat <- termStat(sampleGOdata, whichTerms)
    if (ranksOf != orderBy) {
        dim(rr) <- c(length(rr), 1)
        colnames(rr) <- paste("Rank in ", ifelse(is.character(ranksOf),
            ranksOf, colnames(l)[ranksOf]), sep = "")
        infoMat <- data.frame(infoMat, annoStat, rr, apply(l,
            2, format.FUN, dig = 2, eps = 1e-30), check.names = FALSE,
            stringsAsFactors = FALSE)
    }
    else {
        infoMat <- data.frame(infoMat, annoStat, apply(l,
            2, format.pval, dig = 2, eps = 1e-30), check.names = FALSE,
            stringsAsFactors = FALSE)
    }
    rownames(infoMat) <- 1:length(whichTerms)
    return(infoMat)
}
.local(sampleGOdata, resultFisher)
}

1 个答案:

答案 0 :(得分:4)

.getTermsDefinition(可能)不会从topGOdata导出。

您可以执行类似(未经测试)的操作:

localGetTermsDefinition<-getFromNamespace(".getTermsDefinition", "topGOdata")

然后使用localGetTermsDefinition代替.getTermsDefinition