Ontologies¶
|
Ontology such as the Gene Ontology or the Sequence Ontology: a directed acyclic graph of |
|
Single term in an |
- class picea.Ontology[source]¶
Ontology such as the Gene Ontology or the Sequence Ontology: a directed acyclic graph of
OntologyTermobjects stored by ID, linked byis_aandpart_ofrelationships.Examples
>>> obo = '''format-version: 1.2 ... ... [Term] ... id: SO:0000001 ... name: region ... ... [Term] ... id: SO:0000704 ... name: gene ... is_a: SO:0000001 ! region ... ''' >>> so = Ontology.from_obo(string=obo) >>> so['SO:0000704'].name ['gene'] >>> [term.ID for term in so['SO:0000001'].children] ['SO:0000704']
- classmethod from_obo(filename=None, string=None, skip_obsolete=True)[source]¶
Read an OBO formatted file or string. Exactly one of
filenameorstringmust be given.Only
[Term]stanzas are read. Parents are taken fromis_aandpart_ofrelationships. Every alternative ID (alt_id) is stored as a separate term with the same parents.
- add(element)¶
Add an element, stored by its ID
- Parameters:
element (DAGElement) – Element to add
- filter(filter_func)¶
Filter elements in the current collection based on the output of filter_func
- Parameters:
filter_func (Callable[[DAGElement], bool]) – Callable[[DagElement], bool] receives as input an element of the current collection and returns a boolean indicating whether the element should be kept (i.e. an element with a ‘True’ return value will be kept)
- Returns:
DirectedAcyclicGraph subclass with unwanted elements removed
- Return type:
DirectedAcyclicGraph
- groupby(group_func)¶
Group elements in the current collection by calling ‘group_func’ and using the results as a dictionary key
- Parameters:
group_func (Callable[[DAGElement], Hashable]) – Callable[[DagElement], Hashable] receives as input an element of the current collection and should return something that can be used as a dictionary key (i.e. it should be hashable)
- Returns:
Dictionary with keys for groups and values individual DirectedAcyclicGraph subclasses
- Return type:
DefaultDict[Hashable, DirectedAcyclicGraph]
- class picea.OntologyTerm(ID, parents, container, **kwargs)[source]¶
Single term in an
Ontology. OBO tags are stored as attributes with list values.nameanddefare always present (Nonewhen missing). Useterm["def"], sincedefis a Python keyword.- Parameters:
- property ID¶
Unique identifier of the element. Setting a new ID also updates the references of parent and child elements, and the key of the element in its container.
- property children: DirectedAcyclicGraph¶
All descendants of this element (children, their children, etc.), as a new graph of the same type as the container
- property parents: DirectedAcyclicGraph¶
All ancestors of this element (parents, their parents, etc.), as a new graph of the same type as the container