问题我如何在另一个位置重用参数值?目标了解如何在描述中使用参数引用。
在前面的示例中,我们使用“tar”程序提取了一个文件。然而,这个示例非常有限,因为它假定我们感兴趣的文件名为“hello.txt,并将其写入.cwl文件中。这不是最好的方式。文件名可能不同或取决于所使用的输入文件。为了避免这种情况,我们可以在作业参数文件(.yml)中指定我们想要的文件名。在这个示例中,您将看到如何从其他字段动态引用输入参数的值,这将允许我们指定要提取的文件名。
tar-param.cwl
#!/usr/bin/env cwl-runnercwlVersion: v1.0class: CommandLineToolbaseCommand: [tar, --extract]inputs:tarfile:type: FileinputBinding:prefix: --fileextractfile:type: stringinputBinding:position: 1outputs:extracted_file:type: FileoutputBinding:glob: $(inputs.extractfile)
tar-param-job.yml
tarfile:class: Filepath: hello.tarextractfile: goodbye.txt
创建输入文件,并在命令行中调用cwl-runner:
$ rm hello.tar || true && touch goodbye.txt && tar -cvf hello.tar goodbye.txt$ cwl-runner tar-param.cwl tar-param-job.yml[job tar-param.cwl] /tmp/tmpwH4ouT$ tar \--extract --file \/tmp/tmpREYiEt/stgd7764383-99c9-4848-af51-7c2d6e5527d9/hello.tar \goodbye.txt[job tar-param.cwl] completed success{"extracted_file": {"location": "file:///home/me/cwl/user_guide/goodbye.txt","basename": "goodbye.txt","class": "File","checksum": "sha1$da39a3ee5e6b4b0d3255bfef95601890afd80709","size": 0,"path": "/home/me/cwl/user_guide/goodbye.txt"}}Final process status is success
某些字段允许用$(…)括起来的参数引用。它们将被计算并替换为所引用的值。
outputs:extracted_out:type: FileoutputBinding:glob: $(inputs.extractfile)
引用是使用Javascript语法的一个子集编写的。在这个例子$(inputs.extractfile),$(inputs[“extractfile”]), and$(inputs[‘extractfile’])中是等价的。
“inputs”变量的值是调用CWL工具时提供的输入对象。
注意,因为文件参数是对象,要获取输入文件的路径,必须引用文件对象上的path字段;要在上面的示例中引用到tar文件的路径,您可以写入$(inputs.tarfile.path)。
什么地方允许参数引用?
只能在某些字段中使用参数引用。这些是:
- From
CommandLineTool- arguments
valueFrom
stdinstdoutstderr- From CommandInputParameter
formatsecondaryFiles- From
inputBindingvalueFrom
- From CommandOutputParamater
formatsecondaryFiles- From CommandOutputBinding
globoutputEval
- arguments
- From Workflow
- From InputParameter and WorkflowOutputParameter
formatsecondaryFiles- From steps
- From WorkflowStepInput
valueFrom
- From WorkflowStepInput
- From InputParameter and WorkflowOutputParameter
- From ExpressionTool
expression- From InputParameter and ExpressionToolOutputParameter
formatsecondaryFiles
- From
ResourceRequirementcoresMincoresMaxramMinramMaxtmpdirMintmpdirMaxoutdirMinoutdirMax
- From
InitialWorkDirRequirementlisting- in Dirent
entryentryname
- From EnvVarRequirement
- From EnvironmentDef
envValue
- From EnvironmentDef
