From f8a4ceb59b88b869b1db5c1b0edaf102c6fea959 Mon Sep 17 00:00:00 2001 From: Kevin F Date: Wed, 15 Nov 2023 12:19:21 +0100 Subject: [PATCH] apply requested changes --- src/ISA/ISA/ARCtrl.ISA.fsproj | 5 ++- src/ISA/ISA/ArcTypes/ArcTable.fs | 20 +++++++++--- src/ISA/ISA/ArcTypes/CompositeCell.fs | 13 -------- src/ISA/ISA/ArcTypes/CompositeColumn.fs | 4 ++- src/ISA/ISA/ArcTypes/CompositeHeader.fs | 20 ++++++------ src/ISA/ISA/UIHelper.fs | 16 +++++++++ tests/ISA/ISA.Tests/CompositeCell.Tests.fs | 38 ++++++++++++---------- 7 files changed, 67 insertions(+), 49 deletions(-) create mode 100644 src/ISA/ISA/UIHelper.fs diff --git a/src/ISA/ISA/ARCtrl.ISA.fsproj b/src/ISA/ISA/ARCtrl.ISA.fsproj index f21d026d..87af1716 100644 --- a/src/ISA/ISA/ARCtrl.ISA.fsproj +++ b/src/ISA/ISA/ARCtrl.ISA.fsproj @@ -54,6 +54,7 @@ + @@ -63,9 +64,7 @@ - - - + nfdi4plants, Lukas Weil, Kevin Frey, Kevin Schneider, Oliver Muas ARC and ISA compliant experimental metadata toolkit in F#. This project is meant as an easy means to open, manipulate and save ISA (Investigation,Study,Assay) metadata files in the dotnet environment. diff --git a/src/ISA/ISA/ArcTypes/ArcTable.fs b/src/ISA/ISA/ArcTypes/ArcTable.fs index 7feee899..9047cb35 100644 --- a/src/ISA/ISA/ArcTypes/ArcTable.fs +++ b/src/ISA/ISA/ArcTypes/ArcTable.fs @@ -81,15 +81,27 @@ type ArcTable(name: string, headers: ResizeArray, values: Syste fun (table:ArcTable) -> table.TryGetCellAt(column, row) - member this.IterColumns(mapping: CompositeColumn -> unit) = + member this.IterColumns(action: CompositeColumn -> unit) = for columnIndex in 0 .. (this.ColumnCount-1) do let column = this.GetColumn columnIndex - mapping column + action column - member this.IteriColumns(mapping: int -> CompositeColumn -> unit) = + static member iterColumns(action: CompositeColumn -> unit) = + fun (table:ArcTable) -> + let copy = table.Copy() + copy.IterColumns(action) + copy + + member this.IteriColumns(action: int -> CompositeColumn -> unit) = for columnIndex in 0 .. (this.ColumnCount-1) do let column = this.GetColumn columnIndex - mapping columnIndex column + action columnIndex column + + static member iteriColumns(action: int -> CompositeColumn -> unit) = + fun (table:ArcTable) -> + let copy = table.Copy() + copy.IteriColumns(action) + copy // - Cell API - // // TODO: And then directly a design question. Is a column with rows containing both CompositeCell.Term and CompositeCell.Unitized allowed? diff --git a/src/ISA/ISA/ArcTypes/CompositeCell.fs b/src/ISA/ISA/ArcTypes/CompositeCell.fs index 3100ac0e..fb1bcfbc 100644 --- a/src/ISA/ISA/ArcTypes/CompositeCell.fs +++ b/src/ISA/ISA/ArcTypes/CompositeCell.fs @@ -35,19 +35,6 @@ type CompositeCell = member this.isTerm = match this with | Term _ -> true | _ -> false member this.isFreeText = match this with | FreeText _ -> true | _ -> false - /// - /// Updates current CompositeCell with information from OntologyAnnotation. - /// - /// For `Term`, OntologyAnnotation (oa) is fully set. For `Unitized`, oa is set as unit while value is untouched. - /// For `FreeText` oa.NameText is set. - /// - /// - member this.UpdateWithOA(oa:OntologyAnnotation) = - match this with - | CompositeCell.Term _ -> CompositeCell.createTerm oa - | CompositeCell.Unitized (v,_) -> CompositeCell.createUnitized (v,oa) - | CompositeCell.FreeText _ -> CompositeCell.createFreeText oa.NameText - /// /// This returns the default empty cell from an existing CompositeCell. /// diff --git a/src/ISA/ISA/ArcTypes/CompositeColumn.fs b/src/ISA/ISA/ArcTypes/CompositeColumn.fs index 280ed691..d0f0c353 100644 --- a/src/ISA/ISA/ArcTypes/CompositeColumn.fs +++ b/src/ISA/ISA/ArcTypes/CompositeColumn.fs @@ -52,8 +52,10 @@ type CompositeColumn = { /// /// Simple predictor for empty default cells. + /// + /// Currently uses majority vote for the column to decide cell type. /// - member this.PredictNewColumnCell() = + member this.GetDefaultEmptyCell() = if not this.Header.IsTermColumn then CompositeCell.emptyFreeText else diff --git a/src/ISA/ISA/ArcTypes/CompositeHeader.fs b/src/ISA/ISA/ArcTypes/CompositeHeader.fs index 8949ed81..d74218e9 100644 --- a/src/ISA/ISA/ArcTypes/CompositeHeader.fs +++ b/src/ISA/ISA/ArcTypes/CompositeHeader.fs @@ -211,16 +211,16 @@ type CompositeHeader = | Characteristic oa -> oa | Component oa -> oa | ProtocolType -> OntologyAnnotation.fromString(this.ToString(), tan=this.GetFeaturedColumnAccession) - | ProtocolREF - | ProtocolDescription - | ProtocolUri - | ProtocolVersion - | Performer - | Date - | Input _ - | Output _ - | FreeText _ -> - OntologyAnnotation.fromString (this.ToString()) + | ProtocolREF -> OntologyAnnotation.fromString (this.ToString()) // use owl ontology in the future + | ProtocolDescription -> OntologyAnnotation.fromString (this.ToString()) // use owl ontology in the future + | ProtocolUri -> OntologyAnnotation.fromString (this.ToString()) // use owl ontology in the future + | ProtocolVersion -> OntologyAnnotation.fromString (this.ToString()) // use owl ontology in the future + | Performer -> OntologyAnnotation.fromString (this.ToString()) // use owl ontology in the future + | Date -> OntologyAnnotation.fromString (this.ToString()) // use owl ontology in the future + | Input _ -> OntologyAnnotation.fromString (this.ToString()) // use owl ontology in the future + | Output _ -> OntologyAnnotation.fromString (this.ToString()) // use owl ontology in the future + | FreeText _ -> OntologyAnnotation.fromString (this.ToString()) // use owl ontology in the future + // owl ontology: https://github.com/nfdi4plants/ARC_ontology/blob/main/ARC_v2.0.owl /// /// Tries to create a `CompositeHeader` from a given string. diff --git a/src/ISA/ISA/UIHelper.fs b/src/ISA/ISA/UIHelper.fs new file mode 100644 index 00000000..aa8e427e --- /dev/null +++ b/src/ISA/ISA/UIHelper.fs @@ -0,0 +1,16 @@ +module ARCtrl.ISA.UIHelper + +module CompositeCell = + /// + /// Updates current CompositeCell with information from OntologyAnnotation. + /// + /// For `Term`, OntologyAnnotation (oa) is fully set. For `Unitized`, oa is set as unit while value is untouched. + /// For `FreeText` oa.NameText is set. + /// + /// + /// + let updateWithOA (oa:OntologyAnnotation) (cell: CompositeCell) = + match cell with + | CompositeCell.Term _ -> CompositeCell.createTerm oa + | CompositeCell.Unitized (v,_) -> CompositeCell.createUnitized (v,oa) + | CompositeCell.FreeText _ -> CompositeCell.createFreeText oa.NameText diff --git a/tests/ISA/ISA.Tests/CompositeCell.Tests.fs b/tests/ISA/ISA.Tests/CompositeCell.Tests.fs index 2b5fda3c..8db5a497 100644 --- a/tests/ISA/ISA.Tests/CompositeCell.Tests.fs +++ b/tests/ISA/ISA.Tests/CompositeCell.Tests.fs @@ -154,23 +154,25 @@ let private tests_GetContent = testList "GetContent" [ ] -let private tests_UpdateWithOA = testList "UpdateWithOA" [ - let testOntologyAnnotation = OntologyAnnotation.fromString("New OA", "NEW", "NEW:00001") - testCase "Term" <| fun _ -> - let cc = CompositeCell.createTermFromString("TestTerm", "TEST", "TEST:00001") - let actual = cc.UpdateWithOA testOntologyAnnotation - let expected = CompositeCell.createTermFromString(testOntologyAnnotation.NameText, testOntologyAnnotation.TermSourceREFString, testOntologyAnnotation.TermAccessionShort) - Expect.equal actual expected "" - testCase "Unitized" <| fun _ -> - let cc = CompositeCell.createUnitizedFromString("12", "TestTerm", "TEST", "TEST:00001") - let actual = cc.UpdateWithOA testOntologyAnnotation - let expected = CompositeCell.createUnitizedFromString("12", testOntologyAnnotation.NameText, testOntologyAnnotation.TermSourceREFString, testOntologyAnnotation.TermAccessionShort) - Expect.equal actual expected "" - testCase "FreeText" <| fun _ -> - let cc = CompositeCell.createFreeText("TestTerm") - let actual = cc.UpdateWithOA testOntologyAnnotation - let expected = CompositeCell.createFreeText(testOntologyAnnotation.NameText) - Expect.equal actual expected "" +let private tests_UIHelper = testList "UIHelper" [ + testList "UpdateWithOA" [ + let testOntologyAnnotation = OntologyAnnotation.fromString("New OA", "NEW", "NEW:00001") + testCase "Term" <| fun _ -> + let cc = CompositeCell.createTermFromString("TestTerm", "TEST", "TEST:00001") + let actual = cc |> UIHelper.CompositeCell.updateWithOA testOntologyAnnotation + let expected = CompositeCell.createTermFromString(testOntologyAnnotation.NameText, testOntologyAnnotation.TermSourceREFString, testOntologyAnnotation.TermAccessionShort) + Expect.equal actual expected "" + testCase "Unitized" <| fun _ -> + let cc = CompositeCell.createUnitizedFromString("12", "TestTerm", "TEST", "TEST:00001") + let actual = cc |> UIHelper.CompositeCell.updateWithOA testOntologyAnnotation + let expected = CompositeCell.createUnitizedFromString("12", testOntologyAnnotation.NameText, testOntologyAnnotation.TermSourceREFString, testOntologyAnnotation.TermAccessionShort) + Expect.equal actual expected "" + testCase "FreeText" <| fun _ -> + let cc = CompositeCell.createFreeText("TestTerm") + let actual = cc |> UIHelper.CompositeCell.updateWithOA testOntologyAnnotation + let expected = CompositeCell.createFreeText(testOntologyAnnotation.NameText) + Expect.equal actual expected "" + ] ] let main = @@ -179,5 +181,5 @@ let main = tests_create tests_ToString tests_GetContent - tests_UpdateWithOA + tests_UIHelper ] \ No newline at end of file