问题
我如何描述哪些参数必须和不能组合使用?
目标
学习如何使用记录来描述输入之间的关系。
有时,一个基础工具有几个必须一起提供的参数(它们是相互依赖的)或几个不能一起提供的参数(它们是互斥的)。您可以使用记录和类型联合将参数组合在一起来描述这两个条件。
record.cwl
#!/usr/bin/env cwl-runner
cwlVersion: v1.0
class: CommandLineTool
inputs:
dependent_parameters:
type:
type: record
name: dependent_parameters
fields:
itemA:
type: string
inputBinding:
prefix: -A
itemB:
type: string
inputBinding:
prefix: -B
exclusive_parameters:
type:
- type: record
name: itemC
fields:
itemC:
type: string
inputBinding:
prefix: -C
- type: record
name: itemD
fields:
itemD:
type: string
inputBinding:
prefix: -D
outputs:
example_out:
type: stdout
stdout: output.txt
baseCommand: echo
record-job1.yml
dependent_parameters:
itemA: one
exclusive_parameters:
itemC: three
输出为
$ cwl-runner record.cwl record-job1.yml
Workflow error, try again with --debug for more information:
Invalid job input record:
record-job1.yml:1:1: the `dependent_parameters` field is not valid because
missing required field `itemB`
在这个例子上,不能提供itemA就不能提供itemB。
record-job2.yml
dependent_parameters:
itemA: one
itemB: two
exclusive_parameters:
itemC: three
itemD: four
输出为
$ cwl-runner record.cwl record-job2.yml
record-job2.yml:6:3: invalid field `itemD`, expected one of: 'itemC'
[job record.cwl] /home/example$ echo \
-A \
one \
-B \
two \
-C \
three > /home/example/output.txt
[job record.cwl] completed success
{
"example_out": {
"location": "file:///home/example/11-records/output.txt",
"basename": "output.txt",
"class": "File",
"checksum": "sha1$329fe3b598fed0dfd40f511522eaf386edb2d077",
"size": 23,
"path": "/home/example/output.txt"
}
}
Final process status is success
$ cat output.txt
-A one -B two -C three
第二个例子中,itemC和itemD是独立的,因此只有itemC被调用,itemD被忽略。
record-job3.yml
dependent_parameters:
itemA: one
itemB: two
exclusive_parameters:
itemD: four
输出为
$ cwl-runner record.cwl record-job3.yml
[job record.cwl] /home/example$ echo \
-A \
one \
-B \
two \
-D \
four > /home/example/output.txt
[job record.cwl] completed success
{
"example_out": {
"location": "file:///home/example/output.txt",
"basename": "output.txt",
"class": "File",
"checksum": "sha1$77f572b28e441240a5e30eb14f1d300bcc13a3b4",
"size": 22,
"path": "/home/example/output.txt"
}
}
Final process status is success
$ cat output.txt
-A one -B two -D four
第三个例子中,只有itemD是被调用的。