@@ -188,7 +188,7 @@ This will be demonstrated in the next lesson
188
188
and is discussed in more detail in the [ YAML Guide] ( yaml-guide.md#arrays ) .
189
189
You can specify arrays of arrays, arrays of records, and other complex types.
190
190
191
- ## Advanced Inputs
191
+ ## Inclusive and Exclusive Inputs
192
192
193
193
Sometimes an underlying tool has several arguments that must be provided
194
194
together (they are dependent) or several arguments that cannot be provided
@@ -209,6 +209,7 @@ parameters together to describe these two conditions.
209
209
210
210
``` {runcmd} cwltool record.cwl record-job1.yml
211
211
:working-directory: src/_includes/cwl/inputs/
212
+ :emphasize-lines: 6-7
212
213
```
213
214
214
215
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`.
221
222
222
223
``` {runcmd} cwltool record.cwl record-job2.yml
223
224
:working-directory: src/_includes/cwl/inputs
225
+ :emphasize-lines: 3, 9-10, 24
224
226
````
225
227
226
228
```{code-block} console
227
229
$ cat output.txt
228
230
-A one -B two -C three
229
231
```
230
232
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.
233
235
234
236
``` {literalinclude} /_includes/cwl/inputs/record-job3.yml
235
237
:language: yaml
@@ -239,6 +241,7 @@ is added to the command line and `itemD` is ignored.
239
241
240
242
``` {runcmd} cwltool record.cwl record-job3.yml
241
243
:working-directory: src/_includes/cwl/inputs
244
+ :emphasize-lines: 9-10, 24
242
245
````
243
246
244
247
```{code-block} console
@@ -249,10 +252,49 @@ $ cat output.txt
249
252
In the third example, only ` itemD ` is provided, so it appears on the
250
253
command line.
251
254
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
+
252
295
% TODO
253
296
%
254
297
% - 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
256
298
% - Optional Inputs https://github.com/common-workflow-language/user_guide/issues/44
257
299
% - Several ways of defining inputs/arguments to tools and workflows - https://github.com/common-workflow-language/user_guide/issues/33
258
300
% - Using an input output in another input - https://github.com/common-workflow-language/user_guide/issues/90
0 commit comments