Skip to content

Commit

Permalink
Merge pull request #634 from biolink/go-site-895-gorule-0000039-prote…
Browse files Browse the repository at this point in the history
…in-containing-complex-desc

Check if annotated term is in the complex closure
  • Loading branch information
mugitty committed May 12, 2023
2 parents c5f06bc + b5aca76 commit a2133a2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
22 changes: 17 additions & 5 deletions ontobio/io/qc.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,15 +514,27 @@ class GoRule39(GoRule):

def __init__(self):
super().__init__("GORULE:0000039", "Protein complexes can not be annotated to GO:0032991 (protein-containing complex) or its descendants", FailMode.HARD)
self.protein_containing_complex_descendents = None

def make_protein_complex_descendents_if_not_present(self, ontology: Optional[ontol.Ontology]) -> Set:
if ontology is not None and self.protein_containing_complex_descendents is None:
closure = gafparser.protein_complex_sublcass_closure(ontology)
self.protein_containing_complex_descendents = closure

return {} if self.protein_containing_complex_descendents is None else self.protein_containing_complex_descendents

def test(self, annotation: association.GoAssociation, config: assocparser.AssocParserConfig, group=None) -> TestResult:
# An implementation note: This is done by testing if the DB (column 1) is ComplexPortal.
# This will grab a subset of all actual Protein Complexes. This is noted in the rule description
# An implementation note: This is done by testing if the DB (column 1) is ComplexPortal or DB Object type (column 12) is protein_complex
db = annotation.subject.id.namespace
objecttype = annotation.subject.type
goterm = str(annotation.object.id)

fails = (db == "ComplexPortal" and goterm == "GO:0032991")
return self._result(not fails)
namespace = config.ontology.obo_namespace(goterm)

if namespace == "cellular_component":
if goterm in self.make_protein_complex_descendents_if_not_present(config.ontology):
fails = (db == "ComplexPortal" or (objecttype.namespace == "GO" and objecttype.identity == "0032991"))
return self._result(not fails)
return self._result(True)


class GoRule42(GoRule):
Expand Down
21 changes: 18 additions & 3 deletions tests/test_qc.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,18 +431,33 @@ def test_gorule37():
assert test_result.result_type == qc.ResultType.ERROR

def test_gorule39():
config = all_rules_config(ontology=ontology)
assoc = make_annotation(db="ComplexPortal", goid="GO:0032991").associations[0]

test_result = qc.GoRule39().test(assoc, all_rules_config())
test_result = qc.GoRule39().test(assoc, config)
assert test_result.result_type == qc.ResultType.ERROR

# test descendant of GO:0032991
assoc = make_annotation(db="bla", goid="GO:0005840").associations[0]
assoc.subject.type = association.map_gp_type_label_to_curie("protein_complex")
test_result = qc.GoRule39().test(assoc, config)
assert test_result.result_type == qc.ResultType.ERROR

# test protein complex
assoc = make_annotation(db="bla", goid="GO:0032991").associations[0]
assoc.subject.type=association.map_gp_type_label_to_curie("protein_complex")
test_result = qc.GoRule39().test(assoc, config)
assert test_result.result_type == qc.ResultType.ERROR

assoc.subject.id = association.Curie("FB", "1234")
test_result = qc.GoRule39().test(assoc, all_rules_config())
assoc.subject.type = association.Curie("CHEBI", "33695")
assoc.object.id = association.Curie("GO", "0032991")
test_result = qc.GoRule39().test(assoc, config)
assert test_result.result_type == qc.ResultType.PASS

assoc.subject.id = association.Curie("ComplexPortal", "12345")
assoc.object.id = association.Curie("GO", "0000023")
test_result = qc.GoRule39().test(assoc, all_rules_config())
test_result = qc.GoRule39().test(assoc, config)
assert test_result.result_type == qc.ResultType.PASS

def test_gorule42():
Expand Down

0 comments on commit a2133a2

Please sign in to comment.