6
6
User Guide
7
7
**********
8
8
9
- This user guide aims to help you through the different steps to build your CWL tool with
9
+ This user guide assumes you have at least some basic knowledge about CWL.
10
+
11
+ .. Note ::
12
+ Here is a `CWL user guide `_ for an introduction to tool and workflows wrappers.
13
+
14
+ .. _`CWL user guide` : https://www.commonwl.org/user_guide/
15
+
16
+ The aim is to help you through the different steps to build your CWL tool with
10
17
python-cwlgen.
11
18
12
19
.. Note ::
@@ -16,15 +23,104 @@ python-cwlgen.
16
23
17
24
Basic example
18
25
-------------
19
- Through this little tutorial, we will go step by step through the example you can `find on Github `_.
26
+ Through this little tutorial, we will go step by step through the example you can `find on Github `_. It aims to wrap the ` grep ` command.
20
27
21
28
.. _`find on Github` : https://github.com/common-workflow-language/python-cwlgen/blob/master/examples/example.py
22
29
23
30
Initialize your tool
24
31
""""""""""""""""""""
25
32
26
- Add an input
27
- """"""""""""
33
+ You need to initialize a `CommandLineTool ` object
34
+
35
+ .. code-block :: python
36
+
37
+ import cwlgen
38
+ cwl_tool = cwlgen.CommandLineTool(tool_id = ' grep' ,
39
+ label = ' print lines matching a pattern' ,
40
+ base_command = ' grep' )
41
+
42
+ Now that you have your object, you can attach the different elements of a tool description.
43
+
44
+ Add Inputs
45
+ """"""""""
46
+
47
+ Now we need to add inputs to our tool. We are going to only wrap a simple version of the `grep ` command with a input file and a pattern.
48
+
49
+ First the input file:
50
+
51
+ .. code-block :: python
52
+
53
+ file_binding = cwlgen.CommandLineBinding(position = 2 )
54
+ input_file = cwlgen.CommandInputParameter(' input_file' ,
55
+ param_type = ' File' ,
56
+ input_binding = file_binding,
57
+ doc = ' input file from which you want to look for the pattern' )
58
+ cwl_tool.inputs.append(input_file)
59
+
60
+ And finally the pattern:
61
+
62
+ .. code-block :: python
63
+
64
+ pattern_binding = cwlgen.CommandLineBinding(position = 1 )
65
+ pattern = cwlgen.CommandInputParameter(' pattern' ,
66
+ param_type = ' string' ,
67
+ input_binding = pattern_binding,
68
+ doc = ' pattern to find in the input file' )
69
+ cwl_tool.inputs.append(pattern)
70
+
71
+ .. Note ::
72
+ You can specify more information concerning your inputs: `Input documentation `_
73
+
74
+ .. _`Input documentation` : http://python-cwlgen.readthedocs.io/en/latest/classes.html#input-and-outputs
75
+
76
+ This is it for the inputs, now let's add some outputs and the description will be ready to be tested.
28
77
29
- Add an output
78
+ Add an Output
30
79
"""""""""""""
80
+
81
+ The only output which is retrieved in our example is a File with the line containing the pattern. Here is how to add this output:
82
+
83
+ .. code-block :: python
84
+
85
+ output = cwlgen.CommandOutputParameter(' output' ,
86
+ param_type = ' stdout' ,
87
+ doc = ' lines found with the pattern' )
88
+ cwl_tool.outputs.append(output)
89
+ # Now specify a name for your output file
90
+ cwl_tool.stdout = " grep.txt"
91
+
92
+ Add Documentation and Metadata
93
+ """"""""""""""""""""""""""""""
94
+
95
+ You can ask bunch of information and metadata concerning your tool.
96
+ For instance you can add some documentation:
97
+
98
+ .. code-block :: python
99
+
100
+ cwl_tool.doc = " grep searches for a pattern in a file."
101
+
102
+ For the metadata:
103
+
104
+ .. code-block :: python
105
+
106
+ metadata = {' name' : ' grep' ,
107
+ ' about' : ' grep searches for a pattern in a file.' }
108
+ cwl_tool.metadata = cwlgen.Metadata(** metadata)
109
+
110
+ Write your tool
111
+ """""""""""""""
112
+
113
+ Finally, you can export your tool description with the `export() ` method.
114
+
115
+ .. code-block :: python
116
+
117
+ cwl_tool.export() # On STDOUT
118
+ cwl_tool.export(outfile = " grep.cwl" ) # As a file (grep.cwl)
119
+
120
+ You can then try your tool description (using `cwltool `_ for instance):
121
+
122
+ .. _`cwltool` : https://github.com/common-workflow-language/cwltool/
123
+
124
+ .. code-block :: bash
125
+
126
+ cwltool grep.cwl --input_file underdog_lyrics.txt --pattern lost
0 commit comments