Skip to content

Commit

Permalink
For #2108
Browse files Browse the repository at this point in the history
  • Loading branch information
mugitty committed Feb 23, 2024
1 parent 95707dd commit 8e89b42
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
20 changes: 19 additions & 1 deletion ontobio/io/qc.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
iba_eco = ecomapping.coderef_to_ecoclass("IBA")
iep_eco = ecomapping.coderef_to_ecoclass("IEP")
hep_eco = ecomapping.coderef_to_ecoclass("HEP")

iss_eco = ecomapping.coderef_to_ecoclass("ISS")
isa_eco = ecomapping.coderef_to_ecoclass("ISA")
iso_eco = ecomapping.coderef_to_ecoclass("ISO")

# TestResult = collections.namedtuple("TestResult", ["result_type", "message", "result"])
class TestResult(object):
Expand Down Expand Up @@ -896,6 +898,21 @@ def test(self, annotation: association.GoAssociation, config: assocparser.AssocP
return TestResult(repair_result(repair_state, self.fail_mode), "{}: {} should be one of {}. Repaired to {}".format(self.message(repair_state), relation, allowed_str, repaired_str), repaired_annotation)


class GoRule63(GoRule):

def __init__(self):
super().__init__("GORULE:0000063", "Annotations using ISS/ISA/ISO evidence should refer to a gene product (in the 'with' column)", FailMode.HARD)

def test(self, annotation: association.GoAssociation, config: assocparser.AssocParserConfig, group=None) -> TestResult:
evidence = str(annotation.evidence.type)
withfrom = annotation.evidence.with_support_from


if evidence in [iss_eco, isa_eco, iso_eco] and (withfrom is None or len(withfrom) == 0):
return self._result(False)

return self._result(True)

GoRules = enum.Enum("GoRules", {
"GoRule02": GoRule02(),
"GoRule06": GoRule06(),
Expand All @@ -920,6 +937,7 @@ def test(self, annotation: association.GoAssociation, config: assocparser.AssocP
"GoRule55": GoRule55(),
"GoRule58": GoRule58(),
"GoRule61": GoRule61(),
"GoRule63": GoRule63(),
# GoRule13 at the bottom in order to make all other rules clean up an annotation before reaching 13
"GoRule13": GoRule13()
})
Expand Down
32 changes: 31 additions & 1 deletion tests/test_qc.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,37 @@ def test_gorule61():
version="2.2")
test_result = qc.GoRule61().test(assoc.associations[0], config)
assert test_result.result_type == qc.ResultType.PASS

def test_go_rule_63():
# ISS with anything in withfrom
assoc = make_annotation(evidence="ISS", withfrom="BLAH:12345").associations[0]
test_result = qc.GoRule63().test(assoc, all_rules_config())
assert test_result.result_type == qc.ResultType.PASS

# ISA with anything in withfrom
assoc = make_annotation(evidence="ISA", withfrom="BLAH:12345").associations[0]
test_result = qc.GoRule63().test(assoc, all_rules_config())
assert test_result.result_type == qc.ResultType.PASS

# ISO with anything in withfrom
assoc = make_annotation(evidence="ISO", withfrom="BLAH:12345").associations[0]
test_result = qc.GoRule63().test(assoc, all_rules_config())
assert test_result.result_type == qc.ResultType.PASS

# ISS with nothing in withfrom
assoc = make_annotation(evidence="ISS", withfrom="").associations[0]
test_result = qc.GoRule63().test(assoc, all_rules_config())
assert test_result.result_type == qc.ResultType.ERROR

# ISA with with nothing in withfrom
assoc = make_annotation(evidence="ISA", withfrom="").associations[0]
test_result = qc.GoRule63().test(assoc, all_rules_config())
assert test_result.result_type == qc.ResultType.ERROR

# ISO with with nothing in withfrom
assoc = make_annotation(evidence="ISO", withfrom="").associations[0]
test_result = qc.GoRule63().test(assoc, all_rules_config())
assert test_result.result_type == qc.ResultType.ERROR

def test_all_rules():
# pass
Expand All @@ -739,7 +769,7 @@ def test_all_rules():
assoc = gafparser.to_association(a).associations[0]

test_results = qc.test_go_rules(assoc, config).all_results
assert len(test_results.keys()) == 23
assert len(test_results.keys()) == 24
assert test_results[qc.GoRules.GoRule26.value].result_type == qc.ResultType.PASS
assert test_results[qc.GoRules.GoRule29.value].result_type == qc.ResultType.PASS

Expand Down

0 comments on commit 8e89b42

Please sign in to comment.