Skip to content

Commit

Permalink
Merge pull request #577 from biolink/issue-576-obs-term-repair-aspect
Browse files Browse the repository at this point in the history
Repair obsolete terms before other GO rule tests; for #576
  • Loading branch information
dustine32 committed Jun 16, 2021
2 parents 2066457 + 5fb109d commit 99f1d55
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
14 changes: 7 additions & 7 deletions ontobio/io/gpadparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@ def parse_line(self, line):

assoc = parsed.associations[0]

split_line = assocparser.SplitLine(line=line, values=vals, taxon="")

valid_goid = self._validate_ontology_class_id(str(assoc.object.id), split_line)
if valid_goid is None:
return assocparser.ParseResult(line, [], True)
assoc.object.id = association.Curie.from_str(valid_goid)

go_rule_results = qc.test_go_rules(assoc, self.config)
for rule, result in go_rule_results.all_results.items():
if result.result_type == qc.ResultType.WARNING:
Expand All @@ -173,19 +180,12 @@ def parse_line(self, line):

assoc = go_rule_results.annotation # type: association.GoAssociation

split_line = assocparser.SplitLine(line=line, values=vals, taxon="")

if not self._validate_id(str(assoc.subject.id), split_line, context=ENTITY):
return assocparser.ParseResult(line, [], True)

if not self._validate_id(str(assoc.object.id), split_line, context=ANNOTATION):
return assocparser.ParseResult(line, [], True)

valid_goid = self._validate_ontology_class_id(str(assoc.object.id), split_line)
if valid_goid is None:
return assocparser.ParseResult(line, [], True)
assoc.object.id = association.Curie.from_str(valid_goid)

if not self._validate_id(str(assoc.evidence.type), split_line):
return assocparser.ParseResult(line, [], True)

Expand Down
31 changes: 31 additions & 0 deletions tests/test_gpad_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from ontobio.io import assocparser
from ontobio.model import association
from ontobio.model.association import ConjunctiveSet, ExtensionUnit, Curie
from ontobio.ontol_factory import OntologyFactory

import yaml

Expand Down Expand Up @@ -122,3 +123,33 @@ def test_parse_2_0():
# Test annotation property retrieval
contributors = result.associations[0].annotation_property_values(property_key="contributor-id")
assert set(contributors) == {"http://orcid.org/0000-0003-2689-5511"}

ALT_ID_ONT = "tests/resources/obsolete.json"

def test_aspect_fill_for_obsolete_terms():
# Test null aspect on an obsolete term
# GO:4 is obsolete and has no aspect (hasOBONamespace) in obsolete.json ontology
# GO:3 is it's replacement term
# Note that GPAD lines contain no aspect data
vals = [
"MGI",
"MGI:105128",
"involved_in",
"GO:4",
"PMID:25901318",
"ECO:0000314",
"",
"",
"20190517",
"MGI",
"",
"contributor=http://orcid.org/0000-0002-9796-7693|model-state=production|noctua-model-id=gomodel:5c4605cc00004132"
]
ont = OntologyFactory().create(ALT_ID_ONT)
config = assocparser.AssocParserConfig(ontology=ont, rule_set=assocparser.RuleSet.ALL)
parser = GpadParser(config=config)
result = parser.parse_line("\t".join(vals))
assoc = result.associations[0]

assert assoc.object.id == Curie("GO", "3") # GO:4 should be repaired to its replacement term, GO:3
assert assoc.aspect == 'P' # Aspect should not be empty

0 comments on commit 99f1d55

Please sign in to comment.