Skip to content

Commit 50d824f

Browse files
kinowmr-c
andauthored
Add section about exclusive params with expressions, and emphasize command output lines (#247)
* Highlight lines of interest in the command outputs * Rename "Advanced Inputs" to "Inclusive and Exclusive Inputs" * Add text about the exclusive input parameters and expressions * explain why itemC was chosen when both are provided Co-authored-by: Michael R. Crusoe <[email protected]>
1 parent 76dd547 commit 50d824f

File tree

2 files changed

+71
-4
lines changed

2 files changed

+71
-4
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
cwlVersion: v1.2
2+
class: CommandLineTool
3+
4+
inputs:
5+
file_format:
6+
type:
7+
- 'null'
8+
- name: format_choices
9+
type: enum
10+
symbols:
11+
- auto
12+
- fasta
13+
- fastq
14+
- fasta.gz
15+
- fastq.gz
16+
inputBinding:
17+
position: 0
18+
prefix: '--format'
19+
outputs:
20+
text_output:
21+
type: string
22+
outputBinding:
23+
outputEval: $(inputs.file_format)
24+
25+
baseCommand: 'true'

src/topics/inputs.md

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ This will be demonstrated in the next lesson
188188
and is discussed in more detail in the [YAML Guide](yaml-guide.md#arrays).
189189
You can specify arrays of arrays, arrays of records, and other complex types.
190190

191-
## Advanced Inputs
191+
## Inclusive and Exclusive Inputs
192192

193193
Sometimes an underlying tool has several arguments that must be provided
194194
together (they are dependent) or several arguments that cannot be provided
@@ -209,6 +209,7 @@ parameters together to describe these two conditions.
209209

210210
```{runcmd} cwltool record.cwl record-job1.yml
211211
:working-directory: src/_includes/cwl/inputs/
212+
:emphasize-lines: 6-7
212213
```
213214

214215
In the first example, you can't provide `itemA` without also providing `itemB`.
@@ -221,15 +222,16 @@ In the first example, you can't provide `itemA` without also providing `itemB`.
221222

222223
```{runcmd} cwltool record.cwl record-job2.yml
223224
:working-directory: src/_includes/cwl/inputs
225+
:emphasize-lines: 3, 9-10, 24
224226
````
225227
226228
```{code-block} console
227229
$ cat output.txt
228230
-A one -B two -C three
229231
```
230232

231-
In the second example, `itemC` and `itemD` are exclusive, so only `itemC`
232-
is added to the command line and `itemD` is ignored.
233+
In the second example, `itemC` and `itemD` are exclusive, so only the first
234+
matching item (`itemC`) is added to the command line and remaining item (`itemD`) is ignored.
233235

234236
```{literalinclude} /_includes/cwl/inputs/record-job3.yml
235237
:language: yaml
@@ -239,6 +241,7 @@ is added to the command line and `itemD` is ignored.
239241

240242
```{runcmd} cwltool record.cwl record-job3.yml
241243
:working-directory: src/_includes/cwl/inputs
244+
:emphasize-lines: 9-10, 24
242245
````
243246
244247
```{code-block} console
@@ -249,10 +252,49 @@ $ cat output.txt
249252
In the third example, only `itemD` is provided, so it appears on the
250253
command line.
251254

255+
### Exclusive Input Parameters with Expressions
256+
257+
If you use exclusive input parameters combined with expressions, you need to be
258+
aware that the `inputs` JavaScript object will contain one of the exclusive
259+
input values. This means that you might need to use an **or** boolean operator
260+
to check which values are present.
261+
262+
Let's use an example that contains an exclusive `file_format` input parameter
263+
that accepts `null` (i.e. no value provided), or any value from an enum.
264+
265+
```{literalinclude} /_includes/cwl/inputs/exclusive-parameter-expressions.cwl
266+
:language: cwl
267+
:caption: "`exclusive-parameter-expressions.cwl`"
268+
:name: exclusive-parameter-expressions.cwl
269+
:emphasize-lines: 7, 21-23
270+
```
271+
272+
Note how the JavaScript expression uses the value of the exclusive input parameter
273+
without taking into consideration a `null` value. If you provide a valid value,
274+
such as “fasta” (one of the values of the enum), your command should execute
275+
successfully:
276+
277+
```{runcmd} cwltool exclusive-parameter-expressions.cwl --file_format fasta
278+
:working-directory: src/_includes/cwl/inputs
279+
````
280+
281+
However, if you do not provide any input value, then `file_format` will be
282+
evaluated to a `null` value, which does not match the expected type for the
283+
output field (a `string`), resulting in failure when running your workflow.
284+
285+
```{runcmd} cwltool exclusive-parameter-expressions.cwl
286+
:working-directory: src/_includes/cwl/inputs
287+
:emphasize-lines: 6-10
288+
```
289+
290+
To correct it, you must remember to use an or operator in your JavaScript expression
291+
when using exclusive parameters, or any parameter that allows `null`. For example,
292+
the expression could be changed to `$(inputs.file_format || 'auto')`, to have
293+
a default value if none was provided in the command line or job input file.
294+
252295
% TODO
253296
%
254297
% - Explain its fields, such as default, valueFrom, etc. - https://github.com/common-workflow-language/common-workflow-language/issues/359
255-
% - Exclusive parameters https://github.com/common-workflow-language/user_guide/issues/162
256298
% - Optional Inputs https://github.com/common-workflow-language/user_guide/issues/44
257299
% - Several ways of defining inputs/arguments to tools and workflows - https://github.com/common-workflow-language/user_guide/issues/33
258300
% - Using an input output in another input - https://github.com/common-workflow-language/user_guide/issues/90

0 commit comments

Comments
 (0)