Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract replaced_by mappings for obsolete terms #18

Closed
csbayrak opened this issue Nov 11, 2020 · 4 comments
Closed

Extract replaced_by mappings for obsolete terms #18

csbayrak opened this issue Nov 11, 2020 · 4 comments

Comments

@csbayrak
Copy link

csbayrak commented Nov 11, 2020

Hi, I'd like to use obonet to read HPO terms (http://purl.obolibrary.org/obo/hp.obo)
I noticed that the obsolete terms are ignored when reading the file. I'd prefer to use their corresponding updated names.

Example:

[Term]
id: HP:0000547
name: obsolete Tapetoretinal degeneration
synonym: "Retinotapetal degeneration" EXACT []
is_obsolete: true
replaced_by: HP:0000510

Is there an easy way to extract and use that mapping?

@dhimmel
Copy link
Owner

dhimmel commented Nov 11, 2020

#15 added an ignore_obsolete option to read_obo. Setting ignore_obsolete=False will retain these nodes.

I don't think ontologies generally include edges for obsolete nodes, but I'm not entirely sure.

Does this address your use case? Are you trying to do any of the following:

  1. replace obsolete HP terms with their replacements?
  2. lookup names for obsolete HP terms?

@csbayrak
Copy link
Author

Thank you for your reply!
I'm interested in getting descendants of a list of HP terms. If it is obsolete, I'd like to get the descendants of its replacement.
I guess (1) makes sense.

dhimmel added a commit that referenced this issue Nov 16, 2020
@dhimmel
Copy link
Owner

dhimmel commented Nov 16, 2020

I'm interested in getting descendants of a list of HP terms. If it is obsolete, I'd like to get the descendants of its replacement.

Sounds like you need a two step approach:

  1. replace obsolete terms in your query list with their replacements (if they have replacements, not all obsolete terms do)
  2. find descendants of the non-obsolete terms

In 0ce7c81, I update the example notebook with an example of how to create an old_to_new dictionary to map from obsolete terms to replacements. Here is the key code:

old_to_new = dict()
for node, data in graph_with_obs.nodes(data=True):
    for replaced_by in data.get("replaced_by", []):
        old_to_new[node] = replaced_by

Hopefully this helps you achieve part 1. There is also code for part 2 in the notebook.

Note that in obonet directed edges go from child to parent term, such that the networkx descendants and ancestors functions do the opposite of their usual behavior. You could always reverse all the edges using networkx.MultiDiGraph.reverse if this becomes annoying.

@csbayrak
Copy link
Author

Perfect! Thank you very much for your help. This is so helpful!

@dhimmel dhimmel changed the title obsolete terms Extract replaced_by mappings for obsolete terms Nov 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants