I have a vector of GOIDs that are specific GO IDs outputted from an enrichment analysis. I want to cluster my GOIDs by their parent GOID term. I used GOstats to do my enrichment analysis, and I have noticed there is an inducedTermGraph, which outputs a graphNEL object of direct children and direction parents of the GOIDs you query. If you set parents=TRUE and children=FALSE, your graph includes only parent nodes which relate to your GOID query.

However, how can I extract the node names of these parent nodes??? See code below:

gene.ids <- c(51141, 84968, 140850, 388289, 406994, 677828, 693217, 100287428, 
             100505685, 100506540, 101926966, 101927244, 101928659)
uids <- rnb.get.annotation("genes")
uids <- sort(unique(as.numeric(na.omit(unlist(sapply(unlist(uids)$entrezID, 
        function(i) strsplit(i, split=";")))))))
params <- new("GOHyperGParams", annotation = "org.Hs.eg.db", geneIds = gene.ids, 
             universeGeneIds = uids, ontology = "BP", conditional = TRUE, 
             testDirection = "over")

res <- tryCatch({ hyper.genes <- hyperGTest(params) }, error = function(ee) { print("Errorfests.") })

go.ids <- summary(hyper.genes)[,"GOBPID"]
result <- inducedTermGraph(hyper.genes, id=go.ids, children=FALSE, parents=TRUE)
nAttrs <- list()
z <- attributes(result)$nodes
    names(z) <- nodes(result)
    nAttrs$label <- z
plot(result, nodeAttrs=nAttrs)
  • 1
    $\begingroup$ What is this code? Is that formatting break supposed to be there? There are long winded solutions I can think of with Biopython. Could you make your input clear, and what you want your output to be. $\endgroup$ – James Apr 11 '16 at 1:51
  • $\begingroup$ If you just want to know the parent nodes of a list of GO terms, you can use GOBPPARENTS in the Bioconductor package GO.db (which you use when using GOstats). This may be a better way to manipulate this information programmatically. $\endgroup$ – ddiez Jun 21 '16 at 3:38
  • $\begingroup$ @ddiez do you have a code example of what you mean? for example if I have: terms = c("GO:0001071","GO:0005886") I can't just run this: GOMFPARENTS$terms or GOMFPARENTS(terms). $\endgroup$ – KingBoomie Oct 4 '16 at 12:50
  • $\begingroup$ @RickBeeloo see my answer below with some code. First problem you are mixing ontologies (GO:0001071 is for MF and GO:0005886 for CC). 2) You cannot access GOMFPARENTS with $ and a variable like that. 3) GOMFPARENTS is not a function so using () doesn't work either. $\endgroup$ – ddiez Oct 4 '16 at 13:50

To answer @RickBeeloo's comment above I decided to include an answer with some detailed code. Basically to obtain the ancestors of any Gene Ontology (GO) term using the Bioconductor package GO.db we need a call to the AnnDbBimap object for the adequate ontology. For example if we want it for Molecular Function (MF) we would use GOMFANCESTOR like in the example:


terms <- c("GO:0008022","GO:0001071")

[1] "GO:0005515" "GO:0003674" "GO:0005488" "all"       

[1] "GO:0003674" "all"       

Similar objects can be used for Biological process (BP) and Cellular compartment (CC): GOBPANCESTOR and GOCCANCESTOR. The only limiation is that you cannot mix terms from different ontologies (i.e. all BP, MF or CC). There are similar options to obtain the children of any given GO term (e.g. GOCCCHILDREN). The description of each term can be obtained with:

                   GO:0008022                                           GO:0001071 
 "protein C-terminus binding" "nucleic acid binding transcription factor activity" 

All available mappings can be listed calling GO():


Quality control information for GO:

This package has the following mappings:

GOBPANCESTOR has 28477 mapped keys (of 28477 keys)
GOBPCHILDREN has 16829 mapped keys (of 28477 keys)
GOBPOFFSPRING has 16829 mapped keys (of 28477 keys)
GOBPPARENTS has 28477 mapped keys (of 28477 keys)
GOCCANCESTOR has 3897 mapped keys (of 3897 keys)
GOCCCHILDREN has 1317 mapped keys (of 3897 keys)
GOCCOFFSPRING has 1317 mapped keys (of 3897 keys)
GOCCPARENTS has 3897 mapped keys (of 3897 keys)
GOMFANCESTOR has 10021 mapped keys (of 10021 keys)
GOMFCHILDREN has 2046 mapped keys (of 10021 keys)
GOMFOFFSPRING has 2046 mapped keys (of 10021 keys)
GOMFPARENTS has 10021 mapped keys (of 10021 keys)
GOOBSOLETE has 2012 mapped keys (of 2012 keys)
GOTERM has 42396 mapped keys (of 42396 keys)

Additional Information about this package:

DB schema: GO_DB
DB schema version: 2.1
Date for GO data: 20160305
  • $\begingroup$ Thankyou! I have one question you use: as.list(GOMFANCESTOR[terms]) this will give two lines of output. But which of these lines is the parent of both of the terms? @ddiez $\endgroup$ – KingBoomie Oct 4 '16 at 16:24
  • $\begingroup$ The result is a named list, the names are what follows $ in the result (e.g. $GO:0008022``). The names are the ids of the original GO terms in the variable terms. Each line shows the ancestors of the corresponding id. For example, for GO:0008022 (first id in terms) you get: "GO:0005515" "GO:0003674" "GO:0005488" "all". $\endgroup$ – ddiez Oct 5 '16 at 1:27
  • $\begingroup$ So you have to compare those by hand to get the common parent of both IDs? @ddiez $\endgroup$ – KingBoomie Oct 5 '16 at 6:49
  • $\begingroup$ I posted a question about this topic: stackoverflow.com/questions/39879936/… mabye you are interested in answering it @ddiez $\endgroup$ – KingBoomie Oct 5 '16 at 17:13

It turns out if you set the font.size in the graphNEL object, you can see the node names in the plot of the inducedTermGraph.

Setting font.size to >20 worked for me!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.