1.1. 快速入门#
本节将为您概述 CWL 是什么,以及在何处可以进一步学习。您不需要有 CWL 知识储备,但要能较为自如地按照文中指示操作命令行。
1.1.1. “Hello World”(“世界您好”程序)#
CWL 的作用在于描述各种命令行工具,并且将它们连接起来,以创建工作流 (workflow)。CWL 是一种规范,而非某种特定的软件。因此,由 CWL 描述的工具和工作流能够移植到支持 CWL 标准的多种平台。
CWL 文件按照 YAML 或者 JSON 格式编写的。下例演示了一个简单的 CWL 工作流“Hello World”,并且标有注释,即 #
符号后面的文字:
hello_world.cwl
#cwlVersion: v1.2
# What type of CWL process we have in this document.
class: CommandLineTool
# This CommandLineTool executes the linux "echo" command-line tool.
baseCommand: echo
# The inputs for this process.
inputs:
message:
type: string
# A default value that can be overridden, e.g. --message "Hola mundo"
default: "Hello World"
# Bind this message value as an argument to "echo".
inputBinding:
position: 1
outputs: []
上面的示例不过是 echo
命令行工具的包装器 (wrapper). 使用默认输入值运行上述工作流,产生的结果会和命令 echo "Hello World"
别无二致。
备注
CWL 中“命令行工具”和“工作流”是有所区别的。但为了简单起见,这里我们仍然用了“工作流”一次。更多有关信息可在《基本概念》一节中学到。
1.1.2. 安装 CWL 运行程序#
cwltool
是 CWL 规约的一种实现,也为该规约编写的 CWL 参考运行程序。它符合规约的最新版本 v1.2
版。您可用 pip
安装 cwltool
:
pip
安装 cwltool
.#$ pip install cwltool
备注
如果您无法用 pip 命令安装 cwltool,请参阅《学习前的准备》 一节,了解安装 cwltool
的其他方法,以及继续学习《用户指南》所需软件和库的详细列表。
1.1.3. 运行“Hello World”#
The usage of the cwltool
command-line executable is basically
cwltool [OPTIONS] [CWL_DOCUMENT] [INPUTS_OBJECT]
. You can run the
hello_world.cwl
workflow without specifying any option:
cwltool
运行 hello_world.cwl
.#$ cwltool hello_world.cwl
INFO /opt/hostedtoolcache/Python/3.9.19/x64/bin/cwltool 3.1.20240508115724
INFO Resolved 'hello_world.cwl' to 'file:///home/runner/work/user_guide/user_guide/src/_includes/cwl/hello_world.cwl'
INFO [job hello_world.cwl] /tmp/neh61eyn$ echo \
'Hello World'
Hello World
INFO [job hello_world.cwl] completed success
{}INFO Final process status is success
您还可以撤销输入参数 message
的默认值,有如更改 echo
基本命令的参数:
cwltool
传递输入参数值运行 hello_world.cwl
.#$ cwltool hello_world.cwl --message="Hola mundo"
INFO /opt/hostedtoolcache/Python/3.9.19/x64/bin/cwltool 3.1.20240508115724
INFO Resolved 'hello_world.cwl' to 'file:///home/runner/work/user_guide/user_guide/src/_includes/cwl/hello_world.cwl'
INFO [job hello_world.cwl] /tmp/4gf6c3oy$ echo \
'Hola mundo'
Hola mundo
INFO [job hello_world.cwl] completed success
{}INFO Final process status is success
将值传递给工作流输入参数的另一种方法是利用输入对象 (Inputs Object)。它是由输入字段及其相应值构成的文件,可使用 JSON 或 YAML 格式编写。例如:
hello_world-job.json
#{
"message": "こんにちは世界"
}
这样就可以在执行“Hello World”工作流时使用此输入对象文件:
cwltool
.#$ cwltool hello_world.cwl hello_world-job.json
INFO /opt/hostedtoolcache/Python/3.9.19/x64/bin/cwltool 3.1.20240508115724
INFO Resolved 'hello_world.cwl' to 'file:///home/runner/work/user_guide/user_guide/src/_includes/cwl/hello_world.cwl'
INFO [job hello_world.cwl] /tmp/21a5suid$ echo \
こんにちは世界
こんにちは世界
INFO [job hello_world.cwl] completed success
{}INFO Final process status is success
备注
我们为工作流和输入对象文件起了类似的文件名。输入对象文件名中的 -job.json 后缀是很常见的,但并非规定。工作流和输入对象文件的命名方式可由您任意选择。
1.1.4. 了解更多信息#
请继续阅读《用户指南》后续部分!