Using a workflow input in a step`s valueFrom

Hi CWL folks,

I’m trying to use an input from a workflow’s inputs section as a variable in a valueFrom expression.

The following works, but hardcodes to extract a substring of 11 characters from nameroot:

cwlVersion: v1.2
class: Workflow

requirements:
  ScatterFeatureRequirement: {}
  StepInputExpressionRequirement: {}
  InlineJavascriptRequirement: {}

inputs:
  InputReadsMultipleSamples:
    type: 
      type: array
      items: 
        type: array
        items: File

steps:
  quant:
    run: quant.cwl
    scatter: 
      - InputReads
      - QuantOutfolder
    scatterMethod: dotproduct
    in:
      InputReads: InputReadsMultipleSamples
      QuantOutfolder:
        source: InputReadsMultipleSamples
        valueFrom: $(self[0].nameroot.substring(0,11))
      Index: index/index
    out: [outFolder]

outputs:
  finalOut:
    type: Directory[]
    outputSource: quant/outFolder

The workflow takes an array of File arrays (InputReadsMultipleSamples). With the latter being one or more files belonging to a single sample. The goal is to generically find a name for the output folder (QuantOutfolder), e.g. if the sample files are called sample_001_R1.fastq.gz and sample_001_R2.fastq.gz it shall simply return the matching part sample_001. Since I was not successful extracting the matching part, and it might sometimes be desired to explicitly take x chars from the file names, I wanted to add an input numCharsFileName: int? to use in the substring(0, numCharsFileName).

Is this possible? Or can somebody guide me on a more sophisticated way?
Thanks!

Hello @Brilator

Sounds more like a JavaScript / ECMAScript question :slight_smile:

I would split the nameroot on _, use slice to remove the last element, and then re-join the elements with _ again:

$(self[0].nameroot.split('_').slice(0, -1).join('_'))

You could instead add the numCharsFileName workflow-level input and then connect it to the quant step even though you won’t be passing its value to the quant.cwl process. In the in section of workflow steps when you use valueFrom you can reference inputs.NAME to access the value of other inputs (before their own valueFrom is evaluated):

    in:
      InputReads: InputReadsMultipleSamples
      numChars:
        source: numCharsFileName
        default: 11
      QuantOutfolder:
        source: InputReadsMultipleSamples
        valueFrom: $(self[0].nameroot.substring(0, inputs.numChars))
      Index: index/index

Hi @mrc,

thanks! I was not sure how to pass workflow level inputs to step. Makes perfect sense!
Also thanks for the little JavaScript tutorial. :wink:

1 Like