Complex CWL types¶
Follow below an example to demonstrate how the library handles and convert a CWL where inputs are declared with hybrid types.
1. Parsing¶
In this sample we'll show the access from a remote public URL.
In [1]:
Copied!
from cwl2ogc import load_converter_from_location
cwl_coverter = load_converter_from_location('https://raw.githubusercontent.com/eoap/cwl2ogc/refs/heads/develop/tests/artifacts/cwl-types/complex-cwl-types.cwl')
from cwl2ogc import load_converter_from_location
cwl_coverter = load_converter_from_location('https://raw.githubusercontent.com/eoap/cwl2ogc/refs/heads/develop/tests/artifacts/cwl-types/complex-cwl-types.cwl')
3. Inputs conversion¶
Once the document is parsed, invoke the cwl2ogc
APIs to convert the CWL inputs to the OGC JSON format:
In [2]:
Copied!
import sys
cwl_coverter.dump_inputs(stream=sys.stdout, pretty_print=True)
import sys
cwl_coverter.dump_inputs(stream=sys.stdout, pretty_print=True)
{ "color": { "schema": { "type": "string", "enum": [ "red", "green", "blue" ], "default": "green" }, "metadata": [ { "title": "cwl:type", "value": "enum[ red, green, blue ]" } ], "minOccurs": 1, "maxOccurs": 1, "valuePassing": "byValue", "title": "color label", "description": "color doc" }, "color1": { "schema": { "nullable": true, "type": "array", "items": { "type": "string", "enum": [ "red", "green", "blue" ] } }, "metadata": [ { "title": "cwl:type", "value": "[ null, enum[ red, green, blue ][] ]" } ], "minOccurs": 0, "maxOccurs": 1, "valuePassing": "byValue", "title": "color1 label", "description": "color1 doc" }, "bands": { "schema": { "nullable": true, "type": "array", "items": { "type": "array", "items": { "type": "string", "enum": [ "red", "green", "blue" ] } } }, "metadata": [ { "title": "cwl:type", "value": "[ null, enum[ red, green, blue ][][] ]" } ], "minOccurs": 0, "maxOccurs": 1, "valuePassing": "byValue", "title": "bands label", "description": "bands doc" }, "input0": { "schema": { "type": "string" }, "metadata": [ { "title": "cwl:type", "value": "string" } ], "minOccurs": 1, "maxOccurs": 1, "valuePassing": "byValue", "title": "input0 label", "description": "input0 doc" }, "optional_string": { "schema": { "nullable": true, "type": "string", "default": "default" }, "metadata": [ { "title": "cwl:type", "value": "[ null, string ]" } ], "minOccurs": 0, "maxOccurs": 1, "valuePassing": "byValue", "title": "optional_string label", "description": "optional_string doc" }, "input1": { "schema": { "type": "array", "items": { "type": "string" } }, "metadata": [ { "title": "cwl:type", "value": "string[]" } ], "minOccurs": 1, "maxOccurs": 1, "valuePassing": "byValue", "title": "input1 label", "description": "input1 doc" }, "input2": { "schema": { "type": "array", "items": { "type": "integer" } }, "metadata": [ { "title": "cwl:type", "value": "int[]" } ], "minOccurs": 1, "maxOccurs": 1, "valuePassing": "byValue", "title": "input2 label", "description": "input2 doc" }, "input3": { "schema": { "nullable": true, "type": "array", "items": { "type": "string" } }, "metadata": [ { "title": "cwl:type", "value": "[ string[], null ]" } ], "minOccurs": 0, "maxOccurs": 1, "valuePassing": "byValue", "title": "input3 label", "description": "input3 doc" }, "input4": { "schema": { "nullable": true, "type": "string", "enum": [ "bam", "sam", "bam_mapped", "sam_mapped", "fastq" ] }, "metadata": [ { "title": "cwl:type", "value": "[ null, enum[ bam, sam, bam_mapped, sam_mapped, fastq ] ]" } ], "minOccurs": 0, "maxOccurs": 1, "valuePassing": "byValue", "title": "input4 label", "description": "input4 doc" }, "input5": { "schema": { "nullable": false, "type": "string", "enum": [ "bam", "sam", "bam_mapped", "sam_mapped", "fastq" ], "default": "bam" }, "metadata": [ { "title": "cwl:type", "value": "[ enum[ bam, sam, bam_mapped, sam_mapped, fastq ] ]" } ], "minOccurs": 1, "maxOccurs": 1, "valuePassing": "byValue", "title": "input5 label", "description": "input5 doc" }, "thresh": { "schema": { "nullable": true, "type": "string", "default": "1.0 mm/day" }, "metadata": [ { "title": "cwl:type", "value": "[ null, string ]" } ], "minOccurs": 0, "maxOccurs": 1, "valuePassing": "byValue", "title": "thresh label", "description": "thresh doc" }, "option": { "schema": { "type": "boolean", "default": true }, "metadata": [ { "title": "cwl:type", "value": "boolean" } ], "minOccurs": 1, "maxOccurs": 1, "valuePassing": "byValue", "title": "option label", "description": "option doc" }, "option2": { "schema": { "nullable": true, "type": "boolean" }, "metadata": [ { "title": "cwl:type", "value": "[ null, boolean ]" } ], "minOccurs": 0, "maxOccurs": 1, "valuePassing": "byValue", "title": "option2 label", "description": "option2 doc" }, "array_boolean": { "schema": { "nullable": true, "type": "array", "items": { "type": "boolean" } }, "metadata": [ { "title": "cwl:type", "value": "[ boolean[], null ]" } ], "minOccurs": 0, "maxOccurs": 1, "valuePassing": "byValue", "title": "array_boolean label", "description": "array_boolean doc" } }
2. Outputs conversion¶
Users can reuse the BaseCWLtypes2OGCConverter
instance to convert the CWL outputs to the OGC JSON format:
In [3]:
Copied!
cwl_coverter.dump_outputs(stream=sys.stdout, pretty_print=True)
cwl_coverter.dump_outputs(stream=sys.stdout, pretty_print=True)
{}