Skip to content

Commit

Permalink
Merge pull request #294 from nfdi4plants/fix_annotationValue_read
Browse files Browse the repository at this point in the history
Fix annotation value read 🐛
  • Loading branch information
Freymaurer authored Jan 17, 2024
2 parents 488e332 + 6e0755b commit 8dd99e8
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 66 deletions.
19 changes: 19 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
### 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
* [[#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
Expand Down
2 changes: 1 addition & 1 deletion build/release_package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nfdi4plants/arctrl",
"version": "1.0.1+5576d43",
"version": "1.0.4+167fae8",
"description": "Top level ARC DataModel and API function descriptions.",
"type": "module",
"main": "index.js",
Expand Down
9 changes: 9 additions & 0 deletions src/ISA/ISA.Json/ArcTypes/ArcAssay.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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

[<AutoOpen>]
module ArcAssayExtensions =

Expand Down
9 changes: 9 additions & 0 deletions src/ISA/ISA.Json/ArcTypes/ArcInvestigation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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

[<AutoOpen>]
module ArcInvestigationExtensions =

Expand Down
9 changes: 9 additions & 0 deletions src/ISA/ISA.Json/ArcTypes/ArcStudy.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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

[<AutoOpen>]
module ArcStudyExtensions =

Expand Down
34 changes: 16 additions & 18 deletions src/ISA/ISA.Json/Ontology.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AnnotationValue> =
/// <summary>
/// This decodes from integer, float or string to string only!
/// </summary>
/// <param name="options"></param>
/// <param name="s"></param>
/// <param name="json"></param>
let decoder (options : ConverterOptions) : Decoder<string> =
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


Expand All @@ -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) =
[
Expand Down Expand Up @@ -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))
Expand Down
1 change: 0 additions & 1 deletion src/ISA/ISA/ARCtrl.ISA.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
<Compile Include="JsonTypes\URI.fs" />
<Compile Include="JsonTypes\Comment.fs" />
<Compile Include="JsonTypes\CommentList.fs" />
<Compile Include="JsonTypes\AnnotationValue.fs" />
<Compile Include="JsonTypes\OntologyAnnotation.fs" />
<Compile Include="JsonTypes\OntologySourceReference.fs" />
<Compile Include="JsonTypes\Value.fs" />
Expand Down
26 changes: 0 additions & 26 deletions src/ISA/ISA/JsonTypes/AnnotationValue.fs

This file was deleted.

2 changes: 1 addition & 1 deletion tests/ARCtrl/Template.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
60 changes: 41 additions & 19 deletions tests/ISA/ISA.Json.Tests/Json.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit 8dd99e8

Please sign in to comment.