开发者

R: outside loop the function doesn't work

I'm working in R and analyze my data with topGO package. I want to rewrite the function genTable to generate my own table. To get the description of the GO terms, in the function this code will be 开发者_Go百科used:

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

Looks normal but if I run this outside the loop, the function getTermDefinition is not found. Has anyone an idea why this function is unknown outside the loop? I thought maybe because the . before the function. I don't know where is stand for.

Thanks for any help,

Lisanne

PS: here is the whole function

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)
}


.getTermsDefinition is (probably) not exported from topGOdata.

You can probably do something like (untested):

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

and then use localGetTermsDefinition instead of .getTermsDefinition

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜