althonos / pronto

A Python frontend to (Open Biomedical) Ontologies.
https://pronto.readthedocs.io
MIT License
229 stars 48 forks source link

ValueError: could not find owl:Ontology element #214

Closed h-mayorquin closed 7 months ago

h-mayorquin commented 11 months ago

The following code:

from pronto import Ontology

# cognitive_atlas_owl_url = "https://bioportal.bioontology.org/ontologies/COGAT"
cognitive_atlas_owl_location = "/home/heberto/Downloads/cogat.owl"
assert Path(cognitive_atlas_owl_location).is_file()
ontology = Ontology(cognitive_atlas_owl_location)
with open("ontology.obo", "wb") as f:
    ontology.dump(f, format="obo")

Throws the error:

Traceback (most recent call last):
  File "/home/heberto/development/ontology-matching-service/dev.py", line 19, in <module>
    ontology = Ontology(cognitive_atlas_owl_location)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/heberto/miniconda3/envs/dandi_llm_env/lib/python3.11/site-packages/pronto/ontology.py", line 283, in __init__
    cls(self).parse_from(_handle)  # type: ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/heberto/miniconda3/envs/dandi_llm_env/lib/python3.11/site-packages/pronto/parsers/rdfxml.py", line 89, in parse_from
    raise ValueError("could not find `owl:Ontology` element

This is identifical to: https://github.com/althonos/pronto/issues/68

But I am pretty sure I am using a local file. I suspect that the file is too old, I downloaded it from here:

https://bioportal.bioontology.org/ontologies/COGAT?p=summary

(the latest owl version)

Maybe there is a problem with the file and in that case a more informative error could be delivered?

althonos commented 7 months ago

Well, in that case the error is pretty self explanatory: OWL files should contain an owl:Ontology XML element with the ontology metadata, and that is not the case in the cogat.owl file that you linked.

I'm pretty sure the COGAT ontology doesn't follow the OBO format, so this library is probably not what you want to parse it, consider using an OWL-specific library such as py-horned-owl or owlready.

h-mayorquin commented 7 months ago

Thanks for your response. That makes sense.