8784: Fix test for latest firefox.
[arvados.git] / doc / user / tutorials / writing-cwl-workflow.html.textile.liquid
1 ---
2 layout: default
3 navsection: userguide
4 title: "Writing a CWL workflow"
5 ...
6
7 {% include 'what_is_cwl' %}
8
9 {% include 'tutorial_expectations' %}
10
11 h2. Developing workflows
12
13 For an introduction and and detailed documentation about writing CWL, see the "CWL User Guide":http://commonwl.org/v1.0/UserGuide.html and the "CWL Specification":http://commonwl.org/v1.0 .
14
15 See "Best Practices for writing CWL":{{site.baseurl}}/user/cwl/cwl-style.html and "Arvados CWL Extensions":{{site.baseurl}}/user/cwl/cwl-extensions.html for additional information about using CWL on Arvados.
16
17 h2. Registering a workflow to use in Workbench
18
19 Use @--create-workflow@ to register a CWL workflow with Arvados.  This enables you to share workflows with other Arvados users, and run them by clicking the <span class="btn btn-sm btn-primary"><i class="fa fa-fw fa-gear"></i> Run a process...</span> button on the Workbench Dashboard and on the command line by UUID.
20
21 <notextile>
22 <pre><code>~/arvados/doc/user/cwl/bwa-mem$ <span class="userinput">arvados-cwl-runner --create-workflow bwa-mem.cwl</span>
23 arvados-cwl-runner 1.0.20160628195002, arvados-python-client 0.1.20160616015107, cwltool 1.0.20160629140624
24 2016-07-01 12:21:01 arvados.arv-run[15796] INFO: Upload local files: "bwa-mem.cwl"
25 2016-07-01 12:21:01 arvados.arv-run[15796] INFO: Uploaded to qr1hi-4zz18-7e0hedrmkuyoei3
26 2016-07-01 12:21:01 arvados.cwl-runner[15796] INFO: Created template qr1hi-p5p6p-rjleou1dwr167v5
27 qr1hi-p5p6p-rjleou1dwr167v5
28 </code></pre>
29 </notextile>
30
31 You can provide a partial input file to set default values for the workflow input parameters.  You can also use the @--name@ option to set the name of the workflow:
32
33 <notextile>
34 <pre><code>~/arvados/doc/user/cwl/bwa-mem$ <span class="userinput">arvados-cwl-runner --name "My workflow with defaults" --create-workflow bwa-mem.cwl bwa-mem-template.yml</span>
35 arvados-cwl-runner 1.0.20160628195002, arvados-python-client 0.1.20160616015107, cwltool 1.0.20160629140624
36 2016-07-01 14:09:50 arvados.arv-run[3730] INFO: Upload local files: "bwa-mem.cwl"
37 2016-07-01 14:09:50 arvados.arv-run[3730] INFO: Uploaded to qr1hi-4zz18-0f91qkovk4ml18o
38 2016-07-01 14:09:50 arvados.cwl-runner[3730] INFO: Created template qr1hi-p5p6p-0deqe6nuuyqns2i
39 qr1hi-p5p6p-zuniv58hn8d0qd8
40 </code></pre>
41 </notextile>
42
43 h3. Running registered workflows at the command line
44
45 You can run a registered workflow at the command line by its UUID:
46
47 <notextile>
48 <pre><code>~/arvados/doc/user/cwl/bwa-mem$ <span class="userinput">arvados-cwl-runner qr1hi-p5p6p-zuniv58hn8d0qd8 --help</span>
49 /home/peter/work/scripts/venv/bin/arvados-cwl-runner 0d62edcb9d25bf4dcdb20d8872ea7b438e12fc59 1.0.20161209192028, arvados-python-client 0.1.20161212125425, cwltool 1.0.20161207161158
50 Resolved 'qr1hi-p5p6p-zuniv58hn8d0qd8' to 'keep:655c6cd07550151b210961ed1d3852cf+57/bwa-mem.cwl'
51 usage: qr1hi-p5p6p-zuniv58hn8d0qd8 [-h] [--PL PL] --group_id GROUP_ID
52                                    --read_p1 READ_P1 [--read_p2 READ_P2]
53                                    [--reference REFERENCE] --sample_id
54                                    SAMPLE_ID
55                                    [job_order]
56
57 positional arguments:
58   job_order             Job input json file
59
60 optional arguments:
61   -h, --help            show this help message and exit
62   --PL PL
63   --group_id GROUP_ID
64   --read_p1 READ_P1     The reads, in fastq format.
65   --read_p2 READ_P2     For mate paired reads, the second file (optional).
66   --reference REFERENCE
67                         The index files produced by `bwa index`
68   --sample_id SAMPLE_ID
69 </code></pre>
70 </notextile>
71
72 h2. Using cwltool
73
74 When developing a workflow, it is often helpful to run it on the local host to avoid the overhead of submitting to the cluster.  To execute a workflow only on the local host (without submitting jobs to an Arvados cluster) you can use the @cwltool@ command.  Note that when using @cwltool@ you must have the input data accessible on the local file system using either @arv-mount@ or @arv-get@ to fetch the data from Keep.
75
76 <notextile>
77 <pre><code>~/arvados/doc/user/cwl/bwa-mem$ <span class="userinput">arv-get 2463fa9efeb75e099685528b3b9071e0+438/ .</span>
78 156 MiB / 156 MiB 100.0%
79 ~/arvados/doc/user/cwl/bwa-mem$ <span class="userinput">arv-get ae480c5099b81e17267b7445e35b4bc7+180/ .</span>
80 23 MiB / 23 MiB 100.0%
81 ~/arvados/doc/user/cwl/bwa-mem$ <span class="userinput">cwltool bwa-mem-input.yml bwa-mem-input-local.yml</span>
82 cwltool 1.0.20160629140624
83 [job bwa-mem.cwl] /home/example/arvados/doc/user/cwl/bwa-mem$ docker \
84     run \
85     -i \
86     --volume=/home/example/arvados/doc/user/cwl/bwa-mem/19.fasta.ann:/var/lib/cwl/job979368791_bwa-mem/19.fasta.ann:ro \
87     --volume=/home/example/arvados/doc/user/cwl/bwa-mem/HWI-ST1027_129_D0THKACXX.1_1.fastq:/var/lib/cwl/job979368791_bwa-mem/HWI-ST1027_129_D0THKACXX.1_1.fastq:ro \
88     --volume=/home/example/arvados/doc/user/cwl/bwa-mem/19.fasta.sa:/var/lib/cwl/job979368791_bwa-mem/19.fasta.sa:ro \
89     --volume=/home/example/arvados/doc/user/cwl/bwa-mem/19.fasta.amb:/var/lib/cwl/job979368791_bwa-mem/19.fasta.amb:ro \
90     --volume=/home/example/arvados/doc/user/cwl/bwa-mem/19.fasta.pac:/var/lib/cwl/job979368791_bwa-mem/19.fasta.pac:ro \
91     --volume=/home/example/arvados/doc/user/cwl/bwa-mem/HWI-ST1027_129_D0THKACXX.1_2.fastq:/var/lib/cwl/job979368791_bwa-mem/HWI-ST1027_129_D0THKACXX.1_2.fastq:ro \
92     --volume=/home/example/arvados/doc/user/cwl/bwa-mem/19.fasta.bwt:/var/lib/cwl/job979368791_bwa-mem/19.fasta.bwt:ro \
93     --volume=/home/example/arvados/doc/user/cwl/bwa-mem:/var/spool/cwl:rw \
94     --volume=/tmp/tmpgzyou9:/tmp:rw \
95     --workdir=/var/spool/cwl \
96     --read-only=true \
97     --log-driver=none \
98     --user=1001 \
99     --rm \
100     --env=TMPDIR=/tmp \
101     --env=HOME=/var/spool/cwl \
102     biodckr/bwa \
103     bwa \
104     mem \
105     -t \
106     1 \
107     -R \
108     '@RG        ID:arvados_tutorial     PL:illumina     SM:HWI-ST1027_129' \
109     /var/lib/cwl/job979368791_bwa-mem/19.fasta \
110     /var/lib/cwl/job979368791_bwa-mem/HWI-ST1027_129_D0THKACXX.1_1.fastq \
111     /var/lib/cwl/job979368791_bwa-mem/HWI-ST1027_129_D0THKACXX.1_2.fastq > /home/example/arvados/doc/user/cwl/bwa-mem/HWI-ST1027_129_D0THKACXX.1_1.sam
112 [M::bwa_idx_load_from_disk] read 0 ALT contigs
113 [M::process] read 100000 sequences (10000000 bp)...
114 [M::mem_pestat] # candidate unique pairs for (FF, FR, RF, RR): (0, 4745, 1, 0)
115 [M::mem_pestat] skip orientation FF as there are not enough pairs
116 [M::mem_pestat] analyzing insert size distribution for orientation FR...
117 [M::mem_pestat] (25, 50, 75) percentile: (154, 181, 214)
118 [M::mem_pestat] low and high boundaries for computing mean and std.dev: (34, 334)
119 [M::mem_pestat] mean and std.dev: (185.63, 44.88)
120 [M::mem_pestat] low and high boundaries for proper pairs: (1, 394)
121 [M::mem_pestat] skip orientation RF as there are not enough pairs
122 [M::mem_pestat] skip orientation RR as there are not enough pairs
123 [M::mem_process_seqs] Processed 100000 reads in 9.848 CPU sec, 9.864 real sec
124 [main] Version: 0.7.12-r1039
125 [main] CMD: bwa mem -t 1 -R @RG ID:arvados_tutorial     PL:illumina     SM:HWI-ST1027_129 /var/lib/cwl/job979368791_bwa-mem/19.fasta /var/lib/cwl/job979368791_bwa-mem/HWI-ST1027_129_D0THKACXX.1_1.fastq /var/lib/cwl/job979368791_bwa-mem/HWI-ST1027_129_D0THKACXX.1_2.fastq
126 [main] Real time: 10.061 sec; CPU: 10.032 sec
127 Final process status is success
128 {
129     "aligned_sam": {
130         "size": 30738959,
131         "path": "/home/example/arvados/doc/user/cwl/bwa-mem/HWI-ST1027_129_D0THKACXX.1_1.sam",
132         "checksum": "sha1$0c668cca45fef02397bb5302880526d300ee4dac",
133         "class": "File"
134     }
135 }
136 </code></pre>
137 </notextile>
138
139 If you get the error @JavascriptException: Long-running script killed after 20 seconds.@ this may be due to the Dockerized Node.js engine taking too long to start.  You may address this by installing Node.js locally (run @apt-get install nodejs@ on Debian or Ubuntu) or by specifying a longer timeout with the @--eval-timeout@ option.  For example, run the workflow with @cwltool --eval-timeout=40@ for a 40-second timeout.
140
141 h2. Making workflows directly executable
142
143 You can make a workflow file directly executable (@cwl-runner@ should be an alias to @arvados-cwl-runner@) by adding the following line to the top of the file:
144
145 <notextile>
146 <pre><code>#!/usr/bin/env cwl-runner
147 </code></pre>
148 </notextile>
149
150 <notextile>
151 <pre><code>~/arvados/doc/user/cwl/bwa-mem$ <span class="userinput">./bwa-mem.cwl bwa-mem-input.yml</span>
152 arvados-cwl-runner 1.0.20160628195002, arvados-python-client 0.1.20160616015107, cwltool 1.0.20160629140624
153 2016-06-30 14:56:36 arvados.arv-run[27002] INFO: Upload local files: "bwa-mem.cwl"
154 2016-06-30 14:56:36 arvados.arv-run[27002] INFO: Uploaded to qr1hi-4zz18-h7ljh5u76760ww2
155 2016-06-30 14:56:40 arvados.cwl-runner[27002] INFO: Submitted job qr1hi-8i9sb-fm2n3b1w0l6bskg
156 2016-06-30 14:56:41 arvados.cwl-runner[27002] INFO: Job bwa-mem.cwl (qr1hi-8i9sb-fm2n3b1w0l6bskg) is Running
157 2016-06-30 14:57:12 arvados.cwl-runner[27002] INFO: Job bwa-mem.cwl (qr1hi-8i9sb-fm2n3b1w0l6bskg) is Complete
158 2016-06-30 14:57:12 arvados.cwl-runner[27002] INFO: Overall process status is success
159 {
160     "aligned_sam": {
161         "path": "keep:54325254b226664960de07b3b9482349+154/HWI-ST1027_129_D0THKACXX.1_1.sam",
162         "checksum": "sha1$0dc46a3126d0b5d4ce213b5f0e86e2d05a54755a",
163         "class": "File",
164         "size": 30738986
165     }
166 }
167 </code></pre>
168 </notextile>
169
170 You can even make an input file directly executable the same way with the following two lines at the top:
171
172 <notextile>
173 <pre><code>#!/usr/bin/env cwl-runner
174 cwl:tool: <span class="userinput">bwa-mem.cwl</span>
175 </code></pre>
176 </notextile>
177
178 <notextile>
179 <pre><code>~/arvados/doc/user/cwl/bwa-mem$ <span class="userinput">./bwa-mem-input.yml</span>
180 arvados-cwl-runner 1.0.20160628195002, arvados-python-client 0.1.20160616015107, cwltool 1.0.20160629140624
181 2016-06-30 14:56:36 arvados.arv-run[27002] INFO: Upload local files: "bwa-mem.cwl"
182 2016-06-30 14:56:36 arvados.arv-run[27002] INFO: Uploaded to qr1hi-4zz18-h7ljh5u76760ww2
183 2016-06-30 14:56:40 arvados.cwl-runner[27002] INFO: Submitted job qr1hi-8i9sb-fm2n3b1w0l6bskg
184 2016-06-30 14:56:41 arvados.cwl-runner[27002] INFO: Job bwa-mem.cwl (qr1hi-8i9sb-fm2n3b1w0l6bskg) is Running
185 2016-06-30 14:57:12 arvados.cwl-runner[27002] INFO: Job bwa-mem.cwl (qr1hi-8i9sb-fm2n3b1w0l6bskg) is Complete
186 2016-06-30 14:57:12 arvados.cwl-runner[27002] INFO: Overall process status is success
187 {
188     "aligned_sam": {
189         "path": "keep:54325254b226664960de07b3b9482349+154/HWI-ST1027_129_D0THKACXX.1_1.sam",
190         "checksum": "sha1$0dc46a3126d0b5d4ce213b5f0e86e2d05a54755a",
191         "class": "File",
192         "size": 30738986
193     }
194 }
195 </code></pre>
196 </notextile>