Open alexiswl opened 5 months ago
I can instead create a dummy file object, before evaluating the when condition. I then add this as an element to the source component of the input_file step input parameter.
I then add the pickValue: first_non_null and update the when condition to be when the input_file contents are not empty.
class: Workflow
cwlVersion: v1.2
requirements:
InlineJavascriptRequirement: {}
StepInputExpressionRequirement: {}
MultipleInputFeatureRequirement: {}
inputs:
optional_small_file:
label: Optional File
type: File?
doc: |
This file is an optional file
steps:
generate_dummy_file_object:
in: []
out:
- id: empty_file
run:
class: ExpressionTool
cwlVersion: v1.2
inputs: []
outputs:
empty_file:
type: File
expression: |
${
return {
"empty_file": {
"class": "File",
"basename": "dummy_file.txt",
"contents": ""
}
};
}
get_file_contents:
in:
input_file:
source:
- optional_small_file
- generate_dummy_file_object/empty_file
pickValue: first_non_null
out:
- id: file_contents
when: >-
$( inputs.input_file !== null && inputs.input_file.contents !== "" )
run:
class: ExpressionTool
cwlVersion: v1.2
inputs:
input_file:
type: File
loadContents: true
outputs:
file_contents:
type: string
expression: |
${
return {
"file_contents": inputs.input_file.contents
};
}
outputs:
optional_file_contents:
label: Optional file contents
type: string?
outputSource: get_file_contents/file_contents
5a6,7
> StepInputExpressionRequirement: {}
> MultipleInputFeatureRequirement: {}
14a17,37
> generate_dummy_file_object:
> in: []
> out:
> - id: empty_file
> run:
> class: ExpressionTool
> cwlVersion: v1.2
> inputs: []
> outputs:
> empty_file:
> type: File
> expression: |
> ${
> return {
> "empty_file": {
> "class": "File",
> "basename": "dummy_file.txt",
> "contents": ""
> }
> };
> }
18c41,44
< source: optional_small_file
---
> source:
> - optional_small_file
> - generate_dummy_file_object/empty_file
> pickValue: first_non_null
22c48
< $( inputs.input_file !== null )
---
> $( inputs.input_file !== null && inputs.input_file.contents !== "" )
39c65
<
---
>
A practical example of this use-case is here:
https://github.com/alexiswl/cowsay-motd-cwl/blob/main/workflow/motd_workflow.cwl
In this case, I only want to run step B if I ran step A (because I use an output file of step A as an input in step B), Because step B uses the loadContents on this inputFile, it raises an error if I don't have an empty dummy file as a back up.
Expected Behavior
I have a small workflow below that runs an expression step that collects the file contents.
I want to only run this step if the input is not null.
Although the input file is a mandatory input for the step, I would hope that my workflow could continue because I am skipping the step with the when condition.
Actual Behavior
Unfortunately, because the tool input has a loadContents on the input file parameter, this is run before my 'when' condition on the step. Because the input file does not exist, this fails with the traceback below.
Workflow Code
Full Traceback
Your Environment
cwltool --version