class pronto.Relationship

A Relationship object.

The Relationship class actually behaves as a factory, creating new relationships via the default Python syntax only if no relationship of the same name are present in the class py:attribute::_instances (a dictionnary containing memoized relationships).

Relationships are each singletons, so you can use the is operator to check for equality between relationships.


Relationships are pickable and always refer to the same adress even after being pickled and unpickled, but that requires to use at least pickle protocol 2 (which is not default on Python 2, so take care !):

>>> import pronto
>>> import io, pickle
>>> src = io.BytesIO()
>>> p = pickle.Pickler(src, pickle.HIGHEST_PROTOCOL)
>>> isa = pronto.Relationship('is_a')
>>> isa_id = id(isa)
>>> p.dump(isa)
>>> dst = io.BytesIO(src.getvalue())
>>> u = pickle.Unpickler(dst)
>>> new_isa = u.load()
>>> id(new_isa) == isa_id
>>> # what's that black magic ?!
__init__(obo_name, symmetry=None, transitivity=None, reflexivity=None, complementary=None, prefix=None, direction=None, comment=None, aliases=None)

Instantiate a new relationship.

  • obo_name (str) – the name of the relationship as it appears in obo files (such as is_a, has_part, etc.)
  • symetry (bool or None) – the symetry of the relationship
  • transitivity (bool or None) – the transitivity of the relationship.
  • reflexivity (bool or None) – the reflexivity of the relationship.
  • complementary (string or None) – if any, the obo_name of the complementary relationship.
  • direction (string, optional) – if any, the direction of the relationship (can be ‘topdown’, ‘bottomup’, ‘horizontal’). A relationship with a direction set as ‘topdown’ will be counted as _childhooding_ when acessing Term.children.
  • comment (string, optional) – comments about the relationship.
  • aliases (list, optional) – a list of names that are synonyms to the obo name of this relationship.


For symetry, transitivity, reflexivity, the allowed values are the following:

  • True for reflexive, transitive, symmetric
  • False for areflexive, atransitive, asymmetric
  • None for non-reflexive, non-transitive, non-symmetric
static __new__(cls, obo_name, *args, **kwargs)

Create a relationship or returning an already existing one.

This allows to do the following:

>>> Relationship('has_part').direction

The Python syntax is overloaded, and what looks like a object initialization in fact retrieves an existing object with all its properties already set. The Relationship class behaves like a factory of its own objects !


  • Add a warning for unknown relationship (the goal being to instantiate every known ontology relationship and even allow instatiation of file-defined relationships).

Return a string reprensentation of the relationship.

classmethod bottomup()

Get all bottomup Relationship instances.


>>> from pronto import Relationship
>>> for r in Relationship.bottomup():
...    print(r)

Return the complementary relationship of self.

Raises:ValueError – if the relationship has a complementary which was not defined.
Returns:the complementary relationship.
Return type:complementary (Relationship)


>>> from pronto.relationship import Relationship
>>> print(Relationship('has_part').complement())
>>> print(Relationship('has_units').complement())
classmethod topdown()

Get all topdown Relationship instances.



>>> from pronto import Relationship
>>> for r in Relationship.topdown():
...    print(r)

list of weak references to the object (if defined)


str – the Relationship serialized in an [Typedef] stanza.