2

这是一个非常具体的问题,但也许这里有人知道该怎么做。

我想要的是从诸如“BP”(包 GO.db)之类的本体中遍历所有 GO 术语。我不一定要递归遍历树,我对 GO 术语的评估顺序的唯一要求是,对于给定的 GO 术语,它的所有子项都在该 GO 术语之前进行了评估。

换句话说,我想构造一个GO术语的字符向量V,例如如果G_x和G_y是两个GO术语,并且G_x是G_y的父级,那么这些GO术语在V中的位置索引i_x和i_y是这样的i_x > i_y。

4

2 回答 2

1

我认为这(几乎)有效。这样做的诀窍是?unique保留重复元素的第一个实例。

编辑:经过反思,这只是在向量的开头组织具有最长路径(即具有最多代)的术语。我认为可能存在一个术语在两个分支上的情况,一个具有较短的路径,其中该术语将正确放置在长路径中,但放置在较短路径的早期。也就是说,如果您对粗略的近似表示满意...

# Root nodes for reference:
# BP = "GO:0008150"
# CC = "GO:0005575"
# MF = "GO:0003674"

GO_order <- function(node = "GO:0008150", ontology = "BP") {

    if (ontology == "BP") GOCHILDREN <- GOBPCHILDREN
    if (ontology == "CC") GOCHILDREN <- GOCCCHILDREN
    if (ontology == "MF") GOCHILDREN <- GOMFCHILDREN

    parents <- node

    # initialize output
    out <- c(parents)

    # do the following until there are no more parents
    while (any(!is.na(parents))) {  
        # Get the unique children of the parents (that aren't NA)
        children <- unique(unlist(mget(parents[!is.na(parents)], GOCHILDREN)))

        # append chldren to beginning of `out`
        # unique will keep the first instance of a duplicate 
        # (i.e. the most recent child is kept)
        out <- unique(append(children[!is.na(children)], out))

        # children become the parents of the next generation
        parents <- children
    }
    return(out)
}
于 2013-07-31T01:11:16.350 回答
0

使用 GO.db 的内部函数

GO_child <- function(node = "GO:0008150", ontology = "BP") {
  #MF = "GO:0003674", node of MF
  #BP = "GO:0008150", node of BP
  #CC = "GO:0005575", node of CC
  if (ontology == "BP") res <- GOBPOFFSPRING[[node]]
  if (ontology == "CC") res <- GOCCOFFSPRING[[node]]
  if (ontology == "MF") res <- GOMFOFFSPRING[[node]]
  return(res)
}
于 2016-12-27T19:33:38.480 回答