Type casting and binding in the cwl:in in nested workflows

Hi,
I am writting a cwl nested workflow in which in step one there is another workflow named wf1 and step two is a command line. With wf1, a file will be generated that its path must be used for step2. This file is actually one of the files in an array of files which I refer to it with bet_output_Struct. So I must have the second item of this array and by the name of it, form the path and input it to the second step.

To bind the variable to the workflow in the first step, I wrote this code for the second step:

brainvolumecalc:
    in: 
      path:
        default: 
          source: wf1/bet_output_Struct
          valueFrom: $((self[1].path).toString()  + ".nii.gz")

I declared that path must be string, but I have an error which says “path” is not string.

[step brainvolumecalc] Cannot make job: Invalid job input record:
the `path` field is not valid because
  the value is not string

Do you have any idea how should I cast the variable so that I can have path in the string format?

Thank you for your help in advance

Hello @sRah_saneE

There is no option to use valueFrom or source inside the default field. Maybe try again without default?

1 Like

Your valueFrom can also be simplified to not require the use of the InlineJavascriptRequirement: $(self[1].path).nii.gz

Hi @mrc, thanks for your respond.

Without the InlineJavascriptRequirement, I encountered this error:

[step brainvolumecalc] Cannot make job: Expression evaluation error:
Syntax error in parameter reference 'self[1].path': self[1].path does not contain key 'path'. This could be due to using Javascript code without specifying InlineJavascriptRequirement.

So I added it again, but another error raised:

Expecting value: line 1 column 1 (char 0)
script was:
01 "use strict";

I used it like this:

      path1:
        source: betflirtworkflow/bet_output_Struct
        valueFrom: (($(inputs.path1)[1])['location']).nii.gz

and this error happened:

    raise FileNotFoundError(f"No such file or no access: '{filename}'")
FileNotFoundError: No such file or no access: '(([{"basename": "sub-0001_anat_sub-0001_run-1_T1w_brain.nii.gz", "checksum": "sha1$764c415dd09a913ec316967554b1d82e7e81678e", "class": "File", "format": "http://edamontology.org/format_3989", "http://commonwl.org/cwltool#generation": 0, "location": "file:///tmp/0w8or6cd/sub-0001_anat_sub-0001_run-1_T1w_brain.nii.gz", "nameext": ".gz", "nameroot": "sub-0001_anat_sub-0001_run-1_T1w_brain.nii", "size": 2320466}, {"basename": "sub-0001_anat_sub-0001_run-1_T1w_brain.nii.gz_mask.nii.gz", "checksum": "sha1$b41ecb131c3f41c6417e421024984b6ae69b9760", "class": "File", "format": "http://edamontology.org/format_3989", "http://commonwl.org/cwltool#generation": 0, "location": "file:///tmp/0w8or6cd/sub-0001_anat_sub-0001_run-1_T1w_brain.nii.gz_mask.nii.gz", "nameext": ".gz", "nameroot": "sub-0001_anat_sub-0001_run-1_T1w_brain.nii.gz_mask.nii", "size": 75240}][1])['location']).nii.gz'

P.S. Now I believe the main problem is that cwl does not have access to the file I want.
I even used

streamable: true

but no change.
or maybe because the path it gives is in this format:
file:///tmp/5_eav8n_/sub-0001_anat_sub-0001_run-1_T1w_brain.nii.gz_mask.nii.gz
cwl can’t find it.

I fixed it by writing like this:

path1:
        source: betflirtworkflow/bet_output_Struct
        valueFrom: $(inputs.path1[1].basename)