From 19b72a0a68e790963ba5a180669fac4d8f0baec3 Mon Sep 17 00:00:00 2001 From: Anushya Muruganujan Date: Thu, 18 Jul 2024 18:26:02 -0700 Subject: [PATCH] For #2210 --- ontobio/io/assocparser.py | 2 +- tests/test_gafparser.py | 18 +++++++++++++++ tests/test_gpad_parser.py | 48 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 66 insertions(+), 2 deletions(-) diff --git a/ontobio/io/assocparser.py b/ontobio/io/assocparser.py index 103b8a7e..531ba56c 100644 --- a/ontobio/io/assocparser.py +++ b/ontobio/io/assocparser.py @@ -826,7 +826,7 @@ def _validate_id(self, id, line: SplitLine, allowed_ids=None, context=None): type_name_regex_patterns = self.config.db_type_name_regex_id_syntax[id_prefix] identity_matches_pattern = False for regex in type_name_regex_patterns.values(): - if regex.match(right): + if regex.fullmatch(right): identity_matches_pattern = True break if identity_matches_pattern == False: diff --git a/tests/test_gafparser.py b/tests/test_gafparser.py index 1ee74396..53e99bfa 100644 --- a/tests/test_gafparser.py +++ b/tests/test_gafparser.py @@ -638,6 +638,24 @@ def test_id_syntax(): messages = p.report.to_report_json()["messages"] assert len(messages["gorule-0000027"]) == 1 assert messages["gorule-0000027"][0]["obj"] == "PMID:PMID:18422602" + + p = GafParser(config=assocparser.AssocParserConfig( + ontology=OntologyFactory().create(ONT), db_type_name_regex_id_syntax=database_id_syntax_lookups)) + assoc_result = p.parse_line("PomBase\tSPBC1289.03c\tspi1\t\tGO:0005515\tPMID:0.\tIPI\tPomBase:SPAC25A8.01c\tF\tRan GTPase Spi1\t\tprotein\ttaxon:4896\t20080718\tPomBase\t") + assert len(assoc_result.associations) == 1 + assert assoc_result.skipped == False + messages = p.report.to_report_json()["messages"] + assert len(messages["gorule-0000027"]) == 1 + assert messages["gorule-0000027"][0]["obj"] == "PMID:0." + + p = GafParser(config=assocparser.AssocParserConfig( + ontology=OntologyFactory().create(ONT), db_type_name_regex_id_syntax=database_id_syntax_lookups)) + assoc_result = p.parse_line("PomBase\tSPBC1289.03c\tspi1\t\tGO:0005515\tPMID:x18422602\tIPI\tPomBase:SPAC25A8.01c\tF\tRan GTPase Spi1\t\tprotein\ttaxon:4896\t20080718\tPomBase\t") + assert len(assoc_result.associations) == 1 + assert assoc_result.skipped == False + messages = p.report.to_report_json()["messages"] + assert len(messages["gorule-0000027"]) == 1 + assert messages["gorule-0000027"][0]["obj"] == "PMID:x18422602" p = GafParser(config=assocparser.AssocParserConfig( ontology=OntologyFactory().create(ONT), db_type_name_regex_id_syntax=database_id_syntax_lookups)) diff --git a/tests/test_gpad_parser.py b/tests/test_gpad_parser.py index c331a8ea..0ceb3d0b 100644 --- a/tests/test_gpad_parser.py +++ b/tests/test_gpad_parser.py @@ -382,7 +382,53 @@ def test_id_syntax(): assert result.skipped == False messages = p.report.to_report_json()["messages"] assert len(messages["gorule-0000027"]) == 1 - assert messages["gorule-0000027"][0]["obj"] == "PMID:PMID:15494018" + assert messages["gorule-0000027"][0]["obj"] == "PMID:PMID:15494018" + + vals = ["PomBase", + "SPAC25A8.01c", + "acts_upstream_of_or_within", + "GO:0007155", + "PMID:9.", + "ECO:0000305", + "GO:0005913", + "", + "20041026", + "ZFIN", + "", + "PomBase" + ] + + p = GpadParser(config=config) + result = p.parse_line("\t".join(vals)) + assert len(result.associations) == 1 + assert result.skipped == False + messages = p.report.to_report_json()["messages"] + assert len(messages["gorule-0000027"]) == 1 + assert messages["gorule-0000027"][0]["obj"] == "PMID:9." + + + vals = ["PomBase", + "SPAC25A8.01c", + "acts_upstream_of_or_within", + "GO:0007155", + "PMID:a1549418", + "ECO:0000305", + "GO:0005913", + "", + "20041026", + "ZFIN", + "", + "PomBase" + ] + + p = GpadParser(config=config) + result = p.parse_line("\t".join(vals)) + assert len(result.associations) == 1 + assert result.skipped == False + messages = p.report.to_report_json()["messages"] + assert len(messages["gorule-0000027"]) == 1 + assert messages["gorule-0000027"][0]["obj"] == "PMID:a1549418" + vals = ["PomBase", "SPAC25A8.01c",