TermSet

class pronto.TermSet[source]

A specialized mutable set to store Term instances.

__eq__(other)

Return self==value.

__ge__(other)

Return self>=value.

__gt__(other)

Return self>value.

__le__(other)

Return self<=value.

__lt__(other)

Return self<value.

classmethod _from_iterable(it)

Construct an instance of the class from any iterable input.

Must override this method if the class constructor signature does not accept an iterable for an input.

_hash()

Compute the hash value of a set.

Note that we don’t define __hash__: not all sets are hashable. But if you define a hashable set type, its __hash__ should call this function.

This must be compatible __eq__.

All sets ought to compare equal if they contain the same elements, regardless of how they are implemented, and regardless of the order of the elements; so there’s not much freedom for __eq__ or __hash__. We match the algorithm used by the built-in frozenset type.

isdisjoint(other)

Return True if two sets have a null intersection.

__repr__()[source]

Return repr(self).

add(term: pronto.term.Term) → None[source]

Add an element.

clear() → None[source]

This is slow (creates N new iterators!) but effective.

discard(term: pronto.term.Term) → None[source]

Remove an element. Do not raise an exception if absent.

pop() → pronto.term.Term[source]

Return the popped value. Raise KeyError if empty.

remove(term: pronto.term.Term)[source]

Remove an element. If not a member, raise a KeyError.

subclasses(distance: Optional[int] = None, with_self: bool = True) → pronto.logic.subclasses.SubclassesIterator[source]

Get an iterator over the subclasses of all terms in the set.

superclasses(distance: Optional[int] = None, with_self: bool = True) → pronto.logic.subclasses.SubclassesIterator[source]

Get an iterator over the superclasses of all terms in the set.

Example

>>> ms = pronto.Ontology("ms.obo")
>>> s = pronto.TermSet({ms['MS:1000122'], ms['MS:1000124']})
>>> s.superclasses(with_self=False).to_set().ids
frozenset({'MS:1000031'})
>>> ms["MS:1000031"]
Term('MS:1000031', name='instrument model')