Creating Files at Runtime

Overview

Teaching: 10 min
Exercises: 0 min
Questions
  • How do I create required input files from input parameters at runtime?

Objectives
  • Learn how to create files on the fly during runtime.

Sometimes you need to create a file on the fly from input parameters, such as tools which expect to read their input configuration from a file rather than the command line parameters. To do this, use InitialWorkDirRequirement.

createfile.cwl

#!/usr/bin/env cwl-runner

class: CommandLineTool
cwlVersion: v1.0
baseCommand: ["cat", "example.conf"]

requirements:
  InitialWorkDirRequirement:
    listing:
      - entryname: example.conf
        entry: |
          CONFIGVAR=$(inputs.message)

inputs:
  message: string
outputs:
  example_out:
    type: stdout
stdout: output.txt

echo-job.yml

message: Hello world!

Now invoke cwl-runner with the tool wrapper and the input object on the command line:

$ cwl-runner createfile.cwl echo-job.yml
[job createfile.cwl] /home/example$ cat \
    example.conf > /home/example/output.txt
[job createfile.cwl] completed success
{
    "example_out": {
        "location": "file:///home/example/output.txt",
        "basename": "output.txt",
        "class": "File",
        "checksum": "sha1$5d3f955d1bb862ec618bc2f7ca4c5fa29fa39e89",
        "size": 22,
        "path": "/home/example/output.txt"
    }
}
Final process status is success
$ cat output.txt
CONFIGVAR=Hello world!

Key Points

  • Use InitialWorkDirRequirement to specify input files that need to be created during tool runtime.