
# 示例
本节通过一个简单的示例说明Cromwell的使用方法。
#### 步骤1：WDL流程文件编写
使用Cromwell首先编写WDL流程文件，定义任务如何工作。Cromwell引擎使用WDL文件描述任务执行流程。
下面是一个简单示例WDL流程示例"example.wdl"。详细解释如下：
- 这个流程一共有3个步骤stepa、stepb、stepc，首先执行stepa，stepa使用firstInput 作为输入，且指定并发数为3；然后执行stepb，stepb使用stepa的输出stepa.out作为输入；然后执行stepc，stepc使用stepb的输出stepb.out作为输入。
- 最后将stepc.out作为最终输出结果。
- stepa、stepb、stepc中都定义了runtime运行时，指定了使用"swr.cn-north-1.myhuaweicloud.com/op_svc_gcs_container/cromwell:1.5.8"这个镜像，且指定了使用的资源大小为1核2G。
```
workflow example{
  File firstInput
  scatter (idx in range(3)) {
    call stepa { input: in=firstInput }
  }
  call stepb { input: in=stepa.out }
  call stepc { input: in=stepb.out }
  output {
    File result = stepc.out
  }
}
task stepa {
  File in
  command { cat ${in} > outputa.txt && cat outputa.txt}
  output { File out = "outputa.txt" }
  runtime {
    docker: "swr.cn-north-1.myhuaweicloud.com/op_svc_gcs_container/cromwell:1.5.8"
    cpu: "1"
    memory: "2G"
  }
}
task stepb {
  Array[File] in
  command { cat ${write_lines(in)} > outputb.txt && cat outputb.txt}
  output { File out = "outputb.txt" }
  runtime {
    docker: "swr.cn-north-1.myhuaweicloud.com/op_svc_gcs_container/cromwell:1.5.8"
    cpu: "1"
    memory: "2G"
  }
}
task stepc {
  File in
  command { cat ${in} > outputc.txt && cat outputc.txt}
  output { File out = "outputc.txt" }
  runtime {
    docker: "swr.cn-north-1.myhuaweicloud.com/op_svc_gcs_container/cromwell:1.5.8"
    cpu: "1"
    memory: "2G"
  }
}
```
上面流程定义了一个输入文件File firstInput，输入文件使用".inputs"文件定义，如下"example.inputs"文件所示，example.firstInput使用"obs://gcs-tool-cn-north-1/example.txt"这个文件作为输入。
```
{
  "example.firstInput": "obs://gcs-tool-cn-north-1/example.txt",
}
```
 #### 步骤2：准备Cromwell环境
- 定义了流程后，需要准备Cromwell环境，Cromwell环境创建方法请参见[创建Cromwell引擎](https://support.huaweicloud.com/cromwell-gcs/create_cormwell_env.html#create_cormwell_env__section15289164371120)。
- example.wdl使用了"swr.cn-north-1.myhuaweicloud.com/op_svc_gcs_container/cromwell:1.5.8"这个镜像，这个镜像是公共镜像，可以直接使用。在其他流程中使用镜像，您需要先制作好镜像，然后上传到华为云容器镜像服务中，然后再使用。
- example.inputs使用了OBS桶中的文件，"obs://gcs-tool-cn-north-1/example.txt"是一个公共可读文件，可以直接使用。在其他流程中使用文件，您可以先上传到OBS中，然后再使用。
 
#### 步骤3：投递任务
环境准备好后，就可以投递任务了。
当前Cromwell引擎可以通过命令行和SDK两种方式使用。
- SDK的使用方法请参见[Python SDK参考](https://support.huaweicloud.com/sdkreference-gcs/gcs_sdkreference_001.html)。初始化后调用Cromwell相关接口即可投递任务。
- 命令行使用方法请参见[命令参考](https://support.huaweicloud.com/clir-gcs/gcs_clir_01_0001.html)。安装命令行工具后，使用[gcs sub wdl](https://support.huaweicloud.com/clir-gcs/gcs_clir_04_0025.html)即可投递Cromwell任务。
这里使用命令行工具作为示例投递任务，如下所示。
```
gcs sub wdl example.wdl -i example.inputs -s gcs-env-test
```
gcs sub wdl是命令，example.wdl是流程文件，-example.inputs为输入文件，gcs-env-test是[步骤2：准备Cromwell环境]中创建的Cromwell环境的名称。
回显内容如下。
```
current environment is gcs-env-test
create wdl succeed
{
"id":
"aa215e0b-c896-4138-865e-6cf7921246b6",
"status": "Submitted",
"message": ""
}
```
#### 步骤4：查看执行结果
任务投递后，您可以在基因容器控制台中实时查看任务的执行过程（包括执行结果热力图）、数据、状态、结果等信息。您还可以使用命令行直接查看，具体请参见[gcs get wdl](https://support.huaweicloud.com/clir-gcs/gcs_clir_04_0026.html)。
图1执行结果   
![](https://support.huaweicloud.com/cromwell-gcs/zh-cn_image_0224957572.png "点击放大")
![](https://support.huaweicloud.com/cromwell-gcs/zh-cn_image_0224958839.png "点击放大")
