I want to be able to iterate through inputs.subtract_vcf_files and invoke a command on each file path. But it’s giving me a full JSON representation of this variable rather than just the paths.
The code you tried mixed bash and parameter expansion. For what you wish to do, it is better to use a javascript to completely build the script. As you can see, in the JS expression we use the .path attribute of the files[i] object. Here I’ve just used echo which you would replace by what you need.
For reasons that are too complicated to explain in this post, I decided that I wanted it to work without using Javascript. Below is my solution for that.
#!/usr/bin/env cwl-runner
cwlVersion: v1.0
class: CommandLineTool
requirements:
ShellCommandRequirement: {}
InitialWorkDirRequirement:
listing:
- entryname: parse_paths.py
entry: |-
import json, sys
for d in json.loads(sys.argv[1]):
print(d["path"])
inputs:
main_vcf_file:
type: File
subtract_vcf_files:
type:
type: array
items: File
outputs:
example_out:
type: stdout
stdout: output.txt
arguments:
- shellQuote: false
valueFrom: >
for f in `python3 parse_paths.py '$(inputs.subtract_vcf_files)'`;
do
echo \${f};
done
This line cmd += "\n echo " + inputs.files[i].path; won’t add any white space will it? I would like to get the nameroot for each input file to use for instance as a sample name and then I would run a scatter with dotproduct.