def test_model_dates(): model_associations = [] version = "2.0" report = assocparser.Report(group="unknown", dataset="unknown") vals = [ "MGI:MGI:1915834", "", "RO:0002327", "GO:0003674", "MGI:MGI:2156816|GO_REF:0000015", "ECO:0000307", "", "", "2020-10-09", "MGI", "", "creation-date=2020-09-17|modification-date=2020-10-09|contributor-id=http://orcid.org/0000-0003-2689-5511" ] model_associations = model_associations + to_association( list(vals), report=report, version=version).associations # Different term, earlier creation-date vals[3], vals[11] = "GO:0016301", "creation-date=2011-12-13" model_associations = model_associations + to_association( list(vals), report=report, version=version).associations # Different term, no annotation properties vals[3], vals[11] = "GO:0001962", "" model_associations = model_associations + to_association( list(vals), report=report, version=version).associations builder = gocam_builder.GoCamBuilder(parser_config=PARSER_CONFIG, modelstate="test") model = builder.translate_to_model(gene="MGI:MGI:1915834", assocs=model_associations) assert model.date == "2020-10-09" assert model.creation_date == "2011-12-13" assert model.import_date == datetime.date.today().isoformat()
def make_annotation(db="blah", db_id="blah12345", db_obj_symb="blah", qualifier="", negated=False, goid="GO:1234567", references="BLAH:54321", evidence="IDA", withfrom="BLAH:12345", aspect="C", db_obj_name="", db_obj_syn="", db_obj_type="blah", taxon="taxon:12345", date="20200330", assigned_by="blah", extension="", gene_form_id="", properties="", version=None, from_gaf=True): if from_gaf: qual_parse = assocparser.Qualifier2_1() if version == "2.2": qual_parse = assocparser.Qualifier2_2() annotation = [ db, db_id, db_obj_symb, qualifier, goid, references, evidence, withfrom, aspect, db_obj_name, db_obj_syn, db_obj_type, taxon, date, assigned_by, extension, gene_form_id ] return gafparser.to_association(annotation, qualifier_parser=qual_parse) else: if version != "2.0": # Default to 1.2 if we're anything but 2.0 annotation = [ db, db_id, qualifier, goid, references, evidence, withfrom, taxon, date, assigned_by, extension, properties ] return gpadparser.to_association(annotation, version="1.2") else: annotation = [ "{}:{}".format(db, db_id), "NOT" if negated else "", qualifier, goid, references, evidence, withfrom, taxon, date, assigned_by, extension, properties ] return gpadparser.to_association(annotation, version="2.0")
def test_get_with_froms(): gpi_ents = gocam_builder.GoCamBuilder.parse_gpi( gpi_file="tests/resources/mgi2.test_entities.gpi") report = assocparser.Report(group="unknown", dataset="unknown") vals = [ "MGI:MGI:1929608", "", "RO:0001025", "GO:0005515", "MGI:MGI:3028747|PMID:14627703", "ECO:0000353", "MGI:MGI:1915834", # with/from "", "2004-04-30", "MGI", "", "creation-date=2004-04-30|modification-date=2004-04-30|contributor-id=http://orcid.org/0000-0002-9796-7693" ] result = to_association(list(vals), report=report, version="2.0") go_assoc = result.associations[0] ca_set = collapsed_assoc.CollapsedAssociationSet(GO_ONTO, gpi_ents) with_froms = ca_set.get_with_froms(go_assoc) assert len(with_froms) == 1 and \ with_froms[0].header == ["MGI:MGI:1915834"] and \ with_froms[0].line == ["MGI:MGI:1915834"] vals[6] = "MGI:MGI:1915834|FAKE:12345" result = to_association(list(vals), report=report, version="2.0") go_assoc = result.associations[0] ca_set = collapsed_assoc.CollapsedAssociationSet(GO_ONTO, gpi_ents) with_froms = ca_set.get_with_froms(go_assoc) # FAKE:12345 should be on line since not in GPI nor does it have same taxon as subject MGI:MGI:1929608 assert len(with_froms) == 2 and \ with_froms[0].header == ["MGI:MGI:1915834"] and \ with_froms[0].line == ["MGI:MGI:1915834"] and \ with_froms[1].header == [] and \ with_froms[1].line == ["FAKE:12345"] # Test merging of same-header with/from values in different order ca_set = collapsed_assoc.CollapsedAssociationSet(GO_ONTO, gpi_ents) header1 = collapsed_assoc.GoAssocWithFrom( header=["MGI:MGI:1915834", "FAKE:12345"]) header2 = collapsed_assoc.GoAssocWithFrom( header=["FAKE:12345", "MGI:MGI:1915834"]) ca_set.find_or_create_collapsed_association(go_assoc, with_from=header1) ca_set.find_or_create_collapsed_association(go_assoc, with_from=header2) assert len(ca_set.collapsed_associations ) == 1 and ca_set.collapsed_associations[0].with_froms == [ "FAKE:12345", "MGI:MGI:1915834" ]
def test_gorule57(): a = ["blah"] * 12 a[0] = "HELLO" a[1] = "123" a[2] = "contributes_to" a[3] = "GO:0003674" a[4] = "PMID:12345" a[5] = "ECO:0000501" a[7] = "taxon:2" a[8] = "20200303" a[9] = "MGI" a[10] = "" a[11] = "" res = gpadparser.to_association(a) assoc = gpadparser.to_association(a).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 = "ECO:0000320" assoc.evidence.has_supporting_reference = "PMID:21873635" test_result = qc.GoRule57().test(assoc, config) assert test_result.result_type == qc.ResultType.ERROR assoc.evidence.type = "ECO:some_garbage" assoc.evidence.has_supporting_reference = "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 make_annotation(db="blah", db_id="blah12345", db_obj_symb="blah", qualifier="", goid="GO:1234567", references="BLAH:54321", evidence="IDA", withfrom="BLAH:12345", aspect="C", db_obj_name="", db_obj_syn="", db_obj_type="blah", taxon="taxon:12345", date="20200330", assigned_by="blah", extension="", gene_form_id="", properties="", from_gaf=True): if from_gaf: annotation = [db, db_id, db_obj_symb, qualifier, goid, references, evidence, withfrom, aspect, db_obj_name, db_obj_syn, db_obj_type, taxon, date, assigned_by, extension, gene_form_id] return gafparser.to_association(annotation) else: annotation = [db, db_id, qualifier, goid, references, evidence, withfrom, taxon, date, assigned_by, extension, properties] return gpadparser.to_association(annotation)
def test_parse_interacting_taxon(): report = assocparser.Report(group="unknown", dataset="unknown") vals = [ "MGI", "MGI:1918911", "enables", "GO:0003674", "MGI:MGI:2156816|GO_REF:0000015", "ECO:0000307", "", "taxon:5678", "20100209", "MGI", "", "creation-date=2020-09-17|modification-date=2020-09-17|contributor-id=http://orcid.org/0000-0003-2689-5511" ] result = to_association(list(vals), report=report, version="1.2") assert result.associations[0].interacting_taxon == Curie( namespace="NCBITaxon", identity="5678")
def test_parse_1_2(): report = assocparser.Report(group="unknown", dataset="unknown") vals = [ "MGI", "MGI:1918911", "enables", "GO:0003674", "MGI:MGI:2156816|GO_REF:0000015", "ECO:0000307", "", "", "20100209", "MGI", "", "creation-date=2020-09-17|modification-date=2020-09-17|contributor-id=http://orcid.org/0000-0003-2689-5511" ] result = to_association(list(vals), report=report, version="1.2") assert result.skipped == 0 assert len([m for m in result.report.messages if m["level"] == "ERROR"]) == 0 assert len(result.associations) == 1
def test_parse_2_0(): version = "2.0" report = assocparser.Report(group="unknown", dataset="unknown") vals = [ "MGI:MGI:1918911", "", "RO:0002327", "GO:0003674", "MGI:MGI:2156816|GO_REF:0000015", "ECO:0000307", "", "", "2020-09-17", "MGI", "", "creation-date=2020-09-17|modification-date=2020-09-17|contributor-id=http://orcid.org/0000-0003-2689-5511" ] result = to_association(list(vals), report=report, version=version) assert result.skipped == 0 assert len([m for m in result.report.messages if m["level"] == "ERROR"]) == 0 assert len(result.associations) == 1 # Annotation_Extensions vals[10] = "BFO:0000066(CL:0000010),GOREL:0001004(CL:0000010)" result = to_association(list(vals), report=report, version=version) assert result.associations[0].object_extensions == [ConjunctiveSet([ ExtensionUnit(Curie("BFO", "0000066"), Curie("CL", "0000010")), ExtensionUnit(Curie("GOREL", "0001004"), Curie("CL", "0000010")) ])] # With_or_From vals[6] = "PR:Q505B8|PR:Q8CHK4" result = to_association(list(vals), report=report, version=version) assert result.associations[0].evidence.with_support_from == [ ConjunctiveSet([Curie("PR", "Q505B8")]), ConjunctiveSet([Curie("PR", "Q8CHK4")]) ] # Interacting taxon - this example should fail vals[7] = "Staphylococcus aureus ; NCBITaxon:1280" result = to_association(list(vals), report=report, version=version) assert len([m for m in result.report.messages if m["level"] == "ERROR"]) > 0 assert len(result.associations) == 0 # Now test valid interacting taxon value vals[7] = "NCBITaxon:1280" result = to_association(list(vals), report=report, version=version) assert result.associations[0].interacting_taxon == Curie("NCBITaxon", "1280") # Confirm non-"MGI:MGI:" IDs will parse vals[0] = "WB:WBGene00001189" result = to_association(list(vals), report=report, version=version) assert result.associations[0].subject.id == Curie("WB", "WBGene00001189") # 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"}
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