def test_go_rule08(): assoc = make_annotation(goid="GO:0006810", evidence="IEA").associations[0] test_result = qc.GoRule08().test(assoc, all_rules_config(ontology=ontology)) assert test_result.result_type == qc.ResultType.WARNING assoc.evidence.type = Curie.from_str("ECO:0000305") test_result = qc.GoRule08().test(assoc, all_rules_config(ontology=ontology)) assert test_result.result_type == qc.ResultType.WARNING assoc.object.id = Curie.from_str("GO:0007049") # do not manually annotate # evidence is IC, non IEA test_result = qc.GoRule08().test(assoc, all_rules_config(ontology=ontology)) assert test_result.result_type == qc.ResultType.WARNING assoc.evidence.type = Curie.from_str("ECO:0000501") #IEA # IEA, but on not manual, so should pass test_result = qc.GoRule08().test(assoc, all_rules_config(ontology=ontology)) assert test_result.result_type == qc.ResultType.PASS assoc.object.id = Curie.from_str("GO:0034655") # neither assoc.evidence.type = Curie.from_str("ECO:0000305") test_result = qc.GoRule08().test(assoc, all_rules_config(ontology=ontology)) assert test_result.result_type == qc.ResultType.PASS
def test_go_rules_15(): assoc = make_annotation(goid="GO:0044419", taxon="taxon:123|taxon:456").associations[0] ontology = ontol_factory.OntologyFactory().create( "tests/resources/go-interspecies-20210520.json") test_result = qc.GoRule15().test(assoc, all_rules_config(ontology=ontology)) assert test_result.result_type == qc.ResultType.PASS assoc.object.id = Curie.from_str("GO:1234567") test_result = qc.GoRule15().test(assoc, all_rules_config(ontology=ontology)) assert test_result.result_type == qc.ResultType.WARNING assoc.object.id = Curie.from_str("GO:0002812") test_result = qc.GoRule15().test(assoc, all_rules_config(ontology=ontology)) assert test_result.result_type == qc.ResultType.PASS assoc.object.id = Curie.from_str("GO:0044215") assoc.object.id = Curie.from_str("NCBITaxon:123") assoc.interacting_taxon = None # This is the important part, no interacting taxon test_result = qc.GoRule15().test(assoc, all_rules_config(ontology=ontology)) assert test_result.result_type == qc.ResultType.PASS
def test_go_rule29(): # Nov 11, 1990, more than a year old assoc = make_annotation(evidence="IEA", date="19901111").associations[0] ## Base test: old IEA. test_result = qc.GoRule29().test(assoc, assocparser.AssocParserConfig()) assert test_result.result_type == qc.ResultType.ERROR ## Pass if not IEA assoc.evidence.type = Curie.from_str("ECO:0000305") # Not IEA test_result = qc.GoRule29().test(assoc, assocparser.AssocParserConfig()) assert test_result.result_type == qc.ResultType.PASS ## Pass if only a half year old. now = datetime.datetime.now() six_months_ago = now - datetime.timedelta(days=180) assoc.date = six_months_ago.strftime("%Y%m%d") assoc.evidence.type = Curie.from_str("ECO:0000501") test_result = qc.GoRule29().test(assoc, assocparser.AssocParserConfig()) assert test_result.result_type == qc.ResultType.PASS ## Warning if a year and a half year old. eighteen_months_ago = now - datetime.timedelta(days=(30*18)) assoc.date = eighteen_months_ago.strftime("%Y%m%d") test_result = qc.GoRule29().test(assoc, assocparser.AssocParserConfig()) assert test_result.result_type == qc.ResultType.WARNING
def test_gorule30(): assoc = make_annotation(references="GO_REF:0000033").associations[0] config = assocparser.AssocParserConfig(goref_metadata={ "goref-0000033": { "authors": "Pascale Gaudet, Michael Livstone, Paul Thomas, The Reference Genome Project", "id": "GO_REF:0000033", "is_obsolete": True } }, rule_set=assocparser.RuleSet.ALL) test_result = qc.GoRule30().test(assoc, config) assert test_result.result_type == qc.ResultType.WARNING assoc.evidence.has_supporting_reference = [ Curie.from_str("GO_PAINT:0000000") ] test_result = qc.GoRule30().test(assoc, config) assert test_result.result_type == qc.ResultType.WARNING assoc.evidence.has_supporting_reference = [ Curie.from_str("FOO:123"), Curie.from_str("GO_REF:0000033") ] test_result = qc.GoRule30().test(assoc, config) assert test_result.result_type == qc.ResultType.WARNING assoc.evidence.has_supporting_reference = [Curie.from_str("FOO:123")] test_result = qc.GoRule30().test(assoc, config) assert test_result.result_type == qc.ResultType.PASS
def test_bioentities_load_from_file(): pombase = collections.BioEntities.load_from_file( "tests/resources/truncated-pombase.gpi") assert len(pombase.entities.keys()) == 199 # Has 199 gpi lines in the file assert pombase.get(Curie.from_str("PomBase:SPAC1565.04c")) == Subject( Curie.from_str("PomBase:SPAC1565.04c"), "ste4", "adaptor protein Ste4", [], "protein", Curie.from_str("NCBITaxon:4896"))
def test_gorule43(): assoc = make_annotation(references="GO_REF:0000024", evidence="ISO").associations[0] config = assocparser.AssocParserConfig(goref_metadata={ "goref-0000024": { "authors": "Pascale Gaudet, Michael Livstone, Paul Thomas, The Reference Genome Project", "id": "GO_REF:0000024", "evidence_codes": ["ECO:0000266"] } }, rule_set=assocparser.RuleSet.ALL) test_result = qc.GoRule43().test(assoc, config) assert test_result.result_type == qc.ResultType.PASS assoc.evidence.type = Curie.from_str("ECO:0000501") test_result = qc.GoRule43().test(assoc, config) assert test_result.result_type == qc.ResultType.WARNING assoc.evidence.type = Curie.from_str("ECO:0000266") assoc.evidence.has_supporting_reference = [Curie.from_str("FOO:123")] test_result = qc.GoRule43().test(assoc, config) assert test_result.result_type == qc.ResultType.PASS
def test_gorule46(): config = all_rules_config(ontology=ontology) # Self-binding, yes assoc = make_annotation(db="PomBase", db_id="SPAC25B8.17", goid="GO:0051260", withfrom="PomBase:SPAC25B8.17").associations[0] test_result = qc.GoRule46().test(assoc, config) assert test_result.result_type == qc.ResultType.PASS assoc.evidence.with_support_from = association.ConjunctiveSet.str_to_conjunctions( "PomBase:BLAH123") test_result = qc.GoRule46().test(assoc, config) assert test_result.result_type == qc.ResultType.WARNING assoc.evidence.with_support_from = association.ConjunctiveSet.str_to_conjunctions( "PomBase:SPAC25B8.17|PomBase:BLAH123") test_result = qc.GoRule46().test(assoc, config) assert test_result.result_type == qc.ResultType.PASS assoc.object.id = Curie.from_str("GO:0000123") # Not in a self-binding mode test_result = qc.GoRule46().test(assoc, config) assert test_result.result_type == qc.ResultType.PASS # Test no ontology should just pass assoc.object.id = Curie.from_str("GO:0051260") test_result = qc.GoRule46().test(assoc, all_rules_config()) assert test_result.result_type == qc.ResultType.PASS
def test_gorule57(): assoc = make_annotation(db="HELLO", db_id="123", qualifier="contributes_to", goid="GO:0003674", evidence="ECO:0000501", taxon="taxon:2", from_gaf=False).associations[0] # Look at evidence_code, reference, annotation_properties config = assocparser.AssocParserConfig(group_metadata={ "id": "mgi", "label": "Mouse Genome Informatics", "filter_out": { "evidence": ["ECO:0000501"], "evidence_reference": [ { "evidence": "ECO:0000320", "reference": "PMID:21873635" } ], "annotation_properties": ["noctua-model-id"] } }) test_result = qc.GoRule57().test(assoc, config) assert test_result.result_type == qc.ResultType.ERROR assoc.evidence.type = Curie.from_str("ECO:0000320") assoc.evidence.has_supporting_reference = [Curie.from_str("PMID:21873635")] test_result = qc.GoRule57().test(assoc, config) assert test_result.result_type == qc.ResultType.ERROR assoc.evidence.type = Curie.from_str("ECO:some_garbage") assoc.evidence.has_supporting_reference = [Curie.from_str("PMID:some_garbage")] assoc.properties = {"noctua-model-id": "some_garbage"} test_result = qc.GoRule57().test(assoc, config) assert test_result.result_type == qc.ResultType.ERROR assoc.properties = {} test_result = qc.GoRule57().test(assoc, config) assert test_result.result_type == qc.ResultType.PASS
def test_bioentities_from_gpi_2_0(): entities = collections.BioEntities.load_from_file( "tests/resources/mgi.truncated.gpi2") assert entities.get(Curie( namespace="MGI", identity="MGI:1918925")) == Subject( id=Curie.from_str("MGI:MGI:1918925"), label="0610010F05Rik", fullname=["RIKEN cDNA 0610010F05 gene"], synonyms=[], type=[Curie.from_str("SO:0001217")], taxon=Curie(namespace="NCBITaxon", identity="10090"), db_xrefs=[Curie.from_str("UniProtKB:Q68FF0")])
def test_conjunctive_set_list_to_str(): c = association.ConjunctiveSet.list_to_str([]) assert c == "" c = association.ConjunctiveSet.list_to_str( [association.ConjunctiveSet([Curie.from_str("MGI:12345")])]) assert c == "MGI:12345" c = association.ConjunctiveSet.list_to_str([ association.ConjunctiveSet( [Curie.from_str("MGI:12345"), Curie.from_str("MGI:12345")]) ]) assert c == "MGI:12345,MGI:12345" c = association.ConjunctiveSet.list_to_str([ association.ConjunctiveSet([Curie.from_str("MGI:12345")]), association.ConjunctiveSet([Curie.from_str("MGI:12345")]) ]) assert c == "MGI:12345|MGI:12345" c = association.ConjunctiveSet.list_to_str([ association.ConjunctiveSet( [Curie.from_str("MGI:12345"), Curie.from_str("DOI:333")]), association.ConjunctiveSet([Curie.from_str("GO:987")]) ]) assert c == "MGI:12345,DOI:333|GO:987"
def test_go_rule_06(): assoc = make_annotation(goid="GO:0005575", evidence="HEP", aspect="C").associations[0] test_result = qc.GoRule06().test(assoc, assocparser.AssocParserConfig(ontology=ontology)) assert test_result.result_type == qc.ResultType.ERROR assoc.aspect = "P" assoc.object.id = Curie.from_str("GO:0008150") test_result = qc.GoRule06().test(assoc, assocparser.AssocParserConfig(ontology=ontology)) assert test_result.result_type == qc.ResultType.PASS assoc.evidence.type = Curie.from_str("ECO:0000501") test_result = qc.GoRule06().test(assoc, assocparser.AssocParserConfig(ontology=ontology)) assert test_result.result_type == qc.ResultType.PASS
def test_subject_fullname(): s = association.Subject(Curie.from_str("HELLO:12345"), "Hello object", ["fullname"], [], ["protein"], association.Curie.from_str("NCBITaxon:12345")) assert "fullname" == s.fullname_field() s = association.Subject(Curie.from_str("HELLO:12345"), "Hello object", ["fullname", "another_name"], [], ["protein"], association.Curie.from_str("NCBITaxon:12345")) assert "fullname|another_name" == s.fullname_field() s = association.Subject(Curie.from_str("HELLO:12345"), "Hello object", ["fullname"], [], ["protein"], association.Curie.from_str("NCBITaxon:12345")) assert "fullname" == s.fullname_field(max=1)
def test_go_rule_07(): assoc = make_annotation(goid="GO:0003824", evidence="IPI").associations[0] test_result = qc.GoRule07().test(assoc, assocparser.AssocParserConfig(ontology=ontology)) assert test_result.result_type == qc.ResultType.WARNING assoc.object.id = Curie.from_str("GO:1234567") test_result = qc.GoRule07().test(assoc, assocparser.AssocParserConfig(ontology=ontology)) assert test_result.result_type == qc.ResultType.PASS assoc.object.id = Curie.from_str("GO:0003824") assoc.evidence.type = "ECO:0000501" # Not IPI test_result = qc.GoRule07().test(assoc, assocparser.AssocParserConfig(ontology=ontology)) assert test_result.result_type == qc.ResultType.PASS
def test_go_rule_16(): # No GO term w/ID assoc = make_annotation(evidence="IC", withfrom="BLAH:12345").associations[0] test_result = qc.GoRule16().test(assoc, all_rules_config()) assert test_result.result_type == qc.ResultType.ERROR # withfrom has GO term assoc.evidence.with_support_from = association.ConjunctiveSet.str_to_conjunctions( "GO:0023456") test_result = qc.GoRule16().test(assoc, all_rules_config()) assert test_result.result_type == qc.ResultType.PASS # Pipe assoc.evidence.with_support_from = association.ConjunctiveSet.str_to_conjunctions( "GO:0012345|BLAH:54321") test_result = qc.GoRule16().test(assoc, all_rules_config()) assert test_result.result_type == qc.ResultType.PASS # Empty withfrom assoc.evidence.with_support_from = [] test_result = qc.GoRule16().test(assoc, all_rules_config()) assert test_result.result_type == qc.ResultType.ERROR # Not IC assoc.evidence.type = Curie.from_str("ECO:0000501") assoc.evidence.with_support_from = association.ConjunctiveSet.str_to_conjunctions( "BLAH:5555555|FOO:999999") test_result = qc.GoRule16().test(assoc, all_rules_config()) assert test_result.result_type == qc.ResultType.PASS
def test_go_rules_15(): assoc = make_annotation(goid="GO:0044419", taxon="taxon:123|taxon:456").associations[0] test_result = qc.GoRule15().test(assoc, assocparser.AssocParserConfig(ontology=ontology)) assert test_result.result_type == qc.ResultType.PASS assoc.object.id = Curie.from_str("GO:1234567") test_result = qc.GoRule15().test(assoc, assocparser.AssocParserConfig(ontology=ontology)) assert test_result.result_type == qc.ResultType.WARNING assoc.object.id = Curie.from_str("GO:0044215") assoc.object.id = Curie.from_str("NCBITaxon:123") assoc.interacting_taxon = None # This is the important part, no interacting taxon test_result = qc.GoRule15().test(assoc, assocparser.AssocParserConfig(ontology=ontology)) assert test_result.result_type == qc.ResultType.PASS
def test_gorule50(): a = "PMID:21873635" assoc = make_annotation(db="HELLO", db_id="123", evidence="ISS", withfrom="HELLO:123").associations[0] test_result = qc.GoRule50().test(assoc, assocparser.AssocParserConfig()) assert test_result.result_type == qc.ResultType.WARNING assoc.subject.id = Curie.from_str("BYE:567") test_result = qc.GoRule50().test(assoc, assocparser.AssocParserConfig()) assert test_result.result_type == qc.ResultType.PASS # Not ISS, so fine to have repeated columns assoc.subject.id = Curie.from_str("HELLO:123") assoc.evidence.type = Curie.from_str("ECO:0000501") test_result = qc.GoRule50().test(assoc, assocparser.AssocParserConfig()) assert test_result.result_type == qc.ResultType.PASS
def test_bioentities_get_when_exists(): e = collections.BioEntities({ Curie("FOO", "123"): Subject(Curie("FOO", "123"), "hello", "world", [], "protien", Curie("NCBITaxon", "12345")) }) assert e.get(Curie.from_str("FOO:123")) == Subject( Curie("FOO", "123"), "hello", "world", [], "protien", Curie("NCBITaxon", "12345"))
def load_from_file(BioEntities, path: str): entities = dict() # type: Dict[Curie, Subject] try: gpi_parser = entityparser.GpiParser() with open(path) as gpi: for line in gpi: _, ents = gpi_parser.parse_line(line) for entity in ents: # entity will be a well-formed curie entity_id = Curie.from_str(entity["id"]) entities[entity_id] = Subject( entity_id, entity["label"], entity["full_name"], entity["synonyms"], entity["type"], Curie.from_str(entity["taxon"]["id"])) except Exception as e: logger.error("Failed to read GPI file: {}".format(str(e))) return BioEntities(entities)
def test_gorule37(): assoc = make_annotation(evidence="IBA", references="PMID:21873635", assigned_by="GO_Central").associations[0] test_result = qc.GoRule37().test(assoc, assocparser.AssocParserConfig()) assert test_result.result_type == qc.ResultType.PASS assoc.evidence.type = Curie.from_str("ECO:0000305") # Rule doesn't apply, not IBA test_result = qc.GoRule37().test(assoc, assocparser.AssocParserConfig()) assert test_result.result_type == qc.ResultType.PASS assoc.evidence.type = Curie.from_str("ECO:0000318") assoc.evidence.has_supporting_reference = [Curie.from_str("GO_REF:123")] # IBA, but wrong ref test_result = qc.GoRule37().test(assoc, assocparser.AssocParserConfig()) assert test_result.result_type == qc.ResultType.ERROR assoc.evidence.has_supporting_reference = [Curie.from_str("PMID:21873635")] assoc.provided_by = "Pascale" # IBA, but wrong assigned_by test_result = qc.GoRule37().test(assoc, assocparser.AssocParserConfig()) assert test_result.result_type == qc.ResultType.ERROR
def test_go_rule29(): # Nov 11, 1990, more than a year old assoc = make_annotation(evidence="IEA", date="19901111").associations[0] ## Base test: old IEA. test_result = qc.GoRule29().test(assoc, all_rules_config()) assert test_result.result_type == qc.ResultType.ERROR ## Pass if not IEA assoc.evidence.type = Curie.from_str(ic_eco) # Not IEA test_result = qc.GoRule29().test(assoc, all_rules_config()) assert test_result.result_type == qc.ResultType.PASS ## Pass if only a half year old. now = datetime.datetime.now() six_months_ago = now - datetime.timedelta(days=180) assoc.date = association.Date(six_months_ago.year, six_months_ago.month, six_months_ago.day, "") assoc.evidence.type = Curie.from_str(iea_eco) test_result = qc.GoRule29().test(assoc, all_rules_config()) assert test_result.result_type == qc.ResultType.PASS ## Warning if a year and a half year old. eighteen_months_ago = now - datetime.timedelta(days=(30 * 18)) assoc.date = association.Date(eighteen_months_ago.year, eighteen_months_ago.month, eighteen_months_ago.day, "") test_result = qc.GoRule29().test(assoc, all_rules_config()) assert test_result.result_type == qc.ResultType.WARNING ## Confirm the test can parse a YYYY-MM-DD date format from GPAD 2.0 gpad_2_0_vals = assoc.to_gpad_2_0_tsv( ) # Cheat to shortcut DB and DB_Object_ID concatenation gpad_2_0_vals[5] = iea_eco gpad_2_0_vals[8] = "1990-11-11" assoc = gpadparser.to_association(gpad_2_0_vals, version="2.0").associations[0] test_result = qc.GoRule29().test(assoc, all_rules_config()) assert test_result.result_type == qc.ResultType.ERROR
def test_go_rule02(): assoc = make_annotation(qualifier="NOT", goid="GO:0005515").associations[0] test_result = qc.GoRule02().test(assoc, all_rules_config()) assert test_result.result_type == qc.ResultType.WARNING assoc.negated = False test_result = qc.GoRule02().test(assoc, all_rules_config()) assert test_result.result_type == qc.ResultType.PASS assoc.negated = True assoc.object.id = Curie.from_str("GO:0003674") test_result = qc.GoRule02().test(assoc, all_rules_config()) assert test_result.result_type == qc.ResultType.PASS
def test_subject_types_label(): s = association.Subject(Curie.from_str("HELLO:12345"), "Hello object", ["fullname"], [], ["mRNA", "tRNA"], association.Curie.from_str("NCBITaxon:12345")) assert [Curie.from_str("SO:0000234"), Curie.from_str("SO:0000253")] == s.type
def test_conjunctive_set_str_to_conjunctions(): c = association.ConjunctiveSet.str_to_conjunctions("") assert c == [] c = association.ConjunctiveSet.str_to_conjunctions("MGI:12345") assert c == [association.ConjunctiveSet([Curie.from_str("MGI:12345")])] c = association.ConjunctiveSet.str_to_conjunctions("MGI:12345,MGI:12345") assert c == [ association.ConjunctiveSet( [Curie.from_str("MGI:12345"), Curie.from_str("MGI:12345")]) ] c = association.ConjunctiveSet.str_to_conjunctions("MGI:12345|MGI:12345") assert c == [ association.ConjunctiveSet([Curie.from_str("MGI:12345")]), association.ConjunctiveSet([Curie.from_str("MGI:12345")]) ] c = association.ConjunctiveSet.str_to_conjunctions( "MGI:12345,DOI:333|GO:987") assert c == [ association.ConjunctiveSet( [Curie.from_str("MGI:12345"), Curie.from_str("DOI:333")]), association.ConjunctiveSet([Curie.from_str("GO:987")]) ] c = association.ConjunctiveSet.str_to_conjunctions( "part_of(MGI:123),part_of(FOO:456)|has_direct_input(BAR:987)", conjunct_element_builder=lambda u: association.ExtensionUnit.from_str( u)) assert c == [ association.ConjunctiveSet([ association.ExtensionUnit(Curie.from_str("BFO:0000050"), Curie.from_str("MGI:123")), association.ExtensionUnit(Curie.from_str("BFO:0000050"), Curie.from_str("FOO:456")) ]), association.ConjunctiveSet([ association.ExtensionUnit(Curie.from_str("GOREL:0000752"), Curie.from_str("BAR:987")) ]) ] c = association.ConjunctiveSet.str_to_conjunctions( "HECK_NO,part_of(FOO:456)|has_direct_input(BAR:987)", conjunct_element_builder=lambda u: association.ExtensionUnit.from_str( u)) assert c == association.Error("HECK_NO")
def test_subject_types_unknown(): s = association.Subject(Curie.from_str("HELLO:12345"), "Hello object", ["fullname"], [], [], association.Curie.from_str("NCBITaxon:12345")) assert [Curie(namespace="CHEBI", identity="33695")] == s.type