Skip to content

Commit 0f2a576

Browse files
authored
Merge pull request #7 from tobyhodges/gh-pages
Transferred existing user guide material
2 parents 3690fba + ef99d93 commit 0f2a576

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1624
-34
lines changed

_episodes/01-introduction.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,3 @@ technologies such as Docker, be used with CWL implementations from different
2828
vendors, and is well suited for describing large-scale workflows in cluster,
2929
cloud and high performance computing environments where tasks are scheduled in
3030
parallel across many nodes.
31-
32-
{% include links.md %}

_episodes/02-1st-example.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
title: "First Example"
3+
teaching: 5
4+
exercises: 0
5+
questions:
6+
- "How do I wrap a simple command line tool?"
7+
objectives:
8+
- "Learn the basic structure of a CWL description."
9+
keypoints:
10+
- "CWL documents are written in YAML and/or JSON."
11+
- "The command called is specified with `baseCommand`."
12+
- "Each expected input is described in the `inputs` section."
13+
- "Input values are specified in a separate YAML file."
14+
- "The tool description and input files are provided as arguments to a CWL runner."
15+
---
16+
The simplest "hello world" program. This accepts one input parameter, writes a message to the terminal or job log, and produces no permanent output. CWL documents are written in [JSON][json] or [YAML][yaml], or a mix of the two.
17+
18+
19+
*1st-tool.cwl*
20+
```
21+
{% include cwl/1st-tool.cwl %}
22+
```
23+
24+
Use a YAML object in a separate file to describe the input of a run:
25+
26+
*echo-job.yml*
27+
```
28+
{% include cwl/echo-job.yml %}
29+
```
30+
31+
Now invoke `cwl-runner` with the tool wrapper and the input object on the command line:
32+
33+
```
34+
$ cwl-runner 1st-tool.cwl echo-job.yml
35+
[job 1st-tool.cwl] /tmp/tmpmM5S_1$ echo \
36+
'Hello world!'
37+
Hello world!
38+
[job 1st-tool.cwl] completed success
39+
{}
40+
Final process status is success
41+
42+
```
43+
44+
What's going on here? Let's break it down:
45+
46+
```
47+
cwlVersion: v1.0
48+
class: CommandLineTool
49+
```
50+
51+
The `cwlVersion` field indicates the version of the CWL spec used by the document. The `class` field indicates this document describes a command line tool.
52+
53+
```
54+
baseCommand: echo
55+
```
56+
57+
The `baseCommand` provides the name of program that will actually run (`echo`)
58+
59+
```
60+
inputs:
61+
message:
62+
type: string
63+
inputBinding:
64+
position: 1
65+
```
66+
67+
The `inputs` section describes the inputs of the tool. This is a list of input parameters and each parameter includes an identifier, a data type, and optionally an `inputBinding` which describes how this input parameter should appear on the command line. In this example, the `position` field indicates where it should appear on the command line.
68+
69+
```
70+
outputs: []
71+
```
72+
73+
This tool has no formal output, so the `outputs` section is an empty list.
74+
75+
[json]: http://json.org
76+
[yaml]: http://yaml.org

_episodes/03-input.md

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
---
2+
title: "Essential Input Parameters"
3+
teaching: 10
4+
exercises: 0
5+
questions:
6+
- "How do I describe inputs to a command?"
7+
- "How do I specify the order in which inputs appear in a command?"
8+
objectives:
9+
- "Learn how to describe and handle input parameters and files to a tool."
10+
keypoints:
11+
- "Inputs are described in the `inputs` section of a CWL description."
12+
- "Files should be described with `class: File`."
13+
- "You can use the `inputBinding` section to describe where and how an input
14+
appears in the command."
15+
---
16+
17+
The `inputs` of a tool is a list of input parameters that control how to
18+
run the tool. Each parameter has an `id` for the name of parameter, and
19+
`type` describing what types of values are valid for that parameter.
20+
21+
Available primitive types are *string*, *int*, *long*, *float*, *double*,
22+
and *null*; complex types are *array* and *record*; in addition there are
23+
special types *File*, *Directory* and *Any*.
24+
25+
The following example demonstrates some input parameters with different
26+
types and appearing on the command line in different ways:
27+
28+
29+
*inp.cwl*
30+
31+
~~~
32+
{% include cwl/inp.cwl %}
33+
~~~
34+
35+
*inp-job.yml*
36+
37+
```
38+
{% include cwl/inp-job.yml %}
39+
```
40+
41+
Notice that "example_file", as a `File` type, must be provided as an
42+
object with the fields `class: File` and `path`.
43+
44+
Next, create a whale.txt and invoke `cwl-runner` with the tool wrapper and the
45+
input object on the command line:
46+
47+
```
48+
$ touch whale.txt
49+
$ cwl-runner inp.cwl inp-job.yml
50+
[job inp.cwl] /tmp/tmpzrSnfX$ echo \
51+
-f \
52+
-i42 \
53+
--example-string \
54+
hello \
55+
--file=/tmp/tmpRBSHIG/stg979b6d24-d50a-47e3-9e9e-90097eed2cbc/whale.txt
56+
-f -i42 --example-string hello --file=/tmp/tmpRBSHIG/stg979b6d24-d50a-47e3-9e9e-90097eed2cbc/whale.txt
57+
[job inp.cwl] completed success
58+
{}
59+
Final process status is success
60+
```
61+
> ## Where did those `/tmp` paths come from?
62+
>
63+
> The CWL reference runner (cwltool) and other runners create temporary
64+
> directories with symbolic ("soft") links to your input files to ensure that
65+
> the tools aren't accidently accessing files that were not explicitly
66+
> specified
67+
{: .callout}
68+
69+
The field `inputBinding` is optional and indicates whether and how the
70+
input parameter should be appear on the tool's command line. If
71+
`inputBinding` is missing, the parameter does not appear on the command
72+
line. Let's look at each example in detail.
73+
74+
```
75+
example_flag:
76+
type: boolean
77+
inputBinding:
78+
position: 1
79+
prefix: -f
80+
```
81+
82+
Boolean types are treated as a flag. If the input parameter
83+
"example_flag" is "true", then `prefix` will be added to the
84+
command line. If false, no flag is added.
85+
86+
```
87+
example_string:
88+
type: string
89+
inputBinding:
90+
position: 3
91+
prefix: --example-string
92+
```
93+
94+
String types appear on the command line as literal values. The `prefix`
95+
is optional, if provided, it appears as a separate argument on the
96+
command line before the parameter . In the example above, this is
97+
rendered as `--example-string hello`.
98+
99+
```
100+
example_int:
101+
type: int
102+
inputBinding:
103+
position: 2
104+
prefix: -i
105+
separate: false
106+
```
107+
108+
Integer (and floating point) types appear on the command line with
109+
decimal text representation. When the option `separate` is false (the
110+
default value is true), the prefix and value are combined into a single
111+
argument. In the example above, this is rendered as `-i42`.
112+
113+
114+
```
115+
example_file:
116+
type: File?
117+
inputBinding:
118+
prefix: --file=
119+
separate: false
120+
position: 4
121+
```
122+
123+
File types appear on the command line as the path to the file. When the
124+
parameter type ends with a question mark `?` it indicates that the
125+
parameter is optional. In the example above, this is rendered as
126+
`--file=/tmp/random/path/whale.txt`. However, if the "example_file"
127+
parameter were not provided in the input, nothing would appear on the
128+
command line.
129+
130+
Input files are read-only. If you wish to update an input file, you must
131+
[first copy it to the output directory]({{ page.root }}/15-staging/).
132+
133+
The value of `position` is used to determine where parameter should
134+
appear on the command line. Positions are relative to one another, not
135+
absolute. As a result, positions do not have to be sequential, three
136+
parameters with positions 1, 3, 5 will result in the same command
137+
line as 1, 2, 3. More than one parameter can have the same position
138+
(ties are broken using the parameter name), and the position field itself
139+
is optional. The default position is 0.
140+
141+
The `baseCommand` field will always appear in the final command line before the parameters.

_episodes/04-output.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
---
2+
title: "Returning Output Files"
3+
teaching: 10
4+
exercises: 0
5+
questions:
6+
- "How do I describe outputs from a command?"
7+
objectives:
8+
- "Learn how to describe and handle outputs from a tool."
9+
keypoints:
10+
- "Outputs are described in the `outputs` section of a CWL description."
11+
- "The field `outputBinding` describes how to to set the value of each
12+
output parameter."
13+
- "Wildcards are allowed in the `glob` field."
14+
---
15+
The `outputs` of a tool is a list of output parameters that should be
16+
returned after running the tool. Each parameter has an `id` for the name
17+
of parameter, and `type` describing what types of values are valid for
18+
that parameter.
19+
20+
When a tool runs under CWL, the starting working directory is the
21+
designated output directory. The underlying tool or script must record
22+
its results in the form of files created in the output directory. The
23+
output parameters returned by the CWL tool are either the output files
24+
themselves, or come from examining the content of those files.
25+
26+
*tar.cwl*
27+
28+
```
29+
{% include cwl/tar.cwl %}
30+
```
31+
32+
*tar-job.yml*
33+
34+
```
35+
{% include cwl/tar-job.yml %}
36+
```
37+
38+
Next, create a tar file for the example and invoke `cwl-runner` with the tool
39+
wrapper and the input object on the command line:
40+
41+
```
42+
$ touch hello.txt && tar -cvf hello.tar hello.txt
43+
$ cwl-runner tar.cwl tar-job.yml
44+
[job tar.cwl] /tmp/tmpqOeawQ$ tar \
45+
xf \
46+
/tmp/tmpGDk8Y1/stg80bbad20-494d-47af-8075-dffc32df03a3/hello.tar
47+
[job tar.cwl] completed success
48+
{
49+
"example_out": {
50+
"checksum": "sha1$da39a3ee5e6b4b0d3255bfef95601890afd80709",
51+
"basename": "hello.txt",
52+
"nameroot": "hello",
53+
"nameext": ".txt",
54+
"location": "file:///home/me/cwl/user_guide/hello.txt",
55+
"path": "/home/me/cwl/user_guide/hello.txt",
56+
"class": "File",
57+
"size": 0
58+
}
59+
}
60+
Final process status is success
61+
```
62+
63+
The field `outputBinding` describes how to to set the value of each
64+
output parameter.
65+
66+
```
67+
outputs:
68+
example_out:
69+
type: File
70+
outputBinding:
71+
glob: hello.txt
72+
```
73+
74+
The `glob` field consists of the name of a file in the output directory.
75+
If you don't know name of the file in advance, you can use a wildcard pattern like `*.txt`.

_episodes/05-stdout.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
title: "Capturing Standard Output"
3+
teaching: 10
4+
exercises: 0
5+
questions:
6+
- "How do I capture a tool's standard output stream?"
7+
objectives:
8+
- "Learn how to capture streamed output from a tool."
9+
keypoints:
10+
- "Use the `stdout` field to specify a filename to capture streamed output."
11+
- "The corresponding output parameter must have `type: stdout`."
12+
---
13+
To capture a tool's standard output stream, add the `stdout` field with
14+
the name of the file where the output stream should go. Then add `type:
15+
stdout` on the corresponding output parameter.
16+
17+
*stdout.cwl*
18+
19+
```
20+
{% include cwl/stdout.cwl %}
21+
```
22+
23+
*echo-job.yml*
24+
25+
```
26+
{% include cwl/echo-job.yml %}
27+
```
28+
29+
Now invoke `cwl-runner` providing the tool wrapper and the input object
30+
on the command line:
31+
32+
```
33+
$ cwl-runner stdout.cwl echo-job.yml
34+
[job stdout.cwl] /tmp/tmpE0gTz7$ echo \
35+
'Hello world!' > /tmp/tmpE0gTz7/output.txt
36+
[job stdout.cwl] completed success
37+
{
38+
"output": {
39+
"checksum": "sha1$47a013e660d408619d894b20806b1d5086aab03b",
40+
"basename": "output.txt",
41+
"nameroot": "output",
42+
"nameext": ".txt",
43+
"location": "file:///home/me/cwl/user_guide/output.txt",
44+
"path": "/home/me/cwl/user_guide/output.txt",
45+
"class": "File",
46+
"size": 13
47+
}
48+
}
49+
Final process status is success
50+
51+
```

0 commit comments

Comments
 (0)