1. 问题
    2. 我如何描述哪些参数必须和不能组合使用?
    3. 目标
    4. 学习如何使用记录来描述输入之间的关系。

    有时,一个基础工具有几个必须一起提供的参数(它们是相互依赖的)或几个不能一起提供的参数(它们是互斥的)。您可以使用记录和类型联合将参数组合在一起来描述这两个条件。
    record.cwl

    1. #!/usr/bin/env cwl-runner
    2. cwlVersion: v1.0
    3. class: CommandLineTool
    4. inputs:
    5. dependent_parameters:
    6. type:
    7. type: record
    8. name: dependent_parameters
    9. fields:
    10. itemA:
    11. type: string
    12. inputBinding:
    13. prefix: -A
    14. itemB:
    15. type: string
    16. inputBinding:
    17. prefix: -B
    18. exclusive_parameters:
    19. type:
    20. - type: record
    21. name: itemC
    22. fields:
    23. itemC:
    24. type: string
    25. inputBinding:
    26. prefix: -C
    27. - type: record
    28. name: itemD
    29. fields:
    30. itemD:
    31. type: string
    32. inputBinding:
    33. prefix: -D
    34. outputs:
    35. example_out:
    36. type: stdout
    37. stdout: output.txt
    38. baseCommand: echo

    record-job1.yml

    1. dependent_parameters:
    2. itemA: one
    3. exclusive_parameters:
    4. itemC: three

    输出为

    1. $ cwl-runner record.cwl record-job1.yml
    2. Workflow error, try again with --debug for more information:
    3. Invalid job input record:
    4. record-job1.yml:1:1: the `dependent_parameters` field is not valid because
    5. missing required field `itemB`

    在这个例子上,不能提供itemA就不能提供itemB。

    1. record-job2.yml
    2. dependent_parameters:
    3. itemA: one
    4. itemB: two
    5. exclusive_parameters:
    6. itemC: three
    7. itemD: four

    输出为

    1. $ cwl-runner record.cwl record-job2.yml
    2. record-job2.yml:6:3: invalid field `itemD`, expected one of: 'itemC'
    3. [job record.cwl] /home/example$ echo \
    4. -A \
    5. one \
    6. -B \
    7. two \
    8. -C \
    9. three > /home/example/output.txt
    10. [job record.cwl] completed success
    11. {
    12. "example_out": {
    13. "location": "file:///home/example/11-records/output.txt",
    14. "basename": "output.txt",
    15. "class": "File",
    16. "checksum": "sha1$329fe3b598fed0dfd40f511522eaf386edb2d077",
    17. "size": 23,
    18. "path": "/home/example/output.txt"
    19. }
    20. }
    21. Final process status is success
    22. $ cat output.txt
    23. -A one -B two -C three

    第二个例子中,itemC和itemD是独立的,因此只有itemC被调用,itemD被忽略。
    record-job3.yml

    1. dependent_parameters:
    2. itemA: one
    3. itemB: two
    4. exclusive_parameters:
    5. itemD: four

    输出为

    1. $ cwl-runner record.cwl record-job3.yml
    2. [job record.cwl] /home/example$ echo \
    3. -A \
    4. one \
    5. -B \
    6. two \
    7. -D \
    8. four > /home/example/output.txt
    9. [job record.cwl] completed success
    10. {
    11. "example_out": {
    12. "location": "file:///home/example/output.txt",
    13. "basename": "output.txt",
    14. "class": "File",
    15. "checksum": "sha1$77f572b28e441240a5e30eb14f1d300bcc13a3b4",
    16. "size": 22,
    17. "path": "/home/example/output.txt"
    18. }
    19. }
    20. Final process status is success
    21. $ cat output.txt
    22. -A one -B two -D four

    第三个例子中,只有itemD是被调用的。