Skip to content

Commit

Permalink
small adjustments to updateIOType functionality according to PR request
Browse files Browse the repository at this point in the history
  • Loading branch information
HLWeil committed Oct 16, 2023
1 parent a4c6c7f commit 32d9898
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 29 deletions.
39 changes: 21 additions & 18 deletions src/ISA/ISA/ArcTypes/ArcTable.fs
Original file line number Diff line number Diff line change
Expand Up @@ -268,14 +268,6 @@ type ArcTable(name: string, headers: ResizeArray<CompositeHeader>, 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
Expand All @@ -285,13 +277,14 @@ type ArcTable(name: string, headers: ResizeArray<CompositeHeader>, 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)
Expand All @@ -302,13 +295,14 @@ type ArcTable(name: string, headers: ResizeArray<CompositeHeader>, 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)
Expand All @@ -319,6 +313,15 @@ type ArcTable(name: string, headers: ResizeArray<CompositeHeader>, 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
Expand Down
8 changes: 5 additions & 3 deletions src/ISA/ISA/ArcTypes/ArcTypes.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions tests/ISA/ISA.Tests/ArcInvestigation.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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 _ ->
Expand All @@ -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 _ ->
Expand All @@ -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 _ ->
Expand All @@ -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 _ ->
Expand All @@ -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."
]
]

Expand Down Expand Up @@ -805,6 +805,6 @@ let main =
tests_Study
tests_Assay
tests_GetHashCode
tests_UpdateIOTypes
tests_UpdateIOTypeByEntityIDTypes
// tests_UpdateBy
]

0 comments on commit 32d9898

Please sign in to comment.