From 77d105451f14a5d63fbefc3c8443a22009f5f23b Mon Sep 17 00:00:00 2001 From: HLWeil Date: Wed, 23 Oct 2024 12:43:59 +0200 Subject: [PATCH] make OntologyAnnotation work with localID as TAN --- src/Core/OntologyAnnotation.fs | 10 ++++++++-- tests/Core/OntologyAnnotation.Tests.fs | 20 ++++++++++++++------ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/Core/OntologyAnnotation.fs b/src/Core/OntologyAnnotation.fs index 508bd354..d2ae71d0 100644 --- a/src/Core/OntologyAnnotation.fs +++ b/src/Core/OntologyAnnotation.fs @@ -42,8 +42,14 @@ type OntologyAnnotation(?name,?tsr,?tan, ?comments) = member this.TANInfo = match this.TermAccessionNumber with - | Some v -> - Regex.tryParseTermAnnotation v + | Some tan -> + match Regex.tryParseTermAnnotation tan with + | Some ta -> Some ta + | None -> + match this.TermSourceREF with + | Some "" | None -> None + | Some tsr -> + Some {| IDSpace = tsr; LocalID = tan |} | None -> None member this.NameText = diff --git a/tests/Core/OntologyAnnotation.Tests.fs b/tests/Core/OntologyAnnotation.Tests.fs index 6241ee4e..1710594e 100644 --- a/tests/Core/OntologyAnnotation.Tests.fs +++ b/tests/Core/OntologyAnnotation.Tests.fs @@ -1,12 +1,14 @@ -module OntologyAnnotation.Tests +module OntologyAnnotation.Tests open TestingUtils open ARCtrl -module private Helper = - let short = "EFO:0000721" - let uri = "https://bioregistry.io/EFO:0000721" - let otherParseable = "http://www.ebi.ac.uk/efo/EFO_0000721" +module Helper = + let tsr = "EFO" + let localID = "0000721" + let short = $"{tsr}:{localID}" + let uri = $"https://bioregistry.io/{tsr}:{localID}" + let otherParseable = $"http://www.ebi.ac.uk/efo/{tsr}_{localID}" let other = "Unparseable" open Helper @@ -79,7 +81,13 @@ let private tests_equals = testList "Equals" [ Expect.notEqual oa1 oa2 "" ] -let private tests_constructor = testList "constructor" [ +let private tests_constructor = testList "constructor" [ + testCase "FromSplitTSRAndLocalID" (fun () -> + let oa = OntologyAnnotation(tsr = tsr, tan = localID) + Expect.equal oa.TermAccessionNumber.Value localID "TAN incorrect" + Expect.equal oa.TermAccessionShort short "short TAN incorrect" + Expect.equal oa.TermAccessionOntobeeUrl uri "uri TAN incorrect" + ) testCase "FromShort" (fun () -> let oa = OntologyAnnotation(tan = short) Expect.equal oa.TermAccessionNumber.Value short "TAN incorrect"