|
| 1 | +--- |
| 2 | +title: "JavaScript Expressions" |
| 3 | +teaching: 10 |
| 4 | +exercises: 0 |
| 5 | +questions: |
| 6 | +- "What do I do when I want to create values dynamically and CWL doesn't |
| 7 | +provide a built-in way of doing so?" |
| 8 | +objectives: |
| 9 | +- "Learn how to insert javaScript expressions into a CWL description." |
| 10 | +keypoints: |
| 11 | +- "If `InlineJavascriptRequirement` is specified, you can include JavaScript |
| 12 | +expressions that will be evaulated by the CWL runner." |
| 13 | +- "Expressions are only valid in certain fields." |
| 14 | +- "Expressions should only be used when no built in CWL solution exists." |
| 15 | +--- |
| 16 | +If you need to manipulate input parameters, include the requirement |
| 17 | +`InlineJavascriptRequirement` and then anywhere a parameter reference is |
| 18 | +legal you can provide a fragment of Javascript that will be evaluated by |
| 19 | +the CWL runner. |
| 20 | + |
| 21 | +__Note: JavaScript expressions should only be used when absolutely necessary. |
| 22 | +When manipulating file names, extensions, paths etc, consider whether one of the |
| 23 | +[built in `File` properties][file-prop] like `basename`, `nameroot`, `nameext`, |
| 24 | +etc, could be used instead. |
| 25 | +See the [list of recommended practices][rec-practices].__ |
| 26 | + |
| 27 | +*expression.cwl* |
| 28 | + |
| 29 | +``` |
| 30 | +{% include cwl/expression.cwl %} |
| 31 | +``` |
| 32 | + |
| 33 | +As this tool does not require any `inputs` we can run it with an (almost) empty job file: |
| 34 | + |
| 35 | +*empty.yml* |
| 36 | + |
| 37 | +``` |
| 38 | +{% include cwl/empty.yml %} |
| 39 | +``` |
| 40 | + |
| 41 | +We can then run `expression.cwl`: |
| 42 | + |
| 43 | +``` |
| 44 | +$ cwl-runner expression.cwl empty.yml |
| 45 | +[job 140000594593168] /home/example$ echo -A 2 -B baz -C 10 9 8 7 6 5 4 3 2 1 |
| 46 | +-A 2 -B baz -C 10 9 8 7 6 5 4 3 2 1 |
| 47 | +Final process status is success |
| 48 | +{} |
| 49 | +``` |
| 50 | + |
| 51 | +You can only use expressions in certain fields. These are: |
| 52 | + |
| 53 | +- `filename` |
| 54 | +- `fileContent` |
| 55 | +- `envValue` |
| 56 | +- `valueFrom` |
| 57 | +- `glob` |
| 58 | +- `outputEval` |
| 59 | +- `stdin` |
| 60 | +- `stdout` |
| 61 | +- `coresMin` |
| 62 | +- `coresMax` |
| 63 | +- `ramMin` |
| 64 | +- `ramMax` |
| 65 | +- `tmpdirMin` |
| 66 | +- `tmpdirMax` |
| 67 | +- `outdirMin` |
| 68 | +- `outdirMax` |
| 69 | + |
| 70 | +[rec-practices]: rec-practices/ |
0 commit comments