【9.3.1.1】CWL inputs

Essential Input Parameters

工具的inputs是控制如何运行工具的输入参数列表。每个参数都有一个id,以及描述哪些类型的值对该参数有效的type。

可用的基元types有string、int、long、float、double和null;复杂的types是 array and record;此外,还有特殊类型File、Directory和Any。

以下示例演示了一些不同类型的输入参数,这些参数以不同的方式出现在命令行上。

inp.cwl

#!/usr/bin/env cwl-runner
cwlVersion: v1.0
class: CommandLineTool
baseCommand: echo
inputs:
  example_flag:
    type: Boolean	#布尔类型。如果输入参数"example_flag"为"真",则将添加到命令行中。如果为“假”,则不添加任何标志。
    inputBinding:
      position: 1
      prefix: -f	#软件参数
  example_string:
    type: string	#字符串类型以其string值显示在命令行上。如果提供,则可选。例如:--example-string hello
    inputBinding:
      position: 3
      prefix: --example-string
  example_int:
    type: int		#整数(和浮点)类型显示在带有十进制文本表示的命令行上。
    inputBinding:
      position: 2
      prefix: -i
      separate: false	#当该项为“假”(默认值为“真”)时,前缀和值合并为单个参数。例如:-i42
  example_file:
    type: File?	#问号结尾代表该参数是可选择的,如果YAML文件中有设置eample_file参数,则该参数有用,例如:--file=/tmp/random/path/whale.txt 
    inputBinding:
      prefix: --file=
      separate: false
      position: 4

outputs: []

inp-job.yml

example_flag: true
example_string: hello
example_int: 42
example_file:
  class: File
  path: whale.txt

您可以使用cwltool来创建一个模板输入对象。这样就不用在输入对象文件中键入所有输入参数:

$ cwltool --make-template inp.cwl
INFO /opt/hostedtoolcache/Python/3.9.14/x64/bin/cwltool 3.1.20221008225030
INFO Resolved 'inp.cwl' to 'file:///home/runner/work/user_guide/user_guide/src/_includes/cwl/inputs/inp.cwl'
example_string: a_string  # type "string"
example_int: 0  # type "int"
example_flag: false  # type "boolean"
example_file:  # type "File" (optional)
    class: File
    path: a/file/path

您可以将输出重定向到一个文件,即

cwltool--make template inp.cwl>inp-job.yml

然后使用所需的输入值修改默认值。

注意 “example_file”,是一个文件类型,必须作为一个对象提供,其字段为class: File和path。

Next, create a whale.txt using touch by typing touch whale.txt on the command line.

touch whale.txt

Now invoke cwltool with the tool description and the input object on the command line, using the command cwltool inp.cwl inp-job.yml. The following boxed text describes these two commands and the expected output from the command line:

$ cwltool inp.cwl inp-job.yml
INFO /opt/hostedtoolcache/Python/3.9.14/x64/bin/cwltool 3.1.20221008225030
INFO Resolved 'inp.cwl' to 'file:///home/runner/work/user_guide/user_guide/src/_includes/cwl/inputs/inp.cwl'
INFO [job inp.cwl] /tmp/af0sscd1$ echo \
    -f \
    -i42 \
    --example-string \
    hello \
    --file=/tmp/0sk_gpqo/stg246c8d07-7cf9-4608-bca3-29137518d40b/whale.txt
-f -i42 --example-string hello --file=/tmp/0sk_gpqo/stg246c8d07-7cf9-4608-bca3-29137518d40b/whale.txt
INFO [job inp.cwl] completed success
{}
INFO Final process status is success

CWL引用运行程序(cwltool)和其他运行程序创建临时目录,其中包含指向输入文件的符号(“软”)链接,以确保工具不会意外访问未明确指定的文件

inputBinding

字段inputBinding是可选的,它指示输入参数是否以及如何显示在工具的命令行上。如果缺少inputBinding,则该参数不会出现在命令行上。让我们详细看看每个例子。

example_flag:
  type: boolean
  inputBinding:
    position: 1
    prefix: -f

Boolean types are treated as a flag. If the input parameter “example_flag” is “true”, then prefix will be added to the command line. If false, no flag is added.

example_string:
  type: string
  inputBinding:
    position: 3
    prefix: --example-string

字符串类型在命令行上显示为文字值。prefix是可选的,如果提供,它将作为单独的参数出现在参数之前的命令行中。在上面的例子中,它被呈现为–example-string hello 。

example_int:
  type: int
  inputBinding:
    position: 2
    prefix: -i
    separate: false

整数(和浮点)类型以十进制文本表示形式出现在命令行上。当选项separate为false(默认值为true)时,前缀和值将合并为一个参数。在上面的示例中,它被渲染为-i42。

example_file: type: File? inputBinding: prefix: –file= separate: false position: 4

文件类型在命令行中显示为文件的路径。参数类型何时以问号结束?则表明该参数是可选的。在上面的示例中,它被呈现为–file=/tmp/random/path/wale.txt。但是,如果输入中没有提供“example_file”参数,则命令行上将不会显示任何内容。

position的值用于确定参数应出现在命令行上的位置。位置是相对的,而不是绝对的。因此,位置不必是顺序的,具有位置1、3、5的三个参数将产生与1、2、3相同的命令行。多个参数可以具有相同的位置(使用参数名称会打破联系),位置字段本身是可选的。默认位置为0。

baseCommand字段将始终显示在参数之前的最终命令行中。

…..

更多高级的用法,后续再总结

….

参考资料

药企,独角兽,苏州。团队长期招人,感兴趣的都可以发邮件聊聊:tiehan@sina.cn
个人公众号,比较懒,很少更新,可以在上面提问题,如果回复不及时,可发邮件给我: tiehan@sina.cn