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

Added ability to include nodes marked as obsolete #15

Merged
merged 6 commits into from
Sep 27, 2020
7 changes: 5 additions & 2 deletions obonet/read.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .io import open_read_file


def read_obo(path_or_file):
def read_obo(path_or_file, ignore_obsolete=True):
"""
Return a networkx.MultiDiGraph of the ontology serialized by the
specified path or file.
Expand All @@ -19,6 +19,9 @@ def read_obo(path_or_file):
path_or_file : str or file
Path, URL, or open file object. If path or URL, compression is
inferred from the file extension.
ignore_obsolete : boolean
When true (default), terms that are marked 'is_obsolete' will
not be added to the graph.
"""
obo_file = open_read_file(path_or_file)
typedefs, terms, instances, header = get_sections(obo_file)
Expand All @@ -32,7 +35,7 @@ def read_obo(path_or_file):
edge_tuples = list()

for term in terms:
is_obsolete = term.get('is_obsolete', 'false') == 'true'
is_obsolete = ignore_obsolete and term.get('is_obsolete', 'false') == 'true'
if is_obsolete:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps keep is_obsolete = term.get('is_obsolete', 'false') == 'true' but change the next line to:

if ignore_obsolete and is_obsolete:

continue
term_id = term.pop('id')
Expand Down