Skip to content

Commit

Permalink
Add valueFrom port type conversion example
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaushik Ghose committed Jul 20, 2020
1 parent cc6a200 commit 2d72997
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 1 deletion.
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

<!-- /TOC -->

Expand Down Expand Up @@ -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)).
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.
21 changes: 21 additions & 0 deletions port-matching/tool.cwl
Original file line number Diff line number Diff line change
@@ -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: []
34 changes: 34 additions & 0 deletions port-matching/workflow-value-from.cwl
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions port-matching/workflow.cwl
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2d72997

Please sign in to comment.