|
| 1 | +--- |
| 2 | +title: "Writing Workflows" |
| 3 | +teaching: 10 |
| 4 | +exercises: 0 |
| 5 | +questions: |
| 6 | +- "How do I connect tools together into a workflow?" |
| 7 | +objectives: |
| 8 | +- "Learn how to construct workflows from multiple CWL tool descriptions." |
| 9 | +keypoints: |
| 10 | +- "Each step in a workflow must have its own CWL description." |
| 11 | +- "Top level inputs and outputs of the workflow are described in the `inputs` |
| 12 | +and `outputs` fields respectively." |
| 13 | +- "The steps are specified under `steps`." |
| 14 | +- "Execution order is determined by the flow of inputs and outputs between |
| 15 | +steps." |
| 16 | +--- |
| 17 | +This workflow extracts a java source file from a tar file and then |
| 18 | +compiles it. |
| 19 | + |
| 20 | +*1st-workflow.cwl* |
| 21 | + |
| 22 | +``` |
| 23 | +{% include cwl/1st-workflow.cwl %} |
| 24 | +``` |
| 25 | + |
| 26 | +Use a JSON object in a separate file to describe the input of a run: |
| 27 | + |
| 28 | +*1st-workflow-job.yml* |
| 29 | + |
| 30 | +``` |
| 31 | +{% include cwl/1st-workflow-job.yml %} |
| 32 | +``` |
| 33 | + |
| 34 | +Now invoke `cwl-runner` with the tool wrapper and the input object on the |
| 35 | +command line: |
| 36 | + |
| 37 | +``` |
| 38 | +$ echo "public class Hello {}" > Hello.java && tar -cvf hello.tar Hello.java |
| 39 | +$ cwl-runner 1st-workflow.cwl 1st-workflow-job.yml |
| 40 | +[job untar] /tmp/tmp94qFiM$ tar xf /home/example/hello.tar Hello.java |
| 41 | +[step untar] completion status is success |
| 42 | +[job compile] /tmp/tmpu1iaKL$ docker run -i --volume=/tmp/tmp94qFiM/Hello.java:/var/lib/cwl/job301600808_tmp94qFiM/Hello.java:ro --volume=/tmp/tmpu1iaKL:/var/spool/cwl:rw --volume=/tmp/tmpfZnNdR:/tmp:rw --workdir=/var/spool/cwl --read-only=true --net=none --user=1001 --rm --env=TMPDIR=/tmp java:7 javac -d /var/spool/cwl /var/lib/cwl/job301600808_tmp94qFiM/Hello.java |
| 43 | +[step compile] completion status is success |
| 44 | +[workflow 1st-workflow.cwl] outdir is /home/example |
| 45 | +Final process status is success |
| 46 | +{ |
| 47 | + "classout": { |
| 48 | + "location": "/home/example/Hello.class", |
| 49 | + "checksum": "sha1$e68df795c0686e9aa1a1195536bd900f5f417b18", |
| 50 | + "class": "File", |
| 51 | + "size": 416 |
| 52 | + } |
| 53 | +} |
| 54 | +``` |
| 55 | + |
| 56 | +What's going on here? Let's break it down: |
| 57 | + |
| 58 | +``` |
| 59 | +cwlVersion: v1.0 |
| 60 | +class: Workflow |
| 61 | +``` |
| 62 | + |
| 63 | +The `cwlVersion` field indicates the version of the CWL spec used by the |
| 64 | +document. The `class` field indicates this document describes a workflow. |
| 65 | + |
| 66 | + |
| 67 | +``` |
| 68 | +inputs: |
| 69 | + inp: File |
| 70 | + ex: string |
| 71 | +``` |
| 72 | + |
| 73 | +The `inputs` section describes the inputs of the workflow. This is a |
| 74 | +list of input parameters where each parameter consists of an identifier |
| 75 | +and a data type. These parameters can be used as sources for input to |
| 76 | +specific workflows steps. |
| 77 | + |
| 78 | +``` |
| 79 | +outputs: |
| 80 | + classout: |
| 81 | + type: File |
| 82 | + outputSource: compile/classfile |
| 83 | +``` |
| 84 | + |
| 85 | +The `outputs` section describes the outputs of the workflow. This is a |
| 86 | +list of output parameters where each parameter consists of an identifier |
| 87 | +and a data type. The `outputSource` connects the output parameter `classfile` |
| 88 | +of the `compile` step to the workflow output parameter `classout`. |
| 89 | + |
| 90 | +``` |
| 91 | +steps: |
| 92 | + untar: |
| 93 | + run: tar-param.cwl |
| 94 | + in: |
| 95 | + tarfile: inp |
| 96 | + extractfile: ex |
| 97 | + outputs: [example_out] |
| 98 | +``` |
| 99 | + |
| 100 | +The `steps` section describes the actual steps of the workflow. In this |
| 101 | +example, the first step extracts a file from a tar file, and the second |
| 102 | +step compiles the file from the first step using the java compiler. |
| 103 | +Workflow steps are not necessarily run in the order they are listed, |
| 104 | +instead the order is determined by the dependencies between steps (using |
| 105 | +`source`). In addition, workflow steps which do not depend on one |
| 106 | +another may run in parallel. |
| 107 | + |
| 108 | +The first step, `untar` runs `tar-param.cwl` (described previously in |
| 109 | +[Parameter references][params]). This tool has two input parameters, `tarfile` |
| 110 | +and `extractfile` and one output parameter `example_out`. |
| 111 | + |
| 112 | +The `inputs` section of the workflow step connects these two input parameters to |
| 113 | +the inputs of the workflow, `inp` and `ex` using `source`. This means that when |
| 114 | +the workflow step is executed, the values assigned to `inp` and `ex` will be |
| 115 | +used for the parameters `tarfile` and `extractfile` in order to run the tool. |
| 116 | + |
| 117 | +The `outputs` section of the workflow step lists the output parameters that are |
| 118 | +expected from the tool. |
| 119 | + |
| 120 | +``` |
| 121 | + compile: |
| 122 | + run: arguments.cwl |
| 123 | + in: |
| 124 | + src: untar/example_out |
| 125 | + outputs: [classfile] |
| 126 | +``` |
| 127 | + |
| 128 | +The second step `compile` depends on the results from the first step by |
| 129 | +connecting the input parameter `src` to the output parameter of `untar` using |
| 130 | +`untar/example_out`. The output of this step `classfile` is connected to the |
| 131 | +`outputs` section for the Workflow, described above. |
| 132 | + |
| 133 | +[params]: _episodes/06-params/ |
0 commit comments