2.11. 抽象操作#

抽象操作 (Operation) 与工作流、命令行工具或表达式工具类似,是一种 CWL 流程。作为工作流中的一个步骤,它可以指定输入和输出,但不完全提供具体执行所需的信息。

在开发周期中,工作流准备就绪、可以提交给 CWL 运行程序之前,您可以创建抽象操作,将工作流可视化:

operations.cwl#
cwlVersion: v1.2
class: Workflow


inputs:
  message: string
outputs: []

steps:
  echo:
    run: ../echo.cwl
    in:
      message: message
    out: [out]
  # Here you know you want an operation that changes the case of
  # the previous step, but you do not have an implementation yet.
  uppercase:
    run:
      class: Operation
      inputs:
        message: string
      outputs:
        uppercase_message: string
    in:
      message:
        source: echo/out
    out: [uppercase_message]

The uppercase step of the workflow is an operation. It can appear where a command line tool or an expression is expected. You can also plot it with the CWL Viewer or cwltool:

$ cwltool --print-dot operations.cwl
INFO /home/docs/checkouts/readthedocs.org/user_builds/common-workflow-languageuser-guide-zh-hans/envs/latest/bin/cwltool 3.1.20240508115724
INFO Resolved 'operations.cwl' to 'file:///home/docs/checkouts/readthedocs.org/user_builds/common-workflow-languageuser-guide-zh-hans/checkouts/latest/src/_includes/cwl/operations/operations.cwl'
digraph G {
bgcolor="#eeeeee";
clusterrank=local;
labeljust=right;
labelloc=bottom;
"echo" [fillcolor=lightgoldenrodyellow, label=echo, shape=record, style=filled];
"uppercase" [fillcolor=lightgoldenrodyellow, label=uppercase, shape=record, style=dashed];
"echo" -> "uppercase";
subgraph cluster_inputs {
label="Workflow Inputs";
rank=same;
style=dashed;
"message" [fillcolor="#94DDF4", label=message, shape=record, style=filled];
}

"message" -> "echo";
subgraph cluster_outputs {
label="Workflow Outputs";
labelloc=b;
rank=same;
style=dashed;
}

}

The output of the command above can be rendered cwltool --print-dot operations.cwl | dot -Tsvg > operations.svg ; open operations.svg.

digraph G { bgcolor="#eeeeee"; clusterrank=local; labeljust=right; labelloc=bottom; "echo" [fillcolor=lightgoldenrodyellow, label=echo, shape=record, style=filled]; "uppercase" [fillcolor=lightgoldenrodyellow, label=uppercase, shape=record, style=dashed]; "echo" -> "uppercase"; subgraph cluster_inputs { label="Workflow Inputs"; rank=same; style=dashed; "message" [fillcolor="#94DDF4", label=message, shape=record, style=filled]; } "message" -> "echo"; subgraph cluster_outputs { label="Workflow Outputs"; labelloc=b; rank=same; style=dashed; } }

The operation file will fail to run with cwltool because cwltool lacks the necessary information to execute it:

cwltool 不知道如何运行抽象操作#
$ cwltool operations.cwl --message Hello
INFO /home/docs/checkouts/readthedocs.org/user_builds/common-workflow-languageuser-guide-zh-hans/envs/latest/bin/cwltool 3.1.20240508115724
INFO Resolved 'operations.cwl' to 'file:///home/docs/checkouts/readthedocs.org/user_builds/common-workflow-languageuser-guide-zh-hans/checkouts/latest/src/_includes/cwl/operations/operations.cwl'
ERROR Workflow error, try again with --debug for more information:
operations.cwl:19:7: Workflow has unrunnable abstract Operation

备注

CWL 运行程序可能安排一些将抽象操作绑定到具体步骤的方法。例如,带有 ID 的抽象操作有可能对映到其他工作流引擎中执行的步骤。