This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to specify an optional input for a complex type in CWL?

I need to pass an array as an optional argument in a CWL tool definition. I know that for primitive types ['null', <type>] works fine, but for array it generates an error:

Type property "['null', 'array']" not a valid Avro schema.

I have also tried to specify it the next way:

- id: bam_files
  type: 
  - "null"
  - type: array
    items: string

but cwltool interprets the first given type as the only one, i.e. bam_files is always null or it is a required argument when type: array goes first.

The same applies to enum type.

cwl common-workflow-language

Your second approach should be the correct one. Can you provide the error when you try it that way?

I'm sorry, I checked the job file and found out that I confused an underscore with a dash in the argument name...

Could you please point to the second approach in the docs? As far as I remember, I found that on GitHub, not in the documentation.

1 answer

In this example, type: string[]? would have worked, and that is documented in the standard and the UserGuide. For more complicated situations where there is more than one valid type but the whole thing is optional then the extended syntax is needed.

inputs:
  weird_input:
    type: 
    - "null"
    - type: array
      items: string
    - type: int

Means that weird_input is optional, but if present it must be an int or an array of strings.

Log in to answer this question.