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
isoperator 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 True >>> # 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
- comment (string, optional) – comments about the relationship.
- aliases (list, optional) – a list of names that are synonyms to the obo name of this relationship.
__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 u'topdown'
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.
Get all bottomup
>>> from pronto import Relationship >>> for r in Relationship.bottomup(): ... print(r) Relationship('is_a') Relationship('part_of')
Return the complementary relationship of self.
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()) Relationship('part_of') >>> print(Relationship('has_units').complement()) None
Get all topdown
>>> from pronto import Relationship >>> for r in Relationship.topdown(): ... print(r) Relationship('can_be') Relationship('has_part')
list of weak references to the object (if defined)
str – the
Relationshipserialized in an
The following guide was used: ftp://ftp.geneontology.org/pub/go/www/GO.format.obo-1_4.shtml