bioconductor - R and GO.db: go through all GO terms -


this specific question, maybe here knows how it.

what want go through go terms ontology such "bp" (package go.db). not want go recursively through tree, requirement have on order of evaluation of go terms given go term, it's children have been evaluated before go term.

in other words, want construct character vector v of go terms such if g_x , g_y 2 go terms, , g_x parent of g_y, indices i_x , i_y of position of these go terms in v such i_x > i_y.

i think (almost) works. trick ?unique keeps first instance of duplicated element.

edit: upon reflection, organizing terms longest path root (i.e. generations) @ beginning of vector. think there case term on 2 branches, 1 shorter path, term correctly placed long path, placed shorter path. said, if you're ok rough approximation...

# root nodes 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)      # following until there no more parents     while (any(!is.na(parents))) {           # unique children of parents (that aren't na)         children <- unique(unlist(mget(parents[!is.na(parents)], gochildren)))          # append chldren beginning of `out`         # unique keep first instance of duplicate          # (i.e. recent child kept)         out <- unique(append(children[!is.na(children)], out))          # children become parents of next generation         parents <- children     }     return(out) } 

Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -