From 8e89b427efc4b4868dd75cc84b46ac2c781dfc4d Mon Sep 17 00:00:00 2001 From: Anushya Muruganujan Date: Thu, 22 Feb 2024 16:16:15 -0800 Subject: [PATCH] For #2108 --- ontobio/io/qc.py | 20 +++++++++++++++++++- tests/test_qc.py | 32 +++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/ontobio/io/qc.py b/ontobio/io/qc.py index 14cd685d..1e98761c 100644 --- a/ontobio/io/qc.py +++ b/ontobio/io/qc.py @@ -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): @@ -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(), @@ -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() }) diff --git a/tests/test_qc.py b/tests/test_qc.py index 54d05db8..af02f98c 100644 --- a/tests/test_qc.py +++ b/tests/test_qc.py @@ -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 @@ -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