CWL User Guide 22: Nested Workflows をやってみた

# CWL User Guide 22: Nested Workflows

[Common Workflow Language User Guide: Nested Workflows](http://www.commonwl.org/user_guide/22-nested-workflows/)

今回は、ワークフローから別のワークフローを実行する方法について書かれています

21で使ったファイルが必要です。

# この回にでてくる主なキーワード
* SubworkflowFeatureRequirement
* steps
* run

# CWLファイル、1st-workflow.cwl

```1st-workflow.cwl
#!/usr/bin/env cwl-runner

cwlVersion: v1.0
class: Workflow

inputs: []

outputs:
  classout:
    type: File
    outputSource: compile/classout

requirements:
  - class: SubworkflowFeatureRequirement

steps:
  compile:
    run: 1st-workflow.cwl
    in:
      inp:
        source: create-tar/tar
      ex:
        default: "Hello.java"
    out: [classout]

  create-tar:
    requirements:
      - class: InitialWorkDirRequirement
        listing:
          - entryname: Hello.java
            entry: |
              public class Hello {
                public static void main(String[] argv) {
                    System.out.println("Hello from Java");
                }
              }
    in: []
    out: [tar]
    run:
      class: CommandLineTool
      requirements:
        - class: ShellCommandRequirement
      arguments:
        - shellQuote: false
          valueFrom: |
            date
            tar cf hello.tar Hello.java
            date
      inputs: []
      outputs:
        tar:
          type: File
          outputBinding:
            glob: "hello.tar"
```
# パラメータファイル

# 必要なファイル

# 実行

## 実行前確認

`Hello.class` がないことが確認できる

```
$ rm Hello.class
$ ls
1st-workflow.cwl  1st-workflow-job.yml  arguments.cwl  hello.tar  nestedworkflows.cwl  tar-param.cwl
```

## 実行方法

```
cwltool nestedworkflows.cwl
```

## 実行結果

```console
$ cwltool nestedworkflows.cwl
/usr/local/bin/cwltool 1.0.20171107133715
Resolved 'nestedworkflows.cwl' to 'file:///home/vagrant/cwl_user_guide_work/22-nested-workflows/nestedworkflows.cwl'
[workflow nestedworkflows.cwl] start
[step create-tar] start
[job create-tar] /tmp/tmpt2A3Xw$ /bin/sh \
    -c \
    date
tar cf hello.tar Hello.java
date

Thu Nov 30 03:15:03 JST 2017
Thu Nov 30 03:15:03 JST 2017
[job create-tar] completed success
[step create-tar] completed success
[step compile] start
[workflow compile] start
[step untar] start
[job untar] /tmp/tmpEBE2wd$ tar \
    xf \
    /tmp/tmpAH6U2b/stg9793e8a3-8740-4369-a505-8cb462d77eec/hello.tar \
    Hello.java
[job untar] completed success
[step untar] completed success
[step compile_2] start
[job compile] /tmp/tmpKIJ0en$ docker \
    run \
    -i \
    --volume=/tmp/tmpKIJ0en:/var/spool/cwl:rw \
    --volume=/tmp/tmpH86w67:/tmp:rw \
    --volume=/tmp/tmpEBE2wd/Hello.java:/var/lib/cwl/stg074cefaf-ea7a-42cc-b59e-2607c8ec1c6a/Hello.java:ro \
    --workdir=/var/spool/cwl \
    --read-only=true \
    --user=1000:1000 \
    --rm \
    --env=TMPDIR=/tmp \
    --env=HOME=/var/spool/cwl \
    java:7-jdk \
    javac \
    -d \
    /var/spool/cwl \
    /var/lib/cwl/stg074cefaf-ea7a-42cc-b59e-2607c8ec1c6a/Hello.java
[job compile] completed success
[step compile_2] completed success
[workflow compile] completed success
[step compile] completed success
[workflow nestedworkflows.cwl] completed success
{
    "classout": {
        "checksum": "sha1$36478d3310a80ef7a3f1a7d91d258ec51dcc08ad",
        "basename": "Hello.class",
        "location": "file:///home/vagrant/cwl_user_guide_work/22-nested-workflows/Hello.class",
        "path": "/home/vagrant/cwl_user_guide_work/22-nested-workflows/Hello.class",
        "class": "File",
        "size": 419
    }
}
Final process status is success
```


## 実行結果確認

`Hello.class` が作成されたことが確認できる

```
$ ls
1st-workflow.cwl  1st-workflow-job.yml  arguments.cwl  Hello.class  hello.tar  nestedworkflows.cwl  tar-param.cwl
$ ls Hello.class
Hello.class
```

# 今回使ったファイル

[cwl\_user\_guide\_work/22\-nested\-workflows at master · manabuishii/cwl\_user\_guide\_work](https://github.com/manabuishii/cwl_user_guide_work/tree/master/22-nested-workflows)