2.17. 文件格式#

File 类型既可作为工具和工作流的输入,也可以成为它们生成的输出。另外,我们建议指明 File 类型的格式,以便向他人说明您的工具如何使用,同时还能让您在创建参数文件时进行简单的类型检验。

对于文件格式,我们建议参考现有本体(如示例中的 EDAM)或您所在机构内部使用的本体,不然,则在与他人共享工具之前不要先添加文件格式,以便快速开发。您可以通过网站浏览现有的 IANAEDAM 文件格式列表

我们将在下一篇教程中更详细地解释文件中的 $namespaces$schemas 部分,眼下无需为此分心。

请注意, cwltool 有一项附加功能,即依据文件格式做一些初步推断,一旦出现较明显的不匹配则发出警告。

metadata_example.cwl#
#!/usr/bin/env cwl-runner
cwlVersion: v1.2
class: CommandLineTool

label: An example tool demonstrating metadata.

inputs:
  aligned_sequences:
    type: File
    label: Aligned sequences in BAM format
    format: edam:format_2572
    inputBinding:
      position: 1

baseCommand: [ wc, -l ]

stdout: output.txt

outputs:
  report:
    type: stdout
    format: edam:format_1964
    label: A text file that contains a line count

$namespaces:
  edam: http://edamontology.org/
$schemas:
  - http://edamontology.org/EDAM_1.18.owl

这一 CWL 描述的等效命令行形式为:

$ wc -l /path/to/aligned_sequences.ext > output.txt

2.17.1. 参数文件样本#

以上例子的样本参数文件见下。我们提倡为您的工具加入经您测试可用的参数文件样例,这将帮助他人从做好的“合格品”参数文件入手,更快地上手操作您的工具。

sample.yml#
aligned_sequences:
    class: File
    format: http://edamontology.org/format_2572
    path: file-formats.bam

注意: 按照下例演练前,您需要先下载示例输入文件 file-formats.bam. 该文件位于 https://github.com/common-workflow-language/user_guide/raw/main/src/_includes/cwl/file-formats/file-formats.bam, 可以用 wget 等工具下载:

$ wget https://github.com/common-workflow-language/user_guide/raw/main/src/_includes/cwl/file-formats/file-formats.bam

现在,在命令行上以工具描述和输入对象为参数调用 cwltool:

$ cwltool metadata_example.cwl sample.yml
INFO /home/docs/checkouts/readthedocs.org/user_builds/common-workflow-languageuser-guide-zh-hans/envs/latest/bin/cwltool 3.2.20260411152607
INFO Resolved 'metadata_example.cwl' to 'file:///home/docs/checkouts/readthedocs.org/user_builds/common-workflow-languageuser-guide-zh-hans/checkouts/latest/src/_includes/cwl/file-formats/metadata_example.cwl'
INFO [job metadata_example.cwl] /tmp/q9t4daax$ wc \
    -l \
    /tmp/3z8xzflc/stg0a8168c1-c91a-4215-8e9d-f62f4cd63329/file-formats.bam > /tmp/q9t4daax/output.txt
INFO [job metadata_example.cwl] completed success
{
    "report": {
        "location": "file:///home/docs/checkouts/readthedocs.org/user_builds/common-workflow-languageuser-guide-zh-hans/checkouts/latest/src/_includes/cwl/file-formats/output.txt",
        "basename": "output.txt",
        "class": "File",
        "checksum": "sha1$0d46d23aba5a477396681cf6a306e5cd78db01f9",
        "size": 77,
        "format": "http://edamontology.org/format_1964",
        "path": "/home/docs/checkouts/readthedocs.org/user_builds/common-workflow-languageuser-guide-zh-hans/checkouts/latest/src/_includes/cwl/file-formats/output.txt"
    }
}INFO Final process status is success