althonos / pronto

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

Accessing children of a relationship #177

Open manulera opened 2 years ago

manulera commented 2 years ago

Is it possible to access the children of a relationship? For example, with the method term.subclasses() I can access all the inverse is_a relationships. Is there a way to access other relationships this way? E.g regulates in GO?

I am new to the use of ontologies, so I am not sure if that's the case, but this example from the documentation seems to be doing exactly that.

go = pronto.Ontology.from_obo_library("go.obo")
go['GO:0048870']
list(go['GO:0048870'].objects(go.get_relationship('part_of')))

However, when I run it I get this:

NotImplementedWarning: `Term.objects` is not semantically correct, most of the logic rules have not been implemented. Consider using an actual reasoner instead.
  list(go['GO:0048870'].objects(go.get_relationship('part_of')))

Any tips on this?

cmungall commented 2 years ago

The warning is a little confusing, and I think it's actually a red herring/false positive.

The issue here is that GO changed since the documentation was written, and this term has no direct part-of relationships any more. The actual return value of [] is correct

Try another term, it will give results, without warning:

>>> list(go['GO:0060887'].objects(go.get_relationship('part_of')))
[Term('GO:0060173', name='limb development')]

FWIW, I usually do this:

>>> [r for r in go['GO:0060887'].relationships]
[Relationship('part_of', name='part of')]

See also #119

manulera commented 2 years ago

Hi @cmungall thanks for the detailed response and the examples, and sorry for the super-late answer. I tried your example and indeed it works. However, I think my question was not well formulated, I meant to ask whether it was possible to get the inverse relationship (what I would think of as a child). For example, for the term GO:0006366, get all these children and the relationship that links them to GO:0006366:

Screenshot 2022-07-27 at 14 07 56

manulera commented 1 year ago

HI @cmungall any advise on this?