From 99b7e6bfdb129a3a6ec0316384f4b6d9a348ce07 Mon Sep 17 00:00:00 2001 From: David Reinhart Date: Tue, 7 Jul 2026 14:54:43 -0700 Subject: [PATCH] feat(ensembl): support versioned Ensembl IDs Accept an optional version suffix (e.g. ENSG00000012048.15) in the Ensembl regexp, matching the version handling already used by the uniprot and refseq patterns. The version is preserved by normalization (as with refseq) and stripped only when generating a landing-page URL. Add a test case covering detection, normalization and URL generation for a versioned ID. --- idutils/normalizers.py | 2 ++ idutils/utils.py | 2 +- tests/test_idutils.py | 8 ++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/idutils/normalizers.py b/idutils/normalizers.py index c85e81c..4d5aff7 100644 --- a/idutils/normalizers.py +++ b/idutils/normalizers.py @@ -260,6 +260,8 @@ def to_url(val, scheme, url_scheme="http"): pid = pid[len("wikidata:") :] if scheme == "openalex": url_scheme = "https" + if scheme == "ensembl": + pid = pid.split(".")[0] return landing_urls[scheme].format(scheme=url_scheme, pid=pid) elif scheme in ["purl", "url"]: return pid diff --git a/idutils/utils.py b/idutils/utils.py index 1f6b6b7..dae49e1 100644 --- a/idutils/utils.py +++ b/idutils/utils.py @@ -247,7 +247,7 @@ """ ensembl_regexp = re.compile( - r"({prefixes})(E|FM|G|GT|P|R|T)\d{{11}}$".format( + r"({prefixes})(E|FM|G|GT|P|R|T)\d{{11}}(\.\d+)?$".format( prefixes="|".join(ENSEMBL_PREFIXES) ) ) diff --git a/tests/test_idutils.py b/tests/test_idutils.py index 577b0f5..f67530b 100644 --- a/tests/test_idutils.py +++ b/tests/test_idutils.py @@ -460,6 +460,14 @@ "", "http://www.ensembl.org/id/ENSMUST00000017290", ), + ( + "ENSG00000012048.15", + [ + "ensembl", + ], + "", + "http://www.ensembl.org/id/ENSG00000012048", + ), ( "P02833", [