Term¶
-
class
pronto.
Term
[source]¶ A term, corresponding to a node in the ontology graph.
Formally a
Term
frame is equivalent to anowl:Class
declaration in OWL2 language. However, some constructs may not be possible to express in both OBO and OWL2.Term
should not be manually instantiated, but obtained from an existingOntology
instance, using either thecreate_term
or theget_term
method.-
__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: Optional[str] = None, type: Optional[pronto.synonym.SynonymType] = None, xrefs: Optional[Iterable[pronto.xref.Xref]] = None) → pronto.synonym.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
orNone
) – An optional synonym scope. Must be either EXACT, RELATED, BROAD or NARROW if given.type (
SynonymType
orNone
) – An optional synonym type. Must be declared in the header of the current ontology.xrefs (iterable of
Xref
, orNone
) – 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 theEntity.synonyms
collection.
-
property
anonymous
¶ whether or not the entity has an anonymous id.
Semantics of anonymous entities are the same as B-Nodes in RDF.
- Type
-
property
builtin
¶ whether or not the entity is built-in to the OBO format.
pronto
uses this tag on theis_a
relationship, which is the axiomatic to the OBO language but treated as a relationship in the library.- Type
-
property
created_by
¶ 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 theannotations
attribute of the entity, if any.- Type
str
or None
-
property
definition
¶ the textual 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.
- Type
str
or None
-
property
name
¶ 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
xrefs
¶ 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.
-
objects
(r: pronto.relationship.Relationship) → Iterator[pronto.term.Term][source]¶ Iterate over the terms
t
verifyingself · r · t
.Example
>>> go = pronto.Ontology.from_obo_library("go.obo") >>> go['GO:0048870'] Term('GO:0048870', name='cell motility') >>> list(go['GO:0048870'].objects(go['part_of'])) [Term('GO:0051674', name='localization of cell')]
Todo
Make
Term.objects
take in accountholds_over_chain
andtransitive_over
values of the relationship it is building an iterator with.
-
superclasses
(distance: Optional[int] = None) → Iterator[pronto.term.Term][source]¶ Get an iterator over the superclasses of this
Term
.In order to follow the semantics of
rdf:subClassOf
, which in turn respects the mathematical inclusion of subset inclusion,is_a
is defined as a transitive relationship, hencehas_subclass
is also transitive by closure property. Thereforeself
is always yielded first when calling this method.- Parameters
distance (int, optional) – The maximum distance between this node and the yielded superclass (
0
for the term itself,1
for its immediate superclasses, etc.). UseNone
to explore transitively the entire directed graph.- Yields
Term
– Superclasses of the selected term, breadth-first. The first element is always the term itself, useitertools.islice
to skip it.
Example
>>> ms = pronto.Ontology.from_obo_library("ms.obo") >>> sup = ms['MS:1000143'].superclasses() >>> next(sup) Term('MS:1000143', name='API 150EX') >>> next(sup) Term('MS:1000121', name='SCIEX instrument model') >>> next(sup) Term('MS:1000031', name='instrument model')
Note
The time complexity for this algorithm is in \(O(n)\), where \(n\) is the number of terms in the source ontology.
See also
The RDF Schema 1.1 specification, defining the
rdfs:subClassOf
property, which theis_a
relationship is translated to in OWL2 language.
-
subclasses
(distance: Optional[int] = None) → Iterator[pronto.term.Term][source]¶ Get an iterator over the subclasses of this
Term
.- Yields
Term
– Subclasses of the selected term, breadth-first. The first element is always the term itself, useitertools.islice
to skip it.
Example
>>> ms = pronto.Ontology.from_obo_library("ms.obo") >>> sub = ms['MS:1000031'].subclasses() >>> next(sub) Term('MS:1000031', name='instrument model') >>> next(sub) Term('MS:1000121', name='SCIEX instrument model') >>> next(sub) Term('MS:1000122', name='Bruker Daltonics instrument model')
Note
This method has a runtime of \(O(n^2)\) where \(n\) is the number of terms in the source ontology in the worst case. This is due to the fact that OBO and OWL only explicit superclassing relationship, so we have to build the graph of subclasses from the knowledge graph. By caching the graph however, this can be reduced to an \(O(n)\) operation.
-
is_leaf
() → bool[source]¶ Check whether the term is a leaf in the ontology.
We define leaves as nodes in the ontology which do not have subclasses since the subclassing relationship is directed and can be used to create a DAG of all the terms in the ontology.
Example
>>> ms = pronto.Ontology.from_obo_library("ms.obo") >>> ms['MS:1000031'].is_leaf() # instrument model False >>> ms['MS:1001792'].is_leaf() # Xevo TQ-S True
-
property
disjoint_from
¶ The terms declared as disjoint from this term.
Two terms are disjoint if they have no instances or subclasses in common.
-
property
intersection_of
¶ The terms or term relationships this term is an intersection of.
-