Merge branch 'master' into 2257-inequality-conditions
[arvados.git] / doc / user / tutorials / running-external-program.html.textile.liquid
1 ---
2 layout: default
3 navsection: userguide
4 title: "Using Crunch to run external programs"
5 ...
6
7 This tutorial demonstrates how to use Crunch to run an external program by writting a wrapper using the Python SDK.
8
9 *This tutorial assumes that you are "logged into an Arvados VM instance":{{site.baseurl}}/user/getting_started/ssh-access.html#login, and have a "working environment.":{{site.baseurl}}/user/getting_started/check-environment.html*
10
11 In this tutorial, you will use the external program @md5sum@ to compute hashes instead of the built-in Python library used in earlier tutorials.
12
13 Start by entering the @crunch_scripts@ directory of your git repository:
14
15 <notextile>
16 <pre><code>~$ <span class="userinput">cd <b>you</b>/crunch_scripts</span>
17 </code></pre>
18 </notextile>
19
20 Next, using @nano@ or your favorite Unix text editor, create a new file called @run-md5sum.py@ in the @crunch_scripts@ directory.  
21
22 notextile. <pre>~/<b>you</b>/crunch_scripts$ <code class="userinput">nano run-md5sum.py</code></pre>
23
24 Add the following code to use the @md5sum@ program to compute the hash of each file in a collection:
25
26 <notextile> {% code 'run_md5sum_py' as python %} </notextile>
27
28 Make the file executable:
29
30 notextile. <pre><code>~/<b>you</b>/crunch_scripts$ <span class="userinput">chmod +x run-md5sum.py</span></code></pre>
31
32 Next, add the file to @git@ staging, commit and push:
33
34 <notextile>
35 <pre><code>~/<b>you</b>/crunch_scripts$ <span class="userinput">git add run-md5sum.py</span>
36 ~/<b>you</b>/crunch_scripts$ <span class="userinput">git commit -m"run external md5sum program"</span>
37 ~/<b>you</b>/crunch_scripts$ <span class="userinput">git push origin master</span>
38 </code></pre>
39 </notextile>
40
41 You should now be able to run your new script using Crunch, with "script" referring to our new "run-md5sum.py" script.
42
43 <notextile>
44 <pre><code>~/<b>you</b>/crunch_scripts$ <span class="userinput">cat &gt;~/the_pipeline &lt;&lt;EOF
45 {
46   "name":"Run external md5sum program",
47   "components":{
48     "do_hash":{
49       "script":"run-md5sum.py",
50       "script_parameters":{
51         "input":{
52           "required": true,
53           "dataclass": "Collection"
54         }
55       },
56       "script_version":"<b>you</b>:master"
57     }
58   }
59 }
60 EOF
61 </span>~/<b>you</b>/crunch_scripts$ <span class="userinput">arv pipeline_template create --pipeline-template "$(cat ~/the_pipeline)"</span>
62 </code></pre>
63 </notextile>
64
65 Your new pipeline template will appear on the "Workbench %(rarr)&rarr;% Compute %(rarr)&rarr;% Pipeline&nbsp;templates":http://{{ site.arvados_workbench_host }}/pipeline_instances page.  You can run the "pipeline using workbench":tutorial-pipeline-workbench.html