Skip to content

Commit 04dd944

Browse files
committed
Add text about the exclusive input parameters and expressions
1 parent fc1c19f commit 04dd944

File tree

7 files changed

+96
-11
lines changed

7 files changed

+96
-11
lines changed

src/_includes/cwl/conformance-test.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,13 @@
103103

104104
# Section 11 depends on side-effects
105105
- doc: Test for section 11 (1st example)
106-
job: 11-records/record-job1.yml
107-
tool: 11-records/record.cwl
106+
job: inputs/record-job1.yml
107+
tool: inputs/record.cwl
108108
should_fail: true
109109

110110
- doc: Test for section 11 (2nd example)
111-
job: 11-records/record-job2.yml
112-
tool: 11-records/record.cwl
111+
job: inputs/record-job2.yml
112+
tool: inputs/record.cwl
113113
output:
114114
example_out:
115115
class: File
@@ -119,8 +119,8 @@
119119
size: 23
120120

121121
- doc: Test for section 11 (3rd example)
122-
job: 11-records/record-job3.yml
123-
tool: 11-records/record.cwl
122+
job: inputs/record-job3.yml
123+
tool: inputs/record.cwl
124124
output:
125125
example_out:
126126
class: File
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+
output_format:
6+
type:
7+
- 'null'
8+
- name: output_format
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.output_format)
24+
25+
baseCommand: 'true'
File renamed without changes.

src/topics/inputs.md

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,13 @@ together (they are dependent) or several arguments that cannot be provided
207207
together (they are exclusive). You can use records and type unions to group
208208
parameters together to describe these two conditions.
209209

210-
```{literalinclude} /_includes/cwl/11-records/record.cwl
210+
```{literalinclude} /_includes/cwl/inputs/record.cwl
211211
:language: cwl
212212
:caption: "`record.cwl`"
213213
:name: record.cwl
214214
```
215215

216-
```{literalinclude} /_includes/cwl/11-records/record-job1.yml
216+
```{literalinclude} /_includes/cwl/inputs/record-job1.yml
217217
:language: yaml
218218
:caption: "`record-job1.yml`"
219219
:name: record-job1.yml
@@ -232,7 +232,7 @@ record-job1.yml:1:1: the `dependent_parameters` field is not valid because
232232

233233
In the first example, you can't provide `itemA` without also providing `itemB`.
234234

235-
```{literalinclude} /_includes/cwl/11-records/record-job2.yml
235+
```{literalinclude} /_includes/cwl/inputs/record-job2.yml
236236
:language: yaml
237237
:caption: "`record-job2.yml`"
238238
:name: record-job2.yml
@@ -269,7 +269,7 @@ $ cat output.txt
269269
In the second example, `itemC` and `itemD` are exclusive, so only `itemC`
270270
is added to the command line and `itemD` is ignored.
271271

272-
```{literalinclude} /_includes/cwl/11-records/record-job3.yml
272+
```{literalinclude} /_includes/cwl/inputs/record-job3.yml
273273
:language: yaml
274274
:caption: "`record-job3.yml`"
275275
:name: record-job3.yml
@@ -306,7 +306,67 @@ $ cat output.txt
306306
In the third example, only `itemD` is provided, so it appears on the
307307
command line.
308308

309-
```{note}```
309+
### Exclusive Input Parameters with Expressions
310+
311+
If you use exclusive input parameters combined with expressions, you need to be
312+
aware that the `inputs` JavaScript object will contain one of the exclusive
313+
input values. This means that you might need to use an **or** boolean operator
314+
to check which values are present.
315+
316+
Let's use an example that contains an exclusive `output_format` input parameter
317+
that accepts `null` (i.e. no value provided), or any value from an enum.
318+
319+
```{literalinclude} /_includes/cwl/inputs/exclusive-parameter-expressions.cwl
320+
:language: cwl
321+
:caption: "`exclusive-parameter-expressions.cwl`"
322+
:name: exclusive-parameter-expressions.cwl
323+
:emphasize-lines: 7, 21-23
324+
```
325+
326+
Note how the JavaScript expression uses the value of the exclusive input parameter
327+
without taking into consideration a `null` value. If you provide a valid value,
328+
such as “fasta” (one of the values of the enum), your command should execute
329+
successfully:
330+
331+
```{code-block} console
332+
$ cwltool exclusive-parameter-expressions.cwl --output_format fasta
333+
INFO /home/kinow/Development/python/workspace/user_guide/venv/bin/cwltool 3.1.20220830195442
334+
INFO Resolved 'exclusive-parameter-expressions.cwl' to 'file:///tmp/exclusive-parameter-expressions.cwl'
335+
INFO [job exclusive-parameter-expressions.cwl] /tmp/j02lo8ky$ true \
336+
--format \
337+
fasta
338+
INFO [job exclusive-parameter-expressions.cwl] completed success
339+
{
340+
"text_output": "fasta"
341+
}
342+
INFO Final process status is success
343+
```
344+
345+
However, if you do not provide any input value, then `output_format` will be
346+
evaluated to a `null` value, which does not match the expected type for the
347+
output field (a `string`), resulting in failure when running your workflow.
348+
349+
```{code-block} console
350+
:emphasize-lines: 6-10
351+
$ cwltool exclusive-parameter-expressions.cwl
352+
INFO /home/kinow/Development/python/workspace/user_guide/venv/bin/cwltool 3.1.20220830195442
353+
INFO Resolved 'exclusive-parameter-expressions.cwl' to 'file:///tmp/exclusive-parameter-expressions.cwl'
354+
INFO [job exclusive-parameter-expressions.cwl] /tmp/jmq3nqap$ true
355+
ERROR [job exclusive-parameter-expressions.cwl] Job error:
356+
Error validating output record. the `text_output` field is not valid because
357+
the value is not string
358+
in {
359+
"text_output": null
360+
}
361+
WARNING [job exclusive-parameter-expressions.cwl] completed permanentFail
362+
{}
363+
WARNING Final process status is permanentFail
364+
```
365+
366+
To correct it, you must remember to use an or operator in your JavaScript expression
367+
when using exclusive parameters, or any parameter that allows `null`. For example,
368+
the expression could be changed to `$(inputs.output_format || 'auto')`, to have
369+
a default value if none was provided in the command line or job input file.
310370

311371
% TODO
312372
%

0 commit comments

Comments
 (0)