Ontology managers

pronto

from pronto import Ontology
cl = Ontology("http://purl.obolibrary.org/obo/cl/cl-simple.obo")
len(cl.terms())
2651
term = cl["CL:0002116"]
term
Term('CL:0002116', name='B220-low CD38-positive unswitched memory B cell')
term.definition
Definition('A B220-low CD38-positive unswitched memory B cell is a CD38-positive unswitched memory B cell that has the phenotype B220-low, CD38-positive, IgD-positive, CD138-negative, and IgG-negative.', xrefs={Xref('GOC:rhs'), Xref('GOC:dsd'), Xref('PMID:20123131'), Xref('GOC:tfm')})
term.is_leaf()
True
term.obsolete
False

Owlready2

https://owlready2.readthedocs.io/en/v0.37/onto.html

from owlready2 import get_ontology
* Owlready2 * Warning: optimized Cython parser module 'owlready2_optimized' is not available, defaulting to slower Python implementation

The following cell keeps timing out.

cl = get_ontology("http://purl.obolibrary.org/obo/cl/cl-simple.owl").load()
cl_dict = {i.name: i.label[0] for i in cl.classes()}
cl.search(label="T cell")
cl_dict["CL_0000084"]
x = cl.ontology["CL_0000084"]
x = next(x)
x