goatools.obo_parser module

Read and store Gene Ontology’s obo file.

class goatools.obo_parser.OBOReader(obo_file='go-basic.obo', optional_attrs=None)[source]

Bases: object

Read goatools.org’s obo file. Load into this iterable class.

Download obo from: http://geneontology.org/ontology/go-basic.obo

>>> reader = OBOReader()
>>> for rec in reader:
        print(rec)
class goatools.obo_parser.GOTerm(default_namespace='default')[source]

Bases: object

GO term, actually contain a lot more properties than interfaced here

has_parent(term)[source]

Return True if this GO object has a parent GO ID.

has_child(term)[source]

Return True if this GO object has a child GO ID.

get_all_parents()[source]

Return all parent GO IDs.

get_all_upper()[source]

Return all parent GO IDs through both ‘is_a’ and all relationships.

get_all_children()[source]

Return all children GO IDs.

get_all_lower()[source]

Return all parent GO IDs through both reverse ‘is_a’ and all relationships.

get_all_parent_edges()[source]

Return tuples for all parent GO IDs, containing current GO ID and parent GO ID.

get_all_child_edges()[source]

Return tuples for all child GO IDs, containing current GO ID and child GO ID.

get_goterms_upper()[source]

Returns a set containing parents and all relationship GO Terms.

get_goterms_upper_rels(relationship_set)[source]

Returns a set containing parents and specified relationship GO Terms.

get_goterms_lower()[source]

Returns a set containing children and all reverse-relationship GO Terms.

get_goterms_lower_rels(relationship_set)[source]

Returns a set containing children and specified reverse-relationship GO Terms.

class goatools.obo_parser.GODag(obo_file: str = 'go-basic.obo', optional_attrs: set | None = None, load_obsolete: bool = False, prt=stdout)[source]

Bases: dict

Holds the GO DAG as a dict. Loads go-basic.obo or OBO Graphs JSON (go-basic.json).

load_obo_file(obo_file, optional_attrs, load_obsolete, prt)[source]

Read obo file. Store results.

write_dag(out=stdout)[source]

Write info for all GO Terms in obo file, sorted numerically.

static id2int(go_id)[source]

Given a GO ID, return the int value.

query_term(term, verbose=False)[source]

Given a GO ID, return GO object.

paths_to_top(term, relationships=None)[source]

Returns all possible paths to the root node

Each path includes the term given. The order of the path is top -> bottom, i.e. it starts with the root and ends with the given term (inclusively).

Parameters:

  • term:

    the ID of the GO term, where the paths begin (i.e. the accession ‘GO:0003682’)

  • relationships:

    Optional. Controls which relationship types are traversed in addition to the default ‘is_a’ hierarchy. Requires the GODag to have been loaded with optional_attrs={'relationship'}.

    • None (default): traverse only ‘is_a’ parents.

    • True: traverse ‘is_a’ parents and all optional relationships (e.g. ‘part_of’, ‘regulates’, …).

    • A set or list of relationship-type strings: traverse ‘is_a’ parents plus only the listed relationship types (e.g. {'part_of'}).

Returns:

  • a list of lists of GO Terms

label_wrap(label, wrap_width)[source]
make_graph_pydot(recs, nodecolor, edgecolor, dpi, wrap_width, format='png', draw_parents=True, draw_children=True)[source]

draw AMIGO style network, lineage containing one query record.

make_graph_pygraphviz(recs, nodecolor, edgecolor, dpi, wrap_width, format='png', draw_parents=True, draw_children=True)[source]

Draw AMIGO style network, lineage containing one query record.

draw_lineage(recs, nodecolor='mediumseagreen', edgecolor='lightslateblue', dpi=96, output='GO_lineage.png', engine='pygraphviz', gml=False, draw_parents=True, draw_children=True, wrap_width=999)[source]

Draw GO DAG subplot.

update_association(association)[source]

Add the GO parents of a gene’s associated GO IDs to the gene’s association.