|
| 1 | +--- |
| 2 | +layout: page |
| 3 | +title: Miscellaneous |
| 4 | +permalink: /misc/ |
| 5 | +--- |
| 6 | + |
| 7 | +This is a collection of examples and short notes |
| 8 | +about some operations that fall outside the scope of the User Guide |
| 9 | +and/or have not yet been implemented in a clean way in the CWL standards. |
| 10 | + |
| 11 | +### Non "`File`" types using `evalFrom` |
| 12 | + |
| 13 | +```yaml |
| 14 | +cwlVersion: v1.0 # or v1.1 |
| 15 | +class: CommandLineTool |
| 16 | +requirements: |
| 17 | + InlineJavascriptRequirement: {} |
| 18 | + |
| 19 | +baseCommand: [ echo, "42" ] |
| 20 | + |
| 21 | +inputs: [] |
| 22 | + |
| 23 | +stdout: my_number.txt |
| 24 | + |
| 25 | +outputs: |
| 26 | + my_number: |
| 27 | + type: int |
| 28 | + outputBinding: |
| 29 | + glob: my_number.txt |
| 30 | + loadContents: True |
| 31 | + outputEval: $(parselnt(self[0].contents)) |
| 32 | + |
| 33 | + my_number_as_string: |
| 34 | + type: string |
| 35 | + outputBinding: |
| 36 | + glob: my_number.txt |
| 37 | + loadContents: True |
| 38 | + outputEval: $(self[0].contents) |
| 39 | +``` |
| 40 | +
|
| 41 | +### Rename an input file |
| 42 | +
|
| 43 | +This example shows how you can change the name of an input file |
| 44 | +as part of a tool description. |
| 45 | +This could be useful when you are taking files produced from another |
| 46 | +step in a workflow and don't want to work with the default names that these |
| 47 | +files were given when they were created. |
| 48 | +
|
| 49 | +```yaml |
| 50 | +requirements: |
| 51 | + InitialWorkDirRequirement: |
| 52 | + listing: |
| 53 | + - entry: $(inputs.src1) |
| 54 | + entryName: newName |
| 55 | + - entry: $(inputs.src2) |
| 56 | + entryName: $(inputs.src1.basename)_custom_extension |
| 57 | +``` |
| 58 | +
|
| 59 | +### Rename an output file |
| 60 | +
|
| 61 | +This example shows how you can change the name an output file |
| 62 | +from the default name given to it by a tool: |
| 63 | +
|
| 64 | +```yaml |
| 65 | +cwlVersion: v1.0 # or v1.1 |
| 66 | +class: CommandLineTool |
| 67 | +requirements: |
| 68 | + InlineJavascriptRequirement: {} |
| 69 | + |
| 70 | +baseCommand: [] |
| 71 | + |
| 72 | +inputs: [] |
| 73 | + |
| 74 | +outputs: |
| 75 | + otu_table: |
| 76 | + type: File |
| 77 | + outputBinding: |
| 78 | + glob: otu_table.txt |
| 79 | + outputEval: ${self[0].basename=inputs.otu_table_name; return self;} |
| 80 | +``` |
| 81 | +
|
| 82 | +### Setting `self`-based input bindings for optional inputs |
| 83 | + |
| 84 | +Currently, `cwltool` can't cope with missing optional inputs if their |
| 85 | +input binding makes use of `self`. |
| 86 | +Below is an example workaround for this, |
| 87 | +pending a more sophisticated fix. |
| 88 | + |
| 89 | +```yaml |
| 90 | +#!/usr/bin/env cwl-runner |
| 91 | +cwlVersion: v1.0 |
| 92 | +class: CommandLineTool |
| 93 | +
|
| 94 | +requirements: { InlineJavascriptRequirement: {} } |
| 95 | +
|
| 96 | +inputs: |
| 97 | + cfg: |
| 98 | + type: File? |
| 99 | + inputBinding: |
| 100 | + prefix: -cfg |
| 101 | + valueFrom: | |
| 102 | + ${ if(self === null) { return null;} else { return self.basename; } } |
| 103 | +
|
| 104 | +baseCommand: echo |
| 105 | +
|
| 106 | +outputs: [] |
| 107 | +``` |
| 108 | + |
| 109 | +### Model a "one-or-the-other" parameter |
| 110 | + |
| 111 | +Below is an example of how |
| 112 | +you can specify different strings to be added to a command line |
| 113 | +based on the value given to a Boolean parameter. |
| 114 | + |
| 115 | +```yaml |
| 116 | +cwlVersion: v1.0 |
| 117 | +class: CommandLineTool |
| 118 | +requirements: |
| 119 | + InlineJavascriptRequirement: {} |
| 120 | +inputs: |
| 121 | + fancy_bool: |
| 122 | + type: boolean |
| 123 | + default: false # or true |
| 124 | + inputBinding: |
| 125 | + valueFrom: ${if (self) { return "foo";} else { return "bar";}} |
| 126 | +
|
| 127 | +baseCommand: echo |
| 128 | +
|
| 129 | +outputs: [] |
| 130 | +``` |
0 commit comments