问题
如何编写有条件的工作流?
目标
学习如何构造包含条件步骤的工作流。
此工作流包含一个条件步骤,并根据输入执行。这允许工作流基于程序开始时给定的输入参数或前面的步骤跳过额外的步骤。
conditional-workflow.cwl
class: Workflow
cwlVersion: v1.2
inputs:
val: int
steps:
step1:
in:
in1: val
a_new_var: val
run: foo.cwl
when: $(inputs.in1 < 1)
out: [out1]
step2:
in:
in1: val
a_new_var: val
run: foo.cwl
when: $(inputs.a_new_var > 2)
out: [out1]
outputs:
out1:
type: string
outputSource:
- step1/out1
- step2/out1
pickValue: first_non_null
requirements:
InlineJavascriptRequirement: {}
MultipleInputFeatureRequirement: {}
您将注意到的第一件事是,此工作流仅适用于版本1.2或更高版本的CWL标准。
class: Workflow
cwlVersion: v1.2
工作流程的第一步(step1)包含两个输入属性,当条件满足时将执行foo.cwl。新属性when是条件验证发生的位置。在这种情况下,只有当来自工作流的in1包含值< 1时,该步骤才会执行。
steps:
step1:
in:
in1: val
a_new_var: val
run: foo.cwl
when: $(inputs.in1 < 1)
out: [out1]
使用如下命令cwltool cond-wf-003.1.cwl —val 0,该值将通过第一个条件步,并因此被执行,并在日志中通过INFO [step step1] start显示,而第二个步骤被跳过,因为INFO [step step2]将被跳过。
INFO [workflow ] start
INFO [workflow ] starting step step1
INFO [step step1] start
INFO [job step1] /private/tmp/docker_tmpdcyoto2d$ echo
INFO [job step1] completed success
INFO [step step1] completed success
INFO [workflow ] starting step step2
INFO [step step2] will be skipped
INFO [step step2] completed skipped
INFO [workflow ] completed success
{
"out1": "foo 0"
}
INFO Final process status is success
当给出值3时,第一个条件步骤将不会执行,但第二个步骤将cwltool cond-wf-003.1.cwl —val 3。
INFO [workflow ] start
INFO [workflow ] starting step step1
INFO [step step1] will be skipped
INFO [step step1] completed skipped
INFO [workflow ] starting step step2
INFO [step step2] start
INFO [job step2] /private/tmp/docker_tmpqwr93mxx$ echo
INFO [job step2] completed success
INFO [step step2] completed success
INFO [workflow ] completed success
{
"out1": "foo 3"
}
INFO Final process status is success
如果不满足任何条件,例如在使用——val 2时,工作流将引发一个permanentFail。
cwltool cond-wf-003.1.cwl --val 2
INFO [workflow ] start
INFO [workflow ] starting step step1
INFO [step step1] will be skipped
INFO [step step1] completed skipped
INFO [workflow ] starting step step2
INFO [step step2] will be skipped
INFO [step step2] completed skipped
ERROR [workflow ] Cannot collect workflow output: All sources for 'out1' are null
INFO [workflow ] completed permanentFail
WARNING Final process status is permanentFail