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 cwl_loader import load_cwl_from_location
from cwl2ogc import BaseCWLtypes2OGCConverter
cwl_document = load_cwl_from_location('https://raw.githubusercontent.com/eoap/cwl2ogc/refs/heads/develop/tests/artifacts/cwl-types/complex-cwl-types.cwl')
cwl_converter = BaseCWLtypes2OGCConverter(cwl_document)
from cwl_loader import load_cwl_from_location
from cwl2ogc import BaseCWLtypes2OGCConverter
cwl_document = load_cwl_from_location('https://raw.githubusercontent.com/eoap/cwl2ogc/refs/heads/develop/tests/artifacts/cwl-types/complex-cwl-types.cwl')
cwl_converter = BaseCWLtypes2OGCConverter(cwl_document)
2025-09-17 21:15:29.336 | DEBUG | cwl_loader:load_cwl_from_location:220 - Loading CWL document from https://raw.githubusercontent.com/eoap/cwl2ogc/refs/heads/develop/tests/artifacts/cwl-types/complex-cwl-types.cwl...
2025-09-17 21:15:29.373 | DEBUG | cwl_loader:_load_cwl_from_stream:223 - Reading stream from https://raw.githubusercontent.com/eoap/cwl2ogc/refs/heads/develop/tests/artifacts/cwl-types/complex-cwl-types.cwl...
2025-09-17 21:15:29.391 | DEBUG | cwl_loader:load_cwl_from_stream:197 - CWL data of type <class 'ruamel.yaml.comments.CommentedMap'> successfully loaded from stream
2025-09-17 21:15:29.391 | DEBUG | cwl_loader:load_cwl_from_yaml:141 - Updating the model of type 'CommentedMap' to version 'v1.2'...
2025-09-17 21:15:29.396 | DEBUG | cwl_loader:load_cwl_from_yaml:152 - Raw CWL document successfully updated to v1.2! Now converting to the CWL model...
2025-09-17 21:15:29.498 | DEBUG | cwl_loader:load_cwl_from_yaml:160 - Raw CWL document successfully updated to v1.2! Now dereferencing the steps[].run...
2025-09-17 21:15:29.499 | DEBUG | cwl_loader:load_cwl_from_yaml:170 - steps[].run successfully dereferenced! Now dereferencing the FQNs...
2025-09-17 21:15:29.499 | DEBUG | cwl_loader:_clean_process:90 - Cleaning CommandLineTool main...
2025-09-17 21:15:29.500 | DEBUG | cwl_loader:load_cwl_from_yaml:175 - CWL document successfully dereferenced!
2025-09-17 21:15:29.500 | DEBUG | cwl_loader:_load_cwl_from_stream:231 - Stream from https://raw.githubusercontent.com/eoap/cwl2ogc/refs/heads/develop/tests/artifacts/cwl-types/complex-cwl-types.cwl successfully load!
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_converter.dump_inputs(stream=sys.stdout, pretty_print=True)
import sys
cwl_converter.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",
"format": "int32"
}
},
"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_converter.dump_outputs(stream=sys.stdout, pretty_print=True)
cwl_converter.dump_outputs(stream=sys.stdout, pretty_print=True)
{}