Connecting a File output to a File[] input

Hi there

For a workflow I’m writing, I have a step that produces a File output and a following step that consumes a File[]. Currently it is an error to connect these steps directly together so I used an expression. Here is a working example:

#!/usr/bin/env cwl-runner
cwlVersion: v1.2
class: Workflow

requirements:
  InlineJavascriptRequirement: {}
  StepInputExpressionRequirement: {}

inputs:
  infile:
    type: File
outputs:
  output_value:
    type: File
    outputSource: step2/outfile

steps:
  step1:
    in:
      infile: infile
    out:
      - outfile
    run:
      class: CommandLineTool
      inputs:
        infile:
          type: File
      outputs:
        outfile:
          type: stdout
      baseCommand: cat
  step2:
    in:
      infiles:
        source: step1/outfile
        valueFrom: $([self])
    out:
      - outfile
    run:
      class: CommandLineTool
      inputs:
        infiles:
          type: File[]
      outputs:
        outfile:
          type: stdout
      baseCommand: cat

This seems some needlessly complicated. Is there a better way to do this?

Nope, what you’ve done here is correct.

The output outfile of step1 is of type File but the input to step2 is of type File[]. In order to connect them using the valueFrom attribute to convert the step1.outfile to an array with a single element is standard practise. To go the other way, from File[] to File you’d need to use something like valueFrom: $(self[0]).

I disagree that this is needlessly complicated. It’s just an extra line valueFrom: $([self]). Like with most coding languages, variables of one type aren’t going to be always coerced to a different type.

1 Like

This is purely a style comment, but sometimes it feels awkward just because the block-style syntax is a little bulky, I usually write it like this:

    in:
      infiles: {source: step1/outfile, valueFrom: $([self])}
    out: [outfile]