You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As an alternative to the OWL client and OBO client, which both load ontologies by their source files, the following code could be used to directly reuse any arbitrary ontology that's available through PyOBO. Alternatively, it would be possible to use PyOBO to convert the resources to an ontology file that could then be loaded with one of the pre-existing loaders. This code was originally written in #1339, but that PR was closed since this wasn't really necessary for anything.
classPyOboClient(OntologyClient):
"""A base client for data that's been grabbed via PyOBO."""@classmethoddefupdate_by_prefix(
cls,
prefix: str,
include_relations: bool=False,
predicate: Optional[Callable[["pyobo.Term"], bool]] =None,
):
"""Update the JSON data by looking up the ontology through PyOBO."""importpyoboterms=iter(pyobo.get_ontology(prefix))
ifpredicate:
terms=filter(predicate, terms)
terms=sorted(terms, key=attrgetter("identifier"))
entries= [
{
'id': term.identifier,
'name': term.name,
'synonyms': [synonym.nameforsynonyminterm.synonyms],
'xrefs': [
dict(namespace=xref.prefix, id=xref.identifier)
forxrefinterm.xrefs
],
'alt_ids': [
alt_id.identifierforalt_idinterm.alt_ids
],
'relations': _get_pyobo_rels(term) ifinclude_relationselse {},
}
forterminterms
]
entries=prune_standard(entries)
resource_path=get_resource_path(f'{prefix}.json')
withopen(resource_path, 'w') asfile:
json.dump(entries, fp=file, indent=1, sort_keys=True)
def_get_pyobo_rels(term: "pyobo.Term"):
rv=defaultdict(list)
forparentinterm.parents:
rv["is_a"].append(parent.curie)
fortype_def, referencesinterm.relationships.items():
forreferenceinreferences:
rv[type_def.curie].append(reference.curie)
returndict(rv)
defprune_standard(entries):
returnprune_empty_entries(
entries,
{'synonyms', 'xrefs', 'alt_ids', 'relations'},
)
The text was updated successfully, but these errors were encountered:
As an alternative to the OWL client and OBO client, which both load ontologies by their source files, the following code could be used to directly reuse any arbitrary ontology that's available through PyOBO. Alternatively, it would be possible to use PyOBO to convert the resources to an ontology file that could then be loaded with one of the pre-existing loaders. This code was originally written in #1339, but that PR was closed since this wasn't really necessary for anything.
The text was updated successfully, but these errors were encountered: