Reading Array from File as Input at Runtime
1
0
Entering edit mode
6.5 years ago

I have a 2-step CWL workflow in which the first step produces a file with multiple entries in array form:

[
'entry11 entry12 entry13',
'entry21 entry22 entry23',
'entry31 entry32 entry33',
...
]

I would like to read the entries as a string[] in the second step to be able to scatter over them. Is this possible in CWL? Can it be achieved without writing an ExpressionTool? I found this previous post but that only describes converting a file to a string and I am not sure how to adapt it to string[].

cwl • 1.4k views
ADD COMMENT
1
Entering edit mode
6.5 years ago

The modified expression tool would look like this.

cwlVersion: v1.0
class: ExpressionTool

requirements: { InlineJavascriptRequirement: {} }

inputs:
  a_File:
    type: File
    inputBinding:
      loadContents: true

expression: |
  ${ return { "array_string": JSON.parse(inputs.a_File.contents.replace('"',"'")) }; }

outputs:
  array_string: string[]

JSON.parse function would use contents of the file, but would need to replace double quotes with single quotes. If you scatter the tool that receives this array of strings, each job would get one string, e.g. 'entry11 entry12 entry13'.

ADD COMMENT

Login before adding your answer.

Traffic: 1064 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6