2.17. 文件格式#
Tools and workflows can take File
types as input and produce them as output.
We also recommend indicating the format for File
types. This helps document
for others how to use your tool while allowing you to do some simple
type-checking when creating parameter files.
对于文件格式,我们建议参考现有本体(如示例中的 EDAM)或您所在机构内部使用的本体,不然,则在与他人共享工具之前不要先添加文件格式,以便快速开发。您可以通过网站浏览现有的 IANA 和 EDAM 文件格式列表。
我们将在下一篇教程中更详细地解释文件中的 $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. 该文件位于 common-workflow-language/user_guide, 可以用 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 /opt/hostedtoolcache/Python/3.9.19/x64/bin/cwltool 3.1.20240508115724
INFO Resolved 'metadata_example.cwl' to 'file:///home/runner/work/user_guide/user_guide/src/_includes/cwl/file-formats/metadata_example.cwl'
INFO [job metadata_example.cwl] /tmp/bcocshwo$ wc \
-l \
/tmp/nf0k_pwk/stgdd26a5b2-ed62-451f-a748-351d4673b68c/file-formats.bam > /tmp/bcocshwo/output.txt
INFO [job metadata_example.cwl] completed success
{
"report": {
"location": "file:///home/runner/work/user_guide/user_guide/src/_includes/cwl/file-formats/output.txt",
"basename": "output.txt",
"class": "File",
"checksum": "sha1$1822060fa6e723cded96854d0b8f6a03146696c0",
"size": 77,
"format": "http://edamontology.org/format_1964",
"path": "/home/runner/work/user_guide/user_guide/src/_includes/cwl/file-formats/output.txt"
}
}INFO Final process status is success