|
| 1 | +--- |
| 2 | +title: "Custom Types" |
| 3 | +teaching: 10 |
| 4 | +exercises: 0 |
| 5 | +questions: |
| 6 | +- "How do I create and import my own custom types into a CWL description?" |
| 7 | +objectives: |
| 8 | +- "Learn how to write custom CWL object types." |
| 9 | +- "Learn how to import these custom objects into a tool description." |
| 10 | +keypoints: |
| 11 | +- "You can create your own custom types to load into descriptions." |
| 12 | +- "These custom types allow the user to configure the behaviour of a tool |
| 13 | + without tinkering directly with the tool description." |
| 14 | +- "Custom types are described in separate YAML files and imported as needed." |
| 15 | +--- |
| 16 | + |
| 17 | +Sometimes you may want to write your own custom types for use and reuse in CWL |
| 18 | +descriptions. Use of such custom types can reduce redundancy between multiple |
| 19 | +descriptions that all use the same type, and also allow for additional |
| 20 | +customisation/configuration of a tool/analysis without the need to fiddle with |
| 21 | +the CWL description directly. |
| 22 | + |
| 23 | +The example below is a CWL description of the [InterProScan][ips] tool for |
| 24 | +simultaneously searching protein sequences against a wide variety of resources. |
| 25 | +It is a good example of a number of good practices in CWL. |
| 26 | + |
| 27 | +*custom-types.cwl* |
| 28 | + |
| 29 | +~~~ |
| 30 | +{% include cwl/custom-types.cwl %} |
| 31 | +~~~ |
| 32 | +{: .source} |
| 33 | + |
| 34 | +*custom-types.yml* |
| 35 | + |
| 36 | +~~~ |
| 37 | +{% include cwl/custom-types.yml %} |
| 38 | +~~~ |
| 39 | +{: .source} |
| 40 | + |
| 41 | +On line 34, in `inputs:applications`, a list of applications to be used in the |
| 42 | +search are imported as a custom object: |
| 43 | + |
| 44 | +``` |
| 45 | +inputs: |
| 46 | + proteinFile: |
| 47 | + type: File |
| 48 | + inputBinding: |
| 49 | + prefix: --input |
| 50 | + applications: |
| 51 | + type: InterProScan-apps.yml#apps[]? |
| 52 | + inputBinding: |
| 53 | + itemSeparator: ',' |
| 54 | + prefix: --applications |
| 55 | +``` |
| 56 | +{: .source} |
| 57 | + |
| 58 | +The reference to a custom type is a combination of the name of the file in which |
| 59 | +the object is defined (`InterProScan-apps.yml`) and the name of the object |
| 60 | +within that file (`apps`) that defines the custom type. The square brackets `[]` |
| 61 | +mean that an array of the preceding type is expected, in this case the `apps` |
| 62 | +type from the imported `InterProScan-apps.yaml` file |
| 63 | + |
| 64 | +The contents of the YAML file describing the custom type are given below: |
| 65 | + |
| 66 | +~~~ |
| 67 | +{% include cwl/InterProScan-apps.yml %} |
| 68 | +~~~ |
| 69 | +{: .source} |
| 70 | + |
| 71 | +In order for the custom type to be used in the CWL description, it must be |
| 72 | +imported. Imports are described in `requirements:SchemaDefRequirement`, as |
| 73 | +below in the example `custom-types.cwl` description: |
| 74 | + |
| 75 | +``` |
| 76 | +requirements: |
| 77 | + ResourceRequirement: |
| 78 | + ramMin: 10240 |
| 79 | + coresMin: 3 |
| 80 | + SchemaDefRequirement: |
| 81 | + types: |
| 82 | + - $import: InterProScan-apps.yml |
| 83 | +``` |
| 84 | +{: .source} |
| 85 | + |
| 86 | +Note also that the author of this CWL description has also included |
| 87 | +`ResourceRequirement`s, specifying the minimum amount of RAM and number of cores |
| 88 | +required for the tool to run successfully, as well as details of the version of |
| 89 | +the software that the description was written for and other useful metadata. |
| 90 | +These features are discussed further in other chapters of this user guide. |
| 91 | + |
| 92 | +[ips]: https://github.com/ebi-pf-team/interproscan |
0 commit comments