From 32d9898d82e3a81cd99e283c16892e3e9c4d1ec3 Mon Sep 17 00:00:00 2001 From: Heinrich Lukas Weil Date: Fri, 6 Oct 2023 16:24:56 +0200 Subject: [PATCH] small adjustments to updateIOType functionality according to PR request --- src/ISA/ISA/ArcTypes/ArcTable.fs | 39 ++++++++++--------- src/ISA/ISA/ArcTypes/ArcTypes.fs | 8 ++-- tests/ISA/ISA.Tests/ArcInvestigation.Tests.fs | 16 ++++---- 3 files changed, 34 insertions(+), 29 deletions(-) diff --git a/src/ISA/ISA/ArcTypes/ArcTable.fs b/src/ISA/ISA/ArcTypes/ArcTable.fs index 979c8808..133f3368 100644 --- a/src/ISA/ISA/ArcTypes/ArcTable.fs +++ b/src/ISA/ISA/ArcTypes/ArcTable.fs @@ -268,14 +268,6 @@ type ArcTable(name: string, headers: ResizeArray, values: Syste fun (table:ArcTable) -> table.GetColumn(index) - member this.GetColumnByHeader (header:CompositeHeader) = - let index = this.Headers |> Seq.findIndex (fun x -> x = header) - this.GetColumn(index) - - static member getColumnByHeader (header:CompositeHeader) = - fun (table:ArcTable) -> - table.GetColumnByHeader(header) - member this.TryGetColumnByHeader (header:CompositeHeader) = let index = this.Headers |> Seq.tryFindIndex (fun x -> x = header) index @@ -285,13 +277,14 @@ type ArcTable(name: string, headers: ResizeArray, values: Syste fun (table:ArcTable) -> table.TryGetColumnByHeader(header) - member this.GetInputColumn() = - let index = this.Headers |> Seq.findIndex (fun x -> x.isInput) - this.GetColumn(index) + member this.GetColumnByHeader (header:CompositeHeader) = + match this.TryGetColumnByHeader(header) with + | Some c -> c + | None -> failwithf "Unable to find column with header in table %s: %O" this.Name header - static member getInputColumn () = + static member getColumnByHeader (header:CompositeHeader) = fun (table:ArcTable) -> - table.GetInputColumn() + table.GetColumnByHeader(header) member this.TryGetInputColumn() = let index = this.Headers |> Seq.tryFindIndex (fun x -> x.isInput) @@ -302,13 +295,14 @@ type ArcTable(name: string, headers: ResizeArray, values: Syste fun (table:ArcTable) -> table.TryGetInputColumn() - member this.GetOutputColumn() = - let index = this.Headers |> Seq.findIndex (fun x -> x.isOutput) - this.GetColumn(index) + member this.GetInputColumn() = + match this.TryGetInputColumn() with + | Some c -> c + | None -> failwithf "Unable to find input column in table %s" this.Name - static member getOutputColumn () = + static member getInputColumn () = fun (table:ArcTable) -> - table.GetOutputColumn() + table.GetInputColumn() member this.TryGetOutputColumn() = let index = this.Headers |> Seq.tryFindIndex (fun x -> x.isOutput) @@ -319,6 +313,15 @@ type ArcTable(name: string, headers: ResizeArray, values: Syste fun (table:ArcTable) -> table.TryGetOutputColumn() + member this.GetOutputColumn() = + match this.TryGetOutputColumn() with + | Some c -> c + | None -> failwithf "Unable to find output column in table %s" this.Name + + static member getOutputColumn () = + fun (table:ArcTable) -> + table.GetOutputColumn() + // - Row API - // member this.AddRow (?cells: CompositeCell [], ?index: int) : unit = let index = defaultArg index this.RowCount diff --git a/src/ISA/ISA/ArcTypes/ArcTypes.fs b/src/ISA/ISA/ArcTypes/ArcTypes.fs index 090c4516..ff773493 100644 --- a/src/ISA/ISA/ArcTypes/ArcTypes.fs +++ b/src/ISA/ISA/ArcTypes/ArcTypes.fs @@ -1684,14 +1684,16 @@ type ArcInvestigation(identifier : string, ?title : string, ?description : strin copy.DeregisterMissingAssays() copy - /// Updates the IOtypes of the IO columns across all tables in the investigation if possible. + /// Updates the IOtypes of the IO columns (Input, Output) across all tables in the investigation if possible. /// - /// If an entity with the same name as an entity with a higher IOType specifity is found, the IOType of the entity with the lower IOType specificity is updated. + /// If an entity (Row Value of IO Column) with the same name as an entity with a higher IOType specifity is found, the IOType of the entity with the lower IOType specificity is updated. + /// + /// E.g. In Table1, there is a column "Output [Sample Name]" with an entity "Sample1". In Table2, there is a column "Input [Source Name]" with the same entity "Sample1". By equality of the entities, the IOType of the Input column in Table2 is inferred to be Sample, resulting in "Input [Sample Name]". /// /// E.g. RawDataFile is more specific than Source, but less specific than DerivedDataFile. /// /// E.g. Sample is equally specific to RawDataFile. - member this.UpdateIO() = + member this.UpdateIOTypeByEntityID() = let ioMap = [ for study in this.Studies do diff --git a/tests/ISA/ISA.Tests/ArcInvestigation.Tests.fs b/tests/ISA/ISA.Tests/ArcInvestigation.Tests.fs index df61f38c..22305930 100644 --- a/tests/ISA/ISA.Tests/ArcInvestigation.Tests.fs +++ b/tests/ISA/ISA.Tests/ArcInvestigation.Tests.fs @@ -541,7 +541,7 @@ let tests_Assay = testList "CRUD Assay" [ ] ] -let tests_UpdateIOTypes = testList "UpdateIOType" [ +let tests_UpdateIOTypeByEntityIDTypes = testList "UpdateIOTypeByEntityIDType" [ testList "SameAssay" [ testCase "nothingToUpdate" <| fun _ -> let i = ArcInvestigation.init("MyInvestigation") @@ -557,7 +557,7 @@ let tests_UpdateIOTypes = testList "UpdateIOType" [ CompositeColumn.create (CompositeHeader.Output IOType.Sample, Array.init 3 (fun i -> CompositeCell.createFreeText (sprintf "Sample_Alt %i" i))) |] let a_Copy = a.Copy() - i.UpdateIO() + i.UpdateIOTypeByEntityID() Expect.sequenceEqual a.Tables a_Copy.Tables "Tables should be unchanged" testCase "updateOutputByNextInput" <| fun _ -> let i = ArcInvestigation.init("MyInvestigation") @@ -572,7 +572,7 @@ let tests_UpdateIOTypes = testList "UpdateIOType" [ CompositeColumn.create (CompositeHeader.Input IOType.Source, Array.init 3 (fun i -> CompositeCell.createFreeText (sprintf "Sample %i" i))) CompositeColumn.create (CompositeHeader.Output IOType.Sample, Array.init 3 (fun i -> CompositeCell.createFreeText (sprintf "Sample_Alt %i" i))) |] - i.UpdateIO() + i.UpdateIOTypeByEntityID() Expect.sequenceEqual t1.Headers [CompositeHeader.Input IOType.Source; CompositeHeader.Output IOType.Sample] "Headers should be updated" Expect.sequenceEqual t2.Headers [CompositeHeader.Input IOType.Sample; CompositeHeader.Output IOType.Sample] "Headers should be updated" testCase "failBecauseClashing" <| fun _ -> @@ -588,7 +588,7 @@ let tests_UpdateIOTypes = testList "UpdateIOType" [ CompositeColumn.create (CompositeHeader.Input IOType.DerivedDataFile, Array.init 3 (fun i -> CompositeCell.createFreeText (sprintf "Sample %i" i))) CompositeColumn.create (CompositeHeader.Output IOType.Sample, Array.init 3 (fun i -> CompositeCell.createFreeText (sprintf "Sample_Alt %i" i))) |] - Expect.throws (fun () -> i.UpdateIO()) "Update should fail as sample and data can not be updated against each other." + Expect.throws (fun () -> i.UpdateIOTypeByEntityID()) "Update should fail as sample and data can not be updated against each other." ] testList "AssayAndStudy" [ testCase "nothingToUpdate" <| fun _ -> @@ -607,7 +607,7 @@ let tests_UpdateIOTypes = testList "UpdateIOType" [ |] let a_Copy = a.Copy() let s_Copy = s.Copy() - i.UpdateIO() + i.UpdateIOTypeByEntityID() Expect.sequenceEqual a.Tables a_Copy.Tables "Tables should be unchanged" Expect.sequenceEqual s.Tables s_Copy.Tables "Tables should be unchanged" testCase "updateOutputByNextInput" <| fun _ -> @@ -624,7 +624,7 @@ let tests_UpdateIOTypes = testList "UpdateIOType" [ CompositeColumn.create (CompositeHeader.Input IOType.Source, Array.init 3 (fun i -> CompositeCell.createFreeText (sprintf "Sample %i" i))) CompositeColumn.create (CompositeHeader.Output IOType.Sample, Array.init 3 (fun i -> CompositeCell.createFreeText (sprintf "Sample_Alt %i" i))) |] - i.UpdateIO() + i.UpdateIOTypeByEntityID() Expect.sequenceEqual t1.Headers [CompositeHeader.Input IOType.Source; CompositeHeader.Output IOType.Sample] "Headers should be updated" Expect.sequenceEqual t2.Headers [CompositeHeader.Input IOType.Sample; CompositeHeader.Output IOType.Sample] "Headers should be updated" testCase "failBecauseClashing" <| fun _ -> @@ -641,7 +641,7 @@ let tests_UpdateIOTypes = testList "UpdateIOType" [ CompositeColumn.create (CompositeHeader.Input IOType.DerivedDataFile, Array.init 3 (fun i -> CompositeCell.createFreeText (sprintf "Sample %i" i))) CompositeColumn.create (CompositeHeader.Output IOType.Sample, Array.init 3 (fun i -> CompositeCell.createFreeText (sprintf "Sample_Alt %i" i))) |] - Expect.throws (fun () -> i.UpdateIO()) "Update should fail as sample and data can not be updated against each other." + Expect.throws (fun () -> i.UpdateIOTypeByEntityID()) "Update should fail as sample and data can not be updated against each other." ] ] @@ -805,6 +805,6 @@ let main = tests_Study tests_Assay tests_GetHashCode - tests_UpdateIOTypes + tests_UpdateIOTypeByEntityIDTypes // tests_UpdateBy ] \ No newline at end of file