Question: Reading Array from File as Input at Runtime
0
gravatar for Lukas Rupprecht
17 months ago by
Lukas Rupprecht0 wrote:

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 • 533 views
ADD COMMENTlink modified 17 months ago by bogdan.gavrilovic220 • written 17 months ago by Lukas Rupprecht0
1
gravatar for bogdan.gavrilovic
17 months ago by
bogdan.gavrilovic220 wrote:

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 COMMENTlink written 17 months ago by bogdan.gavrilovic220
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1339 users visited in the last hour