R:外部循环该函数不起作用

发布于 2024-11-07 14:40:21 字数 4024 浏览 0 评论 0原文

我正在 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)
}

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

后知后觉 2024-11-14 14:40:21

.getTermsDefinition(可能)未从 topGOdata 导出。

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

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

然后使用 localGetTermsDefinition 而不是 .getTermsDefinition

.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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文