From d42faaf5e41712b06991b111894bb6a7b3b09d58 Mon Sep 17 00:00:00 2001 From: Kevin F Date: Fri, 12 Jan 2024 16:02:02 +0100 Subject: [PATCH 1/5] Fix template read issue. annotationvalue not correctly read :bug: --- src/ISA/ISA.Json/Ontology.fs | 34 +++++++++++------------- src/ISA/ISA/ARCtrl.ISA.fsproj | 1 - src/ISA/ISA/JsonTypes/AnnotationValue.fs | 26 ------------------ 3 files changed, 16 insertions(+), 45 deletions(-) delete mode 100644 src/ISA/ISA/JsonTypes/AnnotationValue.fs diff --git a/src/ISA/ISA.Json/Ontology.fs b/src/ISA/ISA.Json/Ontology.fs index 32bb1ca6..2671e188 100644 --- a/src/ISA/ISA.Json/Ontology.fs +++ b/src/ISA/ISA.Json/Ontology.fs @@ -10,26 +10,23 @@ open System.IO module AnnotationValue = - let encoder (options : ConverterOptions) (value : obj) = - match value with - | :? AnnotationValue as AnnotationValue.Float f -> - Encode.float f - | :? AnnotationValue as AnnotationValue.Int i -> - Encode.int i - | :? AnnotationValue as AnnotationValue.Text s -> - Encode.string s - | _ -> Encode.nil - - let decoder (options : ConverterOptions) : Decoder = + /// + /// This decodes from integer, float or string to string only! + /// + /// + /// + /// + let decoder (options : ConverterOptions) : Decoder = fun s json -> + // is there a option to decode force to string? match Decode.int s json with - | Ok i -> Ok (AnnotationValue.Int i) + | Ok i -> Ok <| string i | Error _ -> match Decode.float s json with - | Ok f -> Ok (AnnotationValue.Float f) + | Ok f -> Ok <| string f | Error _ -> match Decode.string s json with - | Ok s -> Ok (AnnotationValue.Text s) + | Ok s -> Ok <| s | Error e -> Error e @@ -38,9 +35,10 @@ module OntologySourceReference = let genID (o:OntologySourceReference) = match o.File with | Some f -> f - | None -> match o.Name with - | Some n -> "#OntologySourceRef_" + n.Replace(" ","_") - | None -> "#DummyOntologySourceRef" + | None -> + match o.Name with + | Some n -> "#OntologySourceRef_" + n.Replace(" ","_") + | None -> "#DummyOntologySourceRef" let encoder (options : ConverterOptions) (osr : obj) = [ @@ -114,7 +112,7 @@ module OntologyAnnotation = Decode.object (fun get -> OntologyAnnotation.create( ?Id = get.Optional.Field "@id" GDecode.uri, - ?Name = get.Optional.Field "annotationValue" Decode.string, + ?Name = get.Optional.Field "annotationValue" (AnnotationValue.decoder options), ?TermSourceREF = get.Optional.Field "termSource" Decode.string, ?TermAccessionNumber = get.Optional.Field "termAccession" Decode.string, ?Comments = get.Optional.Field "comments" (Decode.array (Comment.decoder options)) diff --git a/src/ISA/ISA/ARCtrl.ISA.fsproj b/src/ISA/ISA/ARCtrl.ISA.fsproj index 6f3a1f54..31164e45 100644 --- a/src/ISA/ISA/ARCtrl.ISA.fsproj +++ b/src/ISA/ISA/ARCtrl.ISA.fsproj @@ -16,7 +16,6 @@ - diff --git a/src/ISA/ISA/JsonTypes/AnnotationValue.fs b/src/ISA/ISA/JsonTypes/AnnotationValue.fs deleted file mode 100644 index 6b481f71..00000000 --- a/src/ISA/ISA/JsonTypes/AnnotationValue.fs +++ /dev/null @@ -1,26 +0,0 @@ -namespace ARCtrl.ISA - -open Fable.Core - -type AnnotationValue = - | Text of string - | Float of float - | Int of int - - static member empty = Text "" - - /// Create a ISAJson Annotation value from a ISATab string entry - static member fromString (s : string) = - //try s |> int |> AnnotationValue.Int - //with | _ -> - // try s |> float |> AnnotationValue.Float - // with - // | _ -> - AnnotationValue.Text s - - /// Get a ISATab string Annotation Name from a ISAJson object - static member toString (v : AnnotationValue) = - match v with - | Text s -> s - | Int i -> string i - | Float f -> string f \ No newline at end of file From 533dab0039404d3dc0ba8e9612e1a083198ee056 Mon Sep 17 00:00:00 2001 From: Kevin F Date: Fri, 12 Jan 2024 16:04:14 +0100 Subject: [PATCH 2/5] Add tests for edgecase :white_check_mark: --- tests/ARCtrl/Template.Tests.fs | 2 +- tests/ISA/ISA.Json.Tests/Json.Tests.fs | 60 ++++++++++++++++++-------- 2 files changed, 42 insertions(+), 20 deletions(-) diff --git a/tests/ARCtrl/Template.Tests.fs b/tests/ARCtrl/Template.Tests.fs index a97f4af3..3e33943d 100644 --- a/tests/ARCtrl/Template.Tests.fs +++ b/tests/ARCtrl/Template.Tests.fs @@ -262,7 +262,7 @@ let private tests_equality = testList "equality" [ ] let private tests_Web = testList "Web" [ - ptestCaseAsync "getTemplates" <| async { + testCaseAsync "getTemplates" <| async { let! templatesMap = ARCtrl.Template.Web.getTemplates(None) Expect.isTrue (templatesMap.Length > 0) "Count > 0" } diff --git a/tests/ISA/ISA.Json.Tests/Json.Tests.fs b/tests/ISA/ISA.Json.Tests/Json.Tests.fs index a87a10b3..4752a093 100644 --- a/tests/ISA/ISA.Json.Tests/Json.Tests.fs +++ b/tests/ISA/ISA.Json.Tests/Json.Tests.fs @@ -135,33 +135,55 @@ let testDecode = let testOntoloyAnnotation = testList "OntologyAnnotation" [ - - testCase "ReaderSuccess" (fun () -> + + testCase "ReaderSuccess" (fun () -> - let result = OntologyAnnotation.fromJsonString OntologyAnnotation.peptidase + let result = OntologyAnnotation.fromJsonString OntologyAnnotation.peptidase - let comment = Comment.create(Name = "comment",Value = "This is a comment") - let expected = - OntologyAnnotation.create("protease","Peptidase", "MS", "http://purl.obolibrary.org/obo/NCIT_C16965",Comments = [|comment|]) + let comment = Comment.create(Name = "comment",Value = "This is a comment") + let expected = + OntologyAnnotation.create("protease","Peptidase", "MS", "http://purl.obolibrary.org/obo/NCIT_C16965",Comments = [|comment|]) - Expect.equal result expected "Source did not match" - ) - testCase "WriterOutputMatchesInput" (fun () -> + Expect.equal result expected "Source did not match" + ) + testCase "WriterOutputMatchesInput" (fun () -> - let o_read_in = OntologyAnnotation.fromJsonString OntologyAnnotation.peptidase - let o_out = OntologyAnnotation.toJsonString o_read_in + let o_read_in = OntologyAnnotation.fromJsonString OntologyAnnotation.peptidase + let o_out = OntologyAnnotation.toJsonString o_read_in - let expected = - OntologyAnnotation.peptidase - |> Utils.wordFrequency + let expected = + OntologyAnnotation.peptidase + |> Utils.wordFrequency - let actual = - o_out - |> Utils.wordFrequency + let actual = + o_out + |> Utils.wordFrequency - Expect.sequenceEqual actual expected "Written processInput does not match read process input" - ) + Expect.sequenceEqual actual expected "Written processInput does not match read process input" + ) + + testCase "Read AnnotationValue - integer" <| fun _ -> + let json = """{ + "annotationValue": 4242424 +}""" + let oa = OntologyAnnotation.fromJsonString json + let name = Expect.wantSome oa.Name "" + Expect.equal name "4242424" "" + testCase "Read AnnotationValue - float" <| fun _ -> + let json = """{ + "annotationValue": 42.42 +}""" + let oa = OntologyAnnotation.fromJsonString json + let name = Expect.wantSome oa.Name "" + Expect.equal name "42.42" "" + testCase "Read AnnotationValue - string" <| fun _ -> + let json = """{ + "annotationValue": "Example" +}""" + let oa = OntologyAnnotation.fromJsonString json + let name = Expect.wantSome oa.Name "" + Expect.equal name "Example" "" ] let testOntoloyAnnotationLD = From 634a41b7c88dc99bf82bf52af9535bc0f1682e74 Mon Sep 17 00:00:00 2001 From: Kevin F Date: Mon, 15 Jan 2024 12:17:40 +0100 Subject: [PATCH 3/5] Update und release 1.0.3 --- RELEASE_NOTES.md | 15 +++++++++++++++ build/release_package.json | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 28949111..43161360 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,3 +1,18 @@ +### 1.0.3+533dab0 (Released 2024-1-15) +* Additions: + * [[#208839a](https://github.com/nfdi4plants/ARCtrl/commit/208839a2d50e3c7ffd2722a5e65262bea1e185cd)] change annotationValue of Ontology Annotation to string + * [[#533dab0](https://github.com/nfdi4plants/ARCtrl/commit/533dab0039404d3dc0ba8e9612e1a083198ee056)] Add tests for edgecase :white_check_mark: +* Bugfixes: + * [[#d42faaf](https://github.com/nfdi4plants/ARCtrl/commit/d42faaf5e41712b06991b111894bb6a7b3b09d58)] Fix template read issue. annotationvalue not correctly read :bug: + +### 1.0.2+533dab0 (Released 2024-1-15) +* Additions: + * [[#cc7f35f](https://github.com/nfdi4plants/ARCtrl/commit/cc7f35f911b3960c9996276f808d8ee4bc7204d3)] add speedtest and make some small experimental changes + * [[#e85dba4](https://github.com/nfdi4plants/ARCtrl/commit/e85dba44d675a0896cf185c4ee39e5047896eb9c)] make some validation and checks optional for speed improvements + * [[#208839a](https://github.com/nfdi4plants/ARCtrl/commit/208839a2d50e3c7ffd2722a5e65262bea1e185cd)] change annotationValue of Ontology Annotation to string + * [[#a1921ef](https://github.com/nfdi4plants/ARCtrl/commit/a1921ef104e4f168cb6846b2b9de886e4ae774da)] make fillmissingcells optional for addcolumns + * [[#2aca309](https://github.com/nfdi4plants/ARCtrl/commit/2aca309623061171dc1c3ec3897d2c5cd388bf11)] Make ArcStudy IO performance test more strict + ### 1.0.1+5576d43 (Released 2023-12-21) * Additions: * [[#66ff8f4](https://github.com/nfdi4plants/ARCtrl/commit/66ff8f4bb902e1234e84dfaec5411fd7ea5237b3)] improve github ci diff --git a/build/release_package.json b/build/release_package.json index 9c8c0fe4..d64594f0 100644 --- a/build/release_package.json +++ b/build/release_package.json @@ -1,6 +1,6 @@ { "name": "@nfdi4plants/arctrl", - "version": "1.0.1+5576d43", + "version": "1.0.3+533dab0", "description": "Top level ARC DataModel and API function descriptions.", "type": "module", "main": "index.js", From 167fae8bcaa14d8e24055f60ac031b13d8b47199 Mon Sep 17 00:00:00 2001 From: Kevin F Date: Mon, 15 Jan 2024 13:11:21 +0100 Subject: [PATCH 4/5] add json functions for better function names in js :sparkles: --- src/ISA/ISA.Json/ArcTypes/ArcAssay.fs | 9 +++++++++ src/ISA/ISA.Json/ArcTypes/ArcInvestigation.fs | 9 +++++++++ src/ISA/ISA.Json/ArcTypes/ArcStudy.fs | 9 +++++++++ 3 files changed, 27 insertions(+) diff --git a/src/ISA/ISA.Json/ArcTypes/ArcAssay.fs b/src/ISA/ISA.Json/ArcTypes/ArcAssay.fs index 09239920..e8e29e2b 100644 --- a/src/ISA/ISA.Json/ArcTypes/ArcAssay.fs +++ b/src/ISA/ISA.Json/ArcTypes/ArcAssay.fs @@ -82,6 +82,15 @@ module ArcAssay = Assay.encoder (ConverterOptions()) (a.ToAssay()) |> Encode.toString 2 + let toArcJsonString (a:ArcAssay) : string = + let spaces = 0 + Encode.toString spaces (encoder a) + + let fromArcJsonString (jsonString: string) = + match Decode.fromString decoder jsonString with + | Ok a -> a + | Error e -> failwithf "Error. Unable to parse json string to ArcAssay: %s" e + [] module ArcAssayExtensions = diff --git a/src/ISA/ISA.Json/ArcTypes/ArcInvestigation.fs b/src/ISA/ISA.Json/ArcTypes/ArcInvestigation.fs index 1aba93f7..7430282a 100644 --- a/src/ISA/ISA.Json/ArcTypes/ArcInvestigation.fs +++ b/src/ISA/ISA.Json/ArcTypes/ArcInvestigation.fs @@ -73,6 +73,15 @@ module ArcInvestigation = Investigation.encoder (ConverterOptions()) (a.ToInvestigation()) |> Encode.toString 2 + let toArcJsonString (a:ArcInvestigation) : string = + let spaces = 0 + Encode.toString spaces (encoder a) + + let fromArcJsonString (jsonString: string) = + match Decode.fromString decoder jsonString with + | Ok a -> a + | Error e -> failwithf "Error. Unable to parse json string to ArcInvestigation: %s" e + [] module ArcInvestigationExtensions = diff --git a/src/ISA/ISA.Json/ArcTypes/ArcStudy.fs b/src/ISA/ISA.Json/ArcTypes/ArcStudy.fs index a9f43fdc..32c65502 100644 --- a/src/ISA/ISA.Json/ArcTypes/ArcStudy.fs +++ b/src/ISA/ISA.Json/ArcTypes/ArcStudy.fs @@ -67,6 +67,15 @@ module ArcStudy = Study.encoder (ConverterOptions()) (a.ToStudy(assays)) |> Encode.toString 2 + let toArcJsonString (a:ArcStudy) : string = + let spaces = 0 + Encode.toString spaces (encoder a) + + let fromArcJsonString (jsonString: string) = + match Decode.fromString decoder jsonString with + | Ok a -> a + | Error e -> failwithf "Error. Unable to parse json string to ArcStudy: %s" e + [] module ArcStudyExtensions = From 6e0755b5e1c28bb72814247dad1e4ab457e25e40 Mon Sep 17 00:00:00 2001 From: Kevin F Date: Mon, 15 Jan 2024 13:17:42 +0100 Subject: [PATCH 5/5] update and release version 1.0.4 --- RELEASE_NOTES.md | 4 ++++ build/release_package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 43161360..087b44c8 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,3 +1,7 @@ +### 1.0.4+167fae8 (Released 2024-1-15) +* Additions: + * [[#167fae8](https://github.com/nfdi4plants/ARCtrl/commit/167fae8bcaa14d8e24055f60ac031b13d8b47199)] add json functions for better function names in js :sparkles: + ### 1.0.3+533dab0 (Released 2024-1-15) * Additions: * [[#208839a](https://github.com/nfdi4plants/ARCtrl/commit/208839a2d50e3c7ffd2722a5e65262bea1e185cd)] change annotationValue of Ontology Annotation to string diff --git a/build/release_package.json b/build/release_package.json index d64594f0..38ed9653 100644 --- a/build/release_package.json +++ b/build/release_package.json @@ -1,6 +1,6 @@ { "name": "@nfdi4plants/arctrl", - "version": "1.0.3+533dab0", + "version": "1.0.4+167fae8", "description": "Top level ARC DataModel and API function descriptions.", "type": "module", "main": "index.js",