diff --git a/README.md b/README.md index 122c075..422e143 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ _Some patterns commonly encountered when writing CWL workflows_ - [Embedding a bash script (style 2)](#embedding-a-bash-script-style-2) - [Manipulating a list of files using expressions](#manipulating-a-list-of-files-using-expressions) - [Link input files to working directory](#link-input-files-to-working-directory) +- [How to handle port type mismatches](#how-to-handle-port-type-mismatches) @@ -90,4 +91,21 @@ Here is an example for [Python](list-of-files-python.cwl) and for You can use `InitialWorkDirRequirement` to link the files ([example](stage-files.cwl)). -You can mix this with embedding scripts ([example](embed-script-and-stage-files.cwl)). \ No newline at end of file +You can mix this with embedding scripts +([example](embed-script-and-stage-files.cwl)). + +## How to handle port type mismatches + +- Tool A produces a list of Files (or strings, ints ...) +- Tool B accepts only a single File (or string, int ...) +- How do I connect A to B? + +If you are _sure_ this is not going to be a problem, e.g. in this context A will +only ever produce one file, or you are only interested in one file, you can use +a step `valueFrom` expression to convert the types. + +[Here](port-matching/workflow.cwl) is a workflow that will raise validation +warnings and will fail on execution because of port type mismatches. + +[Here](port-matching/workflow-value-from.cwl) is the same workflow with +`valueFrom` added to make the port types match. diff --git a/port-matching/tool.cwl b/port-matching/tool.cwl new file mode 100644 index 0000000..1db6f6c --- /dev/null +++ b/port-matching/tool.cwl @@ -0,0 +1,21 @@ +#!/usr/bin/env cwl-runner + +class: CommandLineTool +cwlVersion: v1.0 + +inputs: + in1: string? + in2: string[]? + +outputs: + out1: + type: string? + outputBinding: + outputEval: $(inputs.in1) + out2: + type: string[]? + outputBinding: + outputEval: $(inputs.in2) + +baseCommand: [echo] +arguments: [] diff --git a/port-matching/workflow-value-from.cwl b/port-matching/workflow-value-from.cwl new file mode 100644 index 0000000..e690942 --- /dev/null +++ b/port-matching/workflow-value-from.cwl @@ -0,0 +1,34 @@ +#!/usr/bin/env cwl-runner + +class: Workflow +cwlVersion: v1.0 + +requirements: + StepInputExpressionRequirement: {} + InlineJavascriptRequirement: {} + +inputs: + in1: string? + in2: string[]? + +outputs: + out1: + type: string? + outputSource: step1/out1 + out2: + type: string[]? + outputSource: step1/out2 + +steps: + step1: + in: + in1: + source: in2 + valueFrom: $(self[0]) + in2: + source: in1 + valueFrom: $([self]) + run: tool.cwl + out: + - out1 + - out2 diff --git a/port-matching/workflow.cwl b/port-matching/workflow.cwl new file mode 100644 index 0000000..ae98af5 --- /dev/null +++ b/port-matching/workflow.cwl @@ -0,0 +1,26 @@ +#!/usr/bin/env cwl-runner + +class: Workflow +cwlVersion: v1.0 + +inputs: + in1: string? + in2: string[]? + +outputs: + out1: + type: string? + outputSource: step1/out1 + out2: + type: string[]? + outputSource: step1/out2 + +steps: + step1: + in: + in1: in2 + in2: in1 + run: tool.cwl + out: + - out1 + - out2