|
3 | 3 | doc:
|
4 | 4 | - $include: userguide-intro.md
|
5 | 5 |
|
| 6 | + - | |
| 7 | + # Wrapping Command Line Tools |
| 8 | +
|
6 | 9 | - |
|
7 | 10 | ## First example
|
8 | 11 |
|
|
11 | 14 | output. CWL documents are written in [JSON](http://json.org) or
|
12 | 15 | [YAML](http://yaml.org), or a mix of the two.
|
13 | 16 |
|
14 |
| - *1st.cwl* |
| 17 | + *1st-tool.cwl* |
15 | 18 | ```
|
16 |
| - - $include: examples/1st.cwl |
| 19 | + - $include: examples/1st-tool.cwl |
17 | 20 | - |
|
18 | 21 | ```
|
19 | 22 |
|
|
29 | 32 | command line:
|
30 | 33 |
|
31 | 34 | ```
|
32 |
| - $ cwl-runner 1st.cwl echo-job.yml |
| 35 | + $ cwl-runner 1st-tool.cwl echo-job.yml |
33 | 36 | [job 140199012414352] $ echo 'Hello world!'
|
34 | 37 | Hello world!
|
35 | 38 | Final process status is success
|
|
311 | 314 | command line:
|
312 | 315 | ```
|
313 | 316 | $ rm hello.tar || true && touch goodbye.txt && tar -cvf hello.tar
|
314 |
| - $ cwl-runner example-tar-param.cwl example-tar-param-job.yml |
| 317 | + $ cwl-runner tar-param.cwl tar-param-job.yml |
315 | 318 | [job 139868145165200] $ tar xf /home/example/hello.tar goodbye.txt
|
316 | 319 | Final process status is success
|
317 | 320 | {
|
|
480 | 483 |
|
481 | 484 | ```
|
482 | 485 | $ cwl-runner array-inputs.cwl array-inputs-job.yml
|
483 |
| - /home/peter/work/cwl-venv/bin/cwltool 1.0.20160325210917 |
484 |
| - [job 140334923640912] /home/peter/work/common-workflow-language/draft-3/examples$ echo -A one two three -B=four -B=five -B=six -C=seven,eight,nine |
| 486 | + [job 140334923640912] /home/example$ echo -A one two three -B=four -B=five -B=six -C=seven,eight,nine |
485 | 487 | -A one two three -B=four -B=five -B=six -C=seven,eight,nine
|
486 | 488 | Final process status is success
|
487 | 489 | {}
|
|
497 | 499 | You can specify arrays of arrays, arrays of records, and other complex
|
498 | 500 | types.
|
499 | 501 |
|
| 502 | + - | |
| 503 | + ## Array outputs |
| 504 | +
|
| 505 | + You can also capture multiple output files into an array of files using `glob`. |
| 506 | +
|
| 507 | + *array-outputs.cwl* |
| 508 | + ``` |
| 509 | + - $include: examples/array-outputs.cwl |
| 510 | + - | |
| 511 | + ``` |
| 512 | +
|
| 513 | + *array-outpust-job.yml* |
| 514 | + ``` |
| 515 | + - $include: examples/array-outputs-job.yml |
| 516 | + - | |
| 517 | + ``` |
| 518 | +
|
| 519 | + Now invoke `cwl-runner` providing the tool wrapper and the input object |
| 520 | + on the command line: |
| 521 | +
|
| 522 | + ``` |
| 523 | + $ cwl-runner array-outputs.cwl array-outputs-job.yml |
| 524 | + [job 140190876078160] /home/example$ touch foo.txt bar.dat baz.txt |
| 525 | + Final process status is success |
| 526 | + { |
| 527 | + "output": [ |
| 528 | + { |
| 529 | + "size": 0, |
| 530 | + "path": "/home/peter/work/common-workflow-language/draft-3/examples/foo.txt", |
| 531 | + "checksum": "sha1$da39a3ee5e6b4b0d3255bfef95601890afd80709", |
| 532 | + "class": "File" |
| 533 | + }, |
| 534 | + { |
| 535 | + "size": 0, |
| 536 | + "path": "/home/peter/work/common-workflow-language/draft-3/examples/baz.txt", |
| 537 | + "checksum": "sha1$da39a3ee5e6b4b0d3255bfef95601890afd80709", |
| 538 | + "class": "File" |
| 539 | + } |
| 540 | + ] |
| 541 | + } |
| 542 | + ``` |
| 543 | +
|
500 | 544 | - |
|
501 | 545 | ## Record inputs, dependent and mutually exclusive parameters
|
502 | 546 |
|
|
677 | 721 |
|
678 | 722 | ```
|
679 | 723 | $ cwl-runner linkfile.cwl arguments-job.yml
|
680 |
| - [job 139928309171664] /home/example$ docker run -i --volume=/home/peter/work/common-workflow-language/draft-3/examples/Hello.java:/var/lib/cwl/job557617295_examples/Hello.java:ro --volume=/home/peter/work/common-workflow-language/draft-3/examples:/var/spool/cwl:rw --volume=/tmp/tmpmNbApw:/tmp:rw --workdir=/var/spool/cwl --read-only=true --net=none --user=1001 --rm --env=TMPDIR=/tmp java:7 javac Hello.java |
| 724 | + [job 139928309171664] /home/example$ docker run -i --volume=/home/example/Hello.java:/var/lib/cwl/job557617295_examples/Hello.java:ro --volume=/home/example:/var/spool/cwl:rw --volume=/tmp/tmpmNbApw:/tmp:rw --workdir=/var/spool/cwl --read-only=true --net=none --user=1001 --rm --env=TMPDIR=/tmp java:7 javac Hello.java |
681 | 725 | Final process status is success
|
682 | 726 | {
|
683 | 727 | "classfile": {
|
684 | 728 | "size": 416,
|
685 |
| - "path": "/home/peter/work/common-workflow-language/draft-3/examples/Hello.class", |
| 729 | + "path": "/home/example/Hello.class", |
686 | 730 | "checksum": "sha1$2f7ac33c1f3aac3f1fec7b936b6562422c85b38a",
|
687 | 731 | "class": "File"
|
688 | 732 | }
|
689 | 733 | }
|
690 | 734 | ```
|
| 735 | +
|
| 736 | + - | |
| 737 | + # Writing Workflows |
| 738 | +
|
| 739 | + ## First workflow |
| 740 | +
|
| 741 | + This workflow extracts a java source file from a tar file and then |
| 742 | + compiles it. |
| 743 | +
|
| 744 | + *1st-workflow.cwl* |
| 745 | + ``` |
| 746 | + - $include: examples/1st-workflow.cwl |
| 747 | + - | |
| 748 | + ``` |
| 749 | +
|
| 750 | + Use a JSON object in a separate file to describe the input of a run: |
| 751 | +
|
| 752 | + *1st-workflow-job.yml* |
| 753 | + ``` |
| 754 | + - $include: examples/1st-workflow-job.yml |
| 755 | + - | |
| 756 | + ``` |
| 757 | +
|
| 758 | + Now invoke `cwl-runner` with the tool wrapper and the input object on the |
| 759 | + command line: |
| 760 | +
|
| 761 | + ``` |
| 762 | + $ cwl-runner 1st-workflow.cwl 1st-workflow-job.yml |
| 763 | + [job untar] /tmp/tmp94qFiM$ tar xf /home/example/hello.tar Hello.java |
| 764 | + [step untar] completion status is success |
| 765 | + [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 |
| 766 | + [step compile] completion status is success |
| 767 | + [workflow 1st-workflow.cwl] outdir is /home/example |
| 768 | + Final process status is success |
| 769 | + { |
| 770 | + "classout": { |
| 771 | + "path": "/home/example/Hello.class", |
| 772 | + "checksum": "sha1$2f7ac33c1f3aac3f1fec7b936b6562422c85b38a", |
| 773 | + "class": "File", |
| 774 | + "size": 416 |
| 775 | + } |
| 776 | + } |
| 777 | + ``` |
| 778 | +
|
| 779 | + What's going on here? Let's break it down: |
| 780 | +
|
| 781 | + ``` |
| 782 | + cwlVersion: cwl:draft-3 |
| 783 | + class: Workflow |
| 784 | + ``` |
| 785 | +
|
| 786 | + The 'cwlVersion` field indicates the version of the CWL spec used by the |
| 787 | + document. The `class` field indicates this document describes a workflow. |
| 788 | +
|
| 789 | +
|
| 790 | + ``` |
| 791 | + inputs: |
| 792 | + - id: inp |
| 793 | + type: File |
| 794 | + - id: ex |
| 795 | + type: string |
| 796 | + ``` |
| 797 | +
|
| 798 | + The `inputs` section describes the inputs of the workflow. This is a |
| 799 | + list of input parameters where each parameter consists of an identifier |
| 800 | + and a data type. These parameters can be used as sources for input to |
| 801 | + specific workflows steps. |
| 802 | +
|
| 803 | + ``` |
| 804 | + outputs: |
| 805 | + - id: classout |
| 806 | + type: File |
| 807 | + source: "#compile/classfile" |
| 808 | + ``` |
| 809 | +
|
| 810 | + The `outputs` section describes the outputs of the workflow. This is a |
| 811 | + list of output parameters where each parameter consists of an identifier |
| 812 | + and a data type. The `source` connects the output parameter `classfile` |
| 813 | + of the `compile` step to the workflow output parameter `classout`. |
| 814 | +
|
| 815 | + ``` |
| 816 | + steps: |
| 817 | + - id: untar |
| 818 | + run: tar-param.cwl |
| 819 | + inputs: |
| 820 | + - id: tarfile |
| 821 | + source: "#inp" |
| 822 | + - id: extractfile |
| 823 | + source: "#ex" |
| 824 | + outputs: |
| 825 | + - id: example_out |
| 826 | + ``` |
| 827 | +
|
| 828 | + The `steps` section describes the actual steps of the workflow. In this |
| 829 | + example, the first step extracts a file from a tar file, and the second |
| 830 | + step compiles the file from the first step using the java compiler. |
| 831 | + Workflow steps are not necessarily run in the order they are listed, |
| 832 | + instead the order is determined by the dependencies between steps (using |
| 833 | + `source`). In addition, workflow steps which do not depend on one |
| 834 | + another may run in parallel. |
| 835 | +
|
| 836 | + The first step, `untar` runs `tar-param.cwl` (described previously in |
| 837 | + [Parameter references](#Parameter_references)). This tool has two input |
| 838 | + parameters, `tarfile` and `extractfile` and one output parameter |
| 839 | + `example_out`. |
| 840 | +
|
| 841 | + The `inputs` section of the workflow step connects these two input |
| 842 | + parameters to the inputs of the workflow, `#inp` and `#ex` using |
| 843 | + `source`. This means that when the workflow step is executed, the values |
| 844 | + assigned to `#inp` and `#ex` will be used for the parameters `tarfile` |
| 845 | + and `extractfile` in order to run the tool. |
| 846 | +
|
| 847 | + The `outputs` section of the workflow step lists the output parameters |
| 848 | + that are expected from the tool. |
| 849 | +
|
| 850 | + ``` |
| 851 | + - id: compile |
| 852 | + run: arguments.cwl |
| 853 | + inputs: |
| 854 | + - id: src |
| 855 | + source: "#untar/example_out" |
| 856 | + outputs: |
| 857 | + - id: classfile |
| 858 | + ``` |
| 859 | +
|
| 860 | + The second step `compile` depends on the results from the first step by |
| 861 | + connecting the input parameter `src` to the output parameter of `untar` |
| 862 | + using `#untar/example_out`. The output of this step `classfile` is |
| 863 | + connected to the `outputs` section for the Workflow, described above. |
0 commit comments