|
| 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. |
0 commit comments