Explicit glob output not parsed for CommandLineTool with default value

Hello,
I’m learning CWL and I’ve this simple wrapper around cp in which I’d like the target file to follow a specific pattern (foo.txtfoo.txt.copy). For this, I use the fields default and valueFrom for the second parameter to cp:

my_tool.cwl:

#!/usr/bin/env cwl-runner

cwlVersion: v1.2
class: CommandLineTool
baseCommand: cp

inputs:
  infile:
    type: File
    inputBinding:
      position: 1

  copied_file:
    type: string
    default: ""
    inputBinding:
      position: 2
      valueFrom: $(inputs.infile.basename).copy

outputs:
  outfile:
    type: File
    outputBinding:
      glob: $(inputs.copied_file)  ## <--- does not work

I cannot understand why explicitly setting the glob value to the desired file (via $(inputs.copied_file)), it is not working.

i.e.:

$ touch foo.txt
$ cwltool --debug my_tool.cwl --infile foo.txt
# ERROR [job my_tool.cwl] Job error:
# ("Error collecting output for parameter 'outfile': my_tool.cwl:27:7: Did not find output file with glob pattern: '[]'.", {})

Whereas if I use either:

  • glob: "*.copy" or, again,
  • glob: $(inputs.infile.basename).copy

it works.

What am I missing?
It seems that inputs.copied_file gets the default value and not the valueFrom value, or am I wrong?
Do you have any suggestions for a better approach?

Thanks!

I think you are correct here. If you use --debug you should be able to see more output about what the tool loaded from arguments and workflow file, and see the expression it used to evaluate the outputEval afterwards.

Do you have any suggestions for a better approach?

I think if you don’t need/want to pass a value to copied_file in the command line, then maybe you can use arguments instead, to simplify it a little and prevent the copied_file from being used.

cwlVersion: v1.2
class: CommandLineTool
baseCommand: cp

inputs:
  infile:
    type: File

arguments:
  - $(inputs.infile.path)
  - $(inputs.infile.basename).copy

outputs:
  outfile:
    type: File
    outputBinding:
      glob: "*.copy"

Cheers
Bruno

1 Like

To summarize, you have collected a string value (named copied_file) from the user, but then ignored its value when constructing the new filename. That’s why the reference to the copied_file input value under glob fails; it still has the original user value, not the computed valueFrom.

2 Likes