I have a problem with hard-coded paths in scripts that would require changing the directory before executing a command line tool.
Let's consider the following minimal example:
○ → tree . ├── code │ └── script.py ├── data │ └── hi.txt └── tool.cwl
#! /usr/bin/env python3 with open('../data/hi.txt', 'r') as f: for line in f: print(line)
When I run
script.py from the
/code diretory, it prints the content of
hi.txt. I then try to wrap this into a CWL tool:
cwlVersion: v1.0 class: CommandLineTool inputs: script: type: File inputBinding: position: 1 default: class: File path: code/script.py data: type: File default: class: File path: data/hi.txt outputs:  requirements: InitialWorkDirRequirement: listing: - entry: $(inputs.script) entryname: code/script.py - entry: $(inputs.data) entryname: data/hi.txt
Running this tool fails when the script tries to open
hi.txt. I can fix this by changing into the right directory at the beginning of the script:
import os os.chdir(os.path.dirname(os.path.abspath(__file__)))
Now I'm wondering if CWL offers a way to change the directory before executing a tool instead. I am aware that using arguments instead of hard-coded paths or at least making the paths relative to the root of my dummy project would help here. But let's just assume that I can not modify the script at all.