Skip to content

Commit

Permalink
support direct type mappings for inputs and outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
caroott authored and kMutagene committed Oct 21, 2024
1 parent 3db45c6 commit 95dab47
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 38 deletions.
74 changes: 43 additions & 31 deletions src/CWL/Decode.fs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ module Decode =
{ Glob = glob }
)

let outputBindingDecoder: (YAMLiciousTypes.YAMLElement -> OutputBinding) =
let outputBindingDecoder: (YAMLiciousTypes.YAMLElement -> OutputBinding option) =
Decode.object(fun get ->
let outputBinding = get.Required.Field "outputBinding" outputBindingGlobDecoder
let outputBinding = get.Optional.Field "outputBinding" outputBindingGlobDecoder
outputBinding
)

Expand All @@ -41,6 +41,30 @@ module Decode =
| _ -> failwith "Invalid CWL type"
)

let cwlTypeStringMatcher t =
match t with
| "File" -> File (FileInstance ())
| "Directory" -> Directory (DirectoryInstance ())
| "Dirent" -> Dirent { Entry = ""; Entryname = None; Writable = None }
| "string" -> String
| "int" -> Int
| "long" -> Long
| "float" -> Float
| "double" -> Double
| "boolean" -> Boolean
| "File[]" -> Array (File (FileInstance ()))
| "Directory[]" -> Array (Directory (DirectoryInstance ()))
| "Dirent[]" -> Array (Dirent { Entry = ""; Entryname = None; Writable = None })
| "string[]" -> Array String
| "int[]" -> Array Int
| "long[]" -> Array Long
| "float[]" -> Array Float
| "double[]" -> Array Double
| "boolean[]" -> Array Boolean
| "stdout" -> Stdout
| "null" -> Null
| _ -> failwith "Invalid CWL type"

let cwlTypeDecoder: (YAMLiciousTypes.YAMLElement -> CWLType) =
Decode.object (fun get ->
let cwlType =
Expand All @@ -55,28 +79,7 @@ module Decode =
)
match cwlType with
| Some t ->
match t with
| "File" -> File (FileInstance ())
| "Directory" -> Directory (DirectoryInstance ())
| "Dirent" -> Dirent { Entry = ""; Entryname = None; Writable = None }
| "string" -> String
| "int" -> Int
| "long" -> Long
| "float" -> Float
| "double" -> Double
| "boolean" -> Boolean
| "File[]" -> Array (File (FileInstance ()))
| "Directory[]" -> Array (Directory (DirectoryInstance ()))
| "Dirent[]" -> Array (Dirent { Entry = ""; Entryname = None; Writable = None })
| "string[]" -> Array String
| "int[]" -> Array Int
| "long[]" -> Array Long
| "float[]" -> Array Float
| "double[]" -> Array Double
| "boolean[]" -> Array Boolean
| "stdout" -> Stdout
| "null" -> Null
| _ -> failwith "Invalid CWL type"
cwlTypeStringMatcher t
| None ->
let cwlTypeArray = get.Required.Field "type" cwlArrayTypeDecoder
cwlTypeArray
Expand All @@ -89,12 +92,18 @@ module Decode =
for key in dict.Keys do
let value = dict.[key]
let outputBinding = outputBindingDecoder value
let cwlType = cwlTypeDecoder value
Output(
key,
cwlType,
outputBinding
)
let cwlType =
match value with
| YAMLElement.Object [YAMLElement.Value v] -> cwlTypeStringMatcher v.Value
| _ -> cwlTypeDecoder value
let output =
Output(
key,
cwlType
)
if outputBinding.IsSome then
DynObj.setValueOpt output "outputBinding" outputBinding
output
|]
)

Expand Down Expand Up @@ -258,7 +267,10 @@ module Decode =
for key in dict.Keys do
let value = dict.[key]
let inputBinding = inputBindingDecoder value
let cwlType = cwlTypeDecoder value
let cwlType =
match value with
| YAMLElement.Object [YAMLElement.Value v] -> cwlTypeStringMatcher v.Value
| _ -> cwlTypeDecoder value
let input =
Input(
key,
Expand Down
29 changes: 25 additions & 4 deletions tests/CWL/Outputs.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let decodeOutput =
let testOutput =
testList "outputs with basetypes and array" [
testCase "Length" <| fun _ ->
let expected = 4
let expected = 5
let actual = decodeOutput.Length
Expect.isTrue
(expected = actual)
Expand Down Expand Up @@ -43,7 +43,7 @@ let testOutput =
testList "Directory" [
let directoryItem = decodeOutput.[1]
testCase "Name" <| fun _ ->
let expected = "example"
let expected = "example1"
let actual = directoryItem.Name
Expect.isTrue
(expected = actual)
Expand All @@ -61,8 +61,29 @@ let testOutput =
(expected = actual)
$"Expected: {expected}\nActual: {actual}"
]
testList "Directory 2" [
let directoryItem = decodeOutput.[2]
testCase "Name" <| fun _ ->
let expected = "example2"
let actual = directoryItem.Name
Expect.isTrue
(expected = actual)
$"Expected: {expected}\nActual: {actual}"
testCase "Type" <| fun _ ->
let expected = Directory (DirectoryInstance())
let actual = directoryItem.Type.Value
Expect.isTrue
(expected = actual)
$"Expected: {expected}\nActual: {actual}"
testCase "OutputBinding" <| fun _ ->
let expected = None
let actual = directoryItem.OutputBinding
Expect.isTrue
(expected = actual)
$"Expected: {expected}\nActual: {actual}"
]
testList "File Array" [
let fileArrayItem = decodeOutput.[2]
let fileArrayItem = decodeOutput.[3]
testCase "Name" <| fun _ ->
let expected = "exampleArray1"
let actual = fileArrayItem.Name
Expand All @@ -83,7 +104,7 @@ let testOutput =
$"Expected: {expected}\nActual: {actual}"
]
testList "File Array 2" [
let fileArrayItem = decodeOutput.[3]
let fileArrayItem = decodeOutput.[4]
testCase "Name" <| fun _ ->
let expected = "exampleArray2"
let actual = fileArrayItem.Name
Expand Down
3 changes: 1 addition & 2 deletions tests/TestingUtils/TestObjects.CWL/Inputs.fs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
module TestObjects.CWL.Inputs

let inputs ="""inputs:
arcDirectory:
type: Directory
arcDirectory: Directory
firstArg:
type: File
inputBinding:
Expand Down
3 changes: 2 additions & 1 deletion tests/TestingUtils/TestObjects.CWL/Outputs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ let outputs ="""outputs:
type: File
outputBinding:
glob: ./arc/runs/fsResult1/result.csv
example:
example1:
type: Directory
outputBinding:
glob: ./arc/runs/fsResult1/example.csv
example2: Directory
exampleArray1:
type: File[]
outputBinding:
Expand Down

0 comments on commit 95dab47

Please sign in to comment.