Relationship

class pronto.Relationship[source]

A relationship, constitute the edges of the ontology graph.

Also sometimes refered as typedefs, relationship types, properties or predicates. Formally equivalent to a property (either ObjectProperty or AnnotationProperty) in OWL2.

classmethod __class_getitem__(params)

Parameterizes a generic class.

At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.

However, note that this method is also called when defining generic classes in the first place with class Foo(Generic[T]): ....

__eq__(other: Any) bool

Return self==value.

__ge__(other)

Return self>=value.

__gt__(other)

Return self>value.

__hash__()

Return hash(self).

__le__(other)

Return self<=value.

__lt__(other)

Return self<value.

__repr__()

Return repr(self).

add_synonym(description: str, scope: str | None = None, type: SynonymType | None = None, xrefs: Iterable[Xref] | None = None) Synonym

Add a new synonym to the current entity.

Parameters:
  • description (str) – The alternate definition of the entity, or a related human-readable synonym.

  • scope (str or None) – An optional synonym scope. Must be either EXACT, RELATED, BROAD or NARROW if given.

  • type (SynonymType or None) – An optional synonym type. Must be declared in the header of the current ontology.

  • xrefs (iterable of Xref, or None) – A collections of database cross-references backing the origin of the synonym.

Raises:

ValueError – when given an invalid synonym type or scope.

Returns:

Synonym – A new synonym for the terms. The synonym is already added to the Entity.synonyms collection.

property alternate_ids: Set[str]

A set of alternate IDs for this entity.

Type:

set of str

property annotations: Set[PropertyValue]

Annotations relevant to the entity.

Type:

set of PropertyValue

property anonymous: bool

Whether or not the entity has an anonymous id.

Semantics of anonymous entities are the same as B-Nodes in RDF.

Type:

bool

property builtin: bool

Whether or not the entity is built-in to the OBO format.

pronto uses this tag on the is_a relationship, which is the axiomatic to the OBO language but treated as a relationship in the library.

Type:

bool

property comment: str | None

A comment about the current entity.

Comments in comment clauses are guaranteed to be conserved by OBO parsers and serializers, unlike bang comments. A non None comment is semantically equivalent to a rdfs:comment in OWL2. When parsing from OWL, several RDF comments will be merged together into a single comment clause spanning over multiple lines.

Type:

str or None

property consider: _S

A set of potential substitutes for an obsolete term.

An obsolete entity can provide one or more entities which may be appropriate substitutes, but needs to be looked at carefully by a human expert before the replacement is done.

See also

replaced_by, which provides a set of entities suitable for automatic replacement.

Type:

EntitySet

property created_by: str | None

The name of the creator of the entity, if any.

This property gets translated to a dc:creator annotation in OWL2, which has very broad semantics. Some OBO ontologies may instead use other annotation properties such as the ones found in Information Interchange Ontology, which can be accessed in the annotations attribute of the entity, if any.

Type:

str or None

property creation_date: datetime | None

The date the entity was created.

Type:

datetime or None

property definition: Definition | None

The definition of the current entity.

Definitions in OBO are intended to be human-readable text describing the entity, with some additional cross-references if possible.

Example

>>> hp = pronto.Ontology.from_obo_library("hp.obo")
>>> term = hp["HP:0009882"]
>>> term.name
'Short distal phalanx of finger'
>>> str(term.definition)
'Short distance from the end of the finger to the most distal...'
>>> sorted(term.definition.xrefs)
[Xref('HPO:probinson'), Xref('PMID:19125433')]
Type:

Definition or None

property disjoint_from: _S

The entities declared as disjoint from this entity.

Two entities are disjoint if they have no instances in common. Two entities that are disjoint cannot share any subentities, but the opposite is not always true.

Type:

EntitySet

property equivalent_to: _S

The entities declared as equivalent to this entity.

Type:

EntitySet

property id: str

The OBO identifier of the entity.

Identifiers can be either prefixed (e.g. MS:1000031), unprefixed (e.g. part_of) or given as plain URLs. Identifiers cannot be edited.

Type:

str

property name: str | None

The name of the entity.

Names are formally equivalent to rdf:label in OWL2. The OBO format version 1.4 made names optional to improve OWL interoperability, as labels are optional in OWL.

Type:

str or None

property namespace: str | None

The namespace this entity is defined in.

Type:

str or None

property obsolete: bool

Whether or not the entity is obsolete.

Hint

All OBO entities can be made obsolete through a boolean flag, and map to one or several replacements. When querying an obsolete entity, pronto will not attempt to perform any kind of replacement itself

>>> ms = pronto.Ontology.from_obo_library("ms.obo")
>>> term = ms["MS:1001414"]
>>> term
Term('MS:1001414', name='MGF scans')
>>> term.obsolete
True

To always get the up-to-date, non-obsolete entity, you could use the following snippet, going through a term replacement if there is no ambiguity

>>> while term.obsolete:
...     if len(term.replaced_by) != 1:
...         raise ValueError(f"no replacement for {term.id}")
...     term = term.replaced_by.pop()
>>> term
Term('MS:1000797', name='peak list scans')

See also

consider and replaced_by, storing some replacement options for an obsolete entity.

Type:

bool

property relationships: Relationships[_E, _S]

The links from an entity to other entities.

This property returns an object that maps a Relationship to an EntitySet (either a TermSet for Term.relationships, or a RelationshipSet for Relationship.relationships).

Hint

The mapping is mutable, so relationships can be created or removed using the usual interface of a MutableMapping.

Example

Get the MS:1000004 term (sample mass) from the Mass Spectrometry ontology:

>>> ms = pronto.Ontology.from_obo_library("ms.obo")
>>> sample_mass = ms["MS:1000004"]

Then use the relationships property to get the relevant unit from the Unit Ontology:

>>> sorted(sample_mass.relationships.keys())
[Relationship('has_units', name='has_units')]
>>> sample_mass.relationships[ms.get_relationship('has_units')]
TermSet({Term('UO:0000021', name='gram')})
Type:

Relationships

property replaced_by: _S

A set of of replacements for an obsolete term.

An obsolete entity can provide one or more replacement that can safely be used to automatically reassign instances to non-obsolete classes.

See also

consider, which provides a set of entities suitable for replacement but requiring expert curation.

Type:

EntitySet

property subsets: FrozenSet[str]

The subsets containing this entity.

Type:

frozenset of str

property synonyms: FrozenSet[Synonym]

A set of synonyms for this entity.

Type:

frozenset of Synonym

property xrefs: FrozenSet[Xref]

A set of database cross-references.

Xrefs can be used to describe an analogous entity in another vocabulary, such as a database or a semantic knowledge base.

Type:

frozenset of Xref

subproperties(distance: int | None = None, with_self: bool = True) SubpropertiesHandler[source]

Get an handle over the subproperties of this Relationship.

Parameters:
  • distance (int, optional) – The maximum distance between this relationship and the yielded subproperties (0 for the relationship itself, 1 for its immediate children, etc.). Use None to explore the entire directed graph transitively.

  • with_self (bool) – Whether or not to include the current term in the terms being yielded. RDF semantics state that the rdfs:subClassOf property is reflexive (and therefore is rdfs:subPropertyOf reflexive too by transitivity), so this is enabled by default, but in most practical cases only the distinct subproperties are desired.

superproperties(distance: int | None = None, with_self: bool = True) SuperpropertiesHandler[source]

Get an handle over the superproperties of this Relationship.

In order to follow the semantics of rdf:subPropertyOf, which in turn respects the mathematical definition of subset inclusion, is_a is defined as a transitive relationship, hence the inverse relationship is also transitive by closure property.

Parameters:
  • distance (int, optional) – The maximum distance between this relationship and the yielded subperoperties (0 for the relationship itself, 1 for its immediate parents, etc.). Use None to explore the entire directed graph transitively.

  • with_self (bool) – Whether or not to include the current term in the terms being yielded. RDF semantics state that the rdfs:subClassOf property is transitive (and therefore is rdfs:subPropertyOf transitive too), so this is enabled by default, but in most practical cases only the distinct subproperties are desired.

property antisymmetric: bool

Whether this relationship is anti-symmetric.

Type:

bool

property asymmetric: bool

Whether this relationship is asymmetric.

Type:

bool

property class_level: bool

Whether this relationship is applied at class level.

This tag affects how OBO relationship tags should be translated in OWL2: by default, all relationship tags are taken to mean an all-some relation over an instance level relation. With this flag set to True, the relationship will be translated to an owl:hasValue restriction.

Type:

bool

property cyclic: bool

Whether this relationship is cyclic.

Type:

bool

property disjoint_over: RelationshipSet

The relationships this relationships is disjoint over.

Type:

frozenset

property domain: Term | None

The domain of the relationship, if any.

Type:

Term or None

property functional: bool

Whether this relationship is functional.

Type:

bool

property inverse_functional: bool

Whether this relationship is inverse functional.

Type:

bool

property metadata_tag: bool

Whether or not this relationship is a metadata tag.

This tag affects how OBO typedefs should be translated in OWL2: by default, all typedef tags are translated to an owl:ObjectProperty. With this flag set to True, the typedef will be translated to an owl:AnnotationProperty.

Type:

bool

property holds_over_chain: FrozenSet[Tuple[Relationship, Relationship]]

The chains this relationship holds over.

Type:

frozenset of Relationship couples

property inverse_of: Relationship | None

The inverse of this relationship, if any.

Type:

Relationship or None

property intersection_of: RelationshipSet

The relations this relationship is an intersection of.

Type:

RelationshipSet

property range: Term | None

The range of the relationship, if any.

Type:

Term or None

property reflexive: bool

Whether or not the relationship is reflexive.

Type:

bool

property symmetric: bool

Whether or not the relationship is symmetric.

Type:

bool

property transitive: bool

Whether or not the relationship is transitive.

Type:

bool

property transitive_over: RelationshipSet

The relations this relationship is transitive over.

Type:

RelationshipSet