Skip to content

Commit

Permalink
make process conversion more robust against different outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
HLWeil committed Jun 26, 2024
1 parent 3e37220 commit 485d778
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 12 deletions.
25 changes: 20 additions & 5 deletions src/Core/Conversion.fs
Original file line number Diff line number Diff line change
Expand Up @@ -100,23 +100,32 @@ module JsonTypes =
let c = MaterialAttribute.create(CharacteristicType = header.ToTerm())
MaterialAttributeValue.create(Category = c,?Value = v,?Unit = u)

let composeFreetextMaterialName (headerFT : string) (name : string) =
$"{headerFT}={name}"


/// Convert a CompositeHeader and Cell tuple to a ISA ProcessInput
let composeProcessInput (header : CompositeHeader) (value : CompositeCell) : ProcessInput =
match header with
| CompositeHeader.Input IOType.Source -> ProcessInput.createSource(value.ToString())
| CompositeHeader.Input IOType.Sample -> ProcessInput.createSample(value.ToString())
| CompositeHeader.Input IOType.Material -> ProcessInput.createMaterial(value.ToString())
| CompositeHeader.Input IOType.Data -> ProcessInput.createRawData(value.ToString())
| CompositeHeader.Input (IOType.FreeText ft) ->
ProcessInput.createMaterial(composeFreetextMaterialName ft (value.ToString()))
| _ ->
failwithf "Could not parse input header %O" header


/// Convert a CompositeHeader and Cell tuple to a ISA ProcessOutput
let composeProcessOutput (header : CompositeHeader) (value : CompositeCell) : ProcessOutput =
match header with
| CompositeHeader.Output IOType.Sample -> ProcessOutput.createSample(value.ToString())
| CompositeHeader.Output IOType.Source
| CompositeHeader.Output IOType.Sample -> ProcessOutput.createSample(value.ToString())
| CompositeHeader.Output IOType.Material -> ProcessOutput.createMaterial(value.ToString())
| CompositeHeader.Output IOType.Data -> ProcessOutput.createRawData(value.ToString())
| CompositeHeader.Output (IOType.FreeText ft) ->
ProcessOutput.createMaterial(composeFreetextMaterialName ft (value.ToString()))
| _ ->
failwithf "Could not parse output header %O" header

Expand Down Expand Up @@ -407,8 +416,11 @@ module ProcessParsing =
ProcessInput.createSample(input.Name, characteristics = chars)
]
else
input
|> ProcessInput.setCharacteristicValues chars
if chars.Length > 0 then
input
|> ProcessInput.setCharacteristicValues chars
else
input
|> List.singleton
| None ->
fun (matrix : System.Collections.Generic.Dictionary<(int * int),CompositeCell>) i ->
Expand All @@ -429,8 +441,11 @@ module ProcessParsing =
ProcessOutput.createSample(output.Name, factors = factors)
]
else
output
|> ProcessOutput.setFactorValues factors
if factors.Length > 0 then
output
|> ProcessOutput.setFactorValues factors
else
output
|> List.singleton
| None ->
fun (matrix : System.Collections.Generic.Dictionary<(int * int),CompositeCell>) i ->
Expand Down
45 changes: 38 additions & 7 deletions tests/Core/ArcJsonConversion.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ module Helper =
t.AddColumns(columns)
t

let singleRowOutputSource =
/// Input [Source] --> Source_0 .. Source_4
let columns =
[|
CompositeColumn.create(CompositeHeader.Input IOType.Source, createCells_FreeText "Source" 1)
CompositeColumn.create(CompositeHeader.Output IOType.Source, createCells_FreeText "Sample" 1)
|]
let t = ArcTable.init(tableName1)
t.AddColumns(columns)
t

let singleRowMixedValues =
/// Input [Source] --> Source_0 .. Source_4
let columns =
Expand Down Expand Up @@ -137,15 +148,19 @@ let private tests_ArcTableProcess =
let expectedParam = ProtocolParameter.create(ParameterName = oa_species)
let expectedValue = Value.Ontology oa_chlamy
let expectedPPV = ProcessParameterValue.create(Category = expectedParam, Value = expectedValue)
let expectedInput = Source.create(Name = "Source_0") |> ProcessInput.Source
let expectedOutput = Sample.create(Name = "Sample_0") |> ProcessOutput.Sample
Expect.equal processes.Length 1 "Should have 1 process"
let p = processes.[0]
Expect.isSome p.ParameterValues "Process should have parameter values"
Expect.equal p.ParameterValues.Value.Length 1 "Process should have 1 parameter values"
Expect.equal p.ParameterValues.Value.[0] expectedPPV "Param value does not match"
Expect.isSome p.Inputs "Process should have inputs"
Expect.equal p.Inputs.Value.Length 1 "Process should have 1 input"
Expect.isSome p.Outputs "Process should have outputs"
Expect.equal p.Outputs.Value.Length 1 "Process should have 1 output"
let paramValues = Expect.wantSome p.ParameterValues "Process should have parameter values"
Expect.equal paramValues.Length 1 "Process should have 1 parameter values"
Expect.equal paramValues.[0] expectedPPV "Param value does not match"
let inputs = Expect.wantSome p.Inputs "Process should have inputs"
Expect.equal inputs.Length 1 "Process should have 1 input"
Expect.equal inputs.[0] expectedInput "Input value does not match"
let outputs = Expect.wantSome p.Outputs "Process should have outputs"
Expect.equal outputs.Length 1 "Process should have 1 output"
Expect.equal outputs.[0] expectedOutput "Output value does not match"
Expect.isSome p.Name "Process should have name"
Expect.equal p.Name.Value tableName1 "Process name should match table name"
)
Expand All @@ -156,6 +171,22 @@ let private tests_ArcTableProcess =
let expectedTable = t
Expect.arcTableEqual table expectedTable "Table should be equal"
)
testCase "SingleRowOutputSource GetProcesses" (fun () ->
let t = singleRowOutputSource.Copy()
let processes = t.GetProcesses()
let expectedInput = Source.create(Name = "Source_0") |> ProcessInput.Source
let expectedOutput = Sample.create(Name = "Sample_0") |> ProcessOutput.Sample
Expect.equal processes.Length 1 "Should have 1 process"
let p = processes.[0]
let inputs = Expect.wantSome p.Inputs "Process should have inputs"
Expect.equal inputs.Length 1 "Process should have 1 input"
Expect.equal inputs.[0] expectedInput "Input value does not match"
let outputs = Expect.wantSome p.Outputs "Process should have outputs"
Expect.equal outputs.Length 1 "Process should have 1 output"
Expect.equal outputs.[0] expectedOutput "Output value does not match"
let name = Expect.wantSome p.Name "Process should have name"
Expect.equal name tableName1 "Process name should match table name"
)

testCase "SingleRowMixedValues GetProcesses" (fun () ->
let t = singleRowMixedValues.Copy()
Expand Down

0 comments on commit 485d778

Please sign in to comment.