althonos / pronto

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

How to access property_value tags? #227

Open chrishmorris opened 4 months ago

chrishmorris commented 4 months ago

taxslim.obo has e.g.

[Term]
id: NCBITaxon:10
name: Cellvibrio
namespace: ncbi_taxonomy
xref: GC_ID:11
xref: PMID:12710603
xref: PMID:24105943
is_a: NCBITaxon:1706371 ! Cellvibrionaceae
property_value: has_rank NCBITaxon:genus

If I read it and export it again with pronto.Ontology("download/taxslim.obo").dumps(format="obo") then property_value lines correctly appear in the output, so they are clearly parsed and incorporated into the Ontology instance.

But I can't figure out how to access them. Both ontology.relationships() and ontology["NCBITaxon:10"].relationships are empty.

What am I missing, please?

althonos commented 2 weeks ago

Hi @chrishmorris,

Property values get written to the annotations of each entity, as a set of PropertyValue objects:

>>> taxslim = pronto.Ontology.from_obo_library("ncbitaxon/subsets/taxslim.obo")
>>> taxslim["NCBITaxon:10"].annotations
{ResourcePropertyValue('has_rank', 'NCBITaxon:genus')}