# Using a workflow input in a step\`s valueFrom

**URL:** <https://cwl.discourse.group/t/using-a-workflow-input-in-a-step-s-valuefrom/940>\
**Category:** CWL Questions\
**Created:** [August 2, 2024, 12:45pm UTC](https://cwl.discourse.group/t/using-a-workflow-input-in-a-step-s-valuefrom/940 "2024-08-02T12:45:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brilator](https://yyz2.discourse-cdn.com/free1/user_avatar/cwl.discourse.group/brilator/32/565_2.png) [@Brilator](https://cwl.discourse.group/u/Brilator)\
**Post date:** [August 2, 2024, 12:45pm UTC](https://cwl.discourse.group/t/using-a-workflow-input-in-a-step-s-valuefrom/940/1 "2024-08-02T12:45:31Z")

</div>

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:

```yaml
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!

---

<div class="post-metadata">

**Author:** ![mrc](https://yyz2.discourse-cdn.com/free1/user_avatar/cwl.discourse.group/mrc/32/3_2.png) [@mrc](https://cwl.discourse.group/u/mrc)\
**Post date:** [August 4, 2024, 8:59am UTC](https://cwl.discourse.group/t/using-a-workflow-input-in-a-step-s-valuefrom/940/2 "2024-08-04T08:59:04Z")

</div>

Hello @Brilator

Sounds more like a JavaScript / ECMAScript question 🙂

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

```auto
$(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):

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

```

---

<div class="post-metadata">

**Author:** ![Brilator](https://yyz2.discourse-cdn.com/free1/user_avatar/cwl.discourse.group/brilator/32/565_2.png) [@Brilator](https://cwl.discourse.group/u/Brilator)\
**Post date:** [August 5, 2024, 6:35am UTC](https://cwl.discourse.group/t/using-a-workflow-input-in-a-step-s-valuefrom/940/3 "2024-08-05T06:35:49Z")

</div>

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. 😉
