How to traverse to GO parents and ancestors

Traverse immediate parents or all ancestors with or without user-specified optional relationships

  • Parents and Ancestors described

  • Code to get Parents and Ancestors

    • Get parents through is_a relationship

    • Get parents through is_a relationship and optional relationship, regulates.

    • Get ancestors through is_a relationship

    • Get ancestors through is_a relationship and optional relationship, regulates.

Parents and Ancestors

Parents

Parents are terms directly above a GO term

The yellow term, regulation of metabolic process, has one or two parents.

    1. If using only the default is_a relationship, the only parent is circled in green:

    • regulation of biological process

    1. If adding the optional relationship, regulates, the two parents are circled in purple:

    • regulation of biological process

    • metabolic process

Ancestors

Ancestors are all terms above a GO term, traversing up all of the GO hierarchy.

    1. If adding the optional relationship, regulates, there are four ancestors are circled in blue:

    • biological_process

    • biological regulation

    • regulation of biological process

    • metabolic process

  • If using only the default is_a relationship, there are three ancestors (not circled)

    • biological_process

    • biological regulation

    • regulation of biological process

parents_and_ancestors

Code to get Parents and Ancestors

import os
from goatools.obo_parser import GODag

# Load a small test GO DAG and all the optional relationships,
# like 'regulates' and 'part_of'
godag = GODag('../tests/data/i126/viral_gene_silence.obo',
              optional_attrs={'relationship'})
../tests/data/i126/viral_gene_silence.obo: fmt(1.2) rel(2019-04-17) 79 GO Terms; optional_attrs(relationship)

Get parents through is_a relationship

Parent is circled in green

GO_ID = 'GO:0019222'  # regulation of metabolic process
from goatools.godag.go_tasks import get_go2parents

optional_relationships = set()
go2parents_isa = get_go2parents(godag, optional_relationships)
print('{GO} parent: {P}'.format(
    GO=GO_ID,
    P=go2parents_isa[GO_ID]))
GO:0019222 parent: {'GO:0050789'}

Get parents through is_a relationship and optional relationship, regulates

Parents are circled in purple

optional_relationships = {'regulates', 'negatively_regulates', 'positively_regulates'}
go2parents_reg = get_go2parents(godag, optional_relationships)
print('{GO} parents: {P}'.format(
    GO=GO_ID,
    P=go2parents_reg[GO_ID]))
GO:0019222 parents: {'GO:0050789', 'GO:0008152'}

Get ancestors through is_a relationship

Not circled, but can be seen in figure

from goatools.gosubdag.gosubdag import GoSubDag

gosubdag_r0 = GoSubDag([GO_ID], godag, prt=None)
print('{GO} ancestors: {P}'.format(
    GO=GO_ID,
    P=gosubdag_r0.rcntobj.go2ancestors[GO_ID]))
GO:0019222 ancestors: {'GO:0050789', 'GO:0008150', 'GO:0065007'}

Get ancestors through is_a relationship and optional relationship, regulates

Circles in blue

gosubdag_r1 = GoSubDag([GO_ID], godag, relationships=optional_relationships, prt=None)
print('{GO} ancestors: {P}'.format(
    GO=GO_ID,
    P=gosubdag_r1.rcntobj.go2ancestors[GO_ID]))
GO:0019222 ancestors: {'GO:0008150', 'GO:0065007', 'GO:0050789', 'GO:0008152'}