2.5. Additional Arguments and Parameters#
Sometimes tools require additional command line options that don’t correspond exactly to input parameters.
In this example, we will wrap the Java compiler to compile a java source file to a class file. By default, “javac” will create the class files in the same directory as the source file. However, CWL input files (and the directories in which they appear) may be read-only, so we need to instruct “javac” to write the class file to the designated output directory instead.
#!/usr/bin/env cwl-runner
cwlVersion: v1.0
class: CommandLineTool
label: Example trivial wrapper for Java 9 compiler
hints:
DockerRequirement:
dockerPull: openjdk:9.0.1-11-slim
baseCommand: javac
arguments: ["-d", $(runtime.outdir)]
inputs:
src:
type: File
inputBinding:
position: 1
outputs:
classfile:
type: File
outputBinding:
glob: "*.class"
src:
class: File
path: Hello.java
Next, create a sample Java file to use with the command-line tool.
$ echo "public class Hello {}" > Hello.java
And now invoke cwltool
providing the tool description and the input object on the command line:
$ cwltool arguments.cwl arguments-job.yml
INFO /opt/hostedtoolcache/Python/3.9.13/x64/bin/cwltool 3.1.20220913185150
INFO Resolved 'arguments.cwl' to 'file:///home/runner/work/user_guide/user_guide/src/_includes/cwl/additional-arguments-and-parameters/arguments.cwl'
INFO ['udocker', 'pull', 'openjdk:9.0.1-11-slim']
Info: creating repo: /home/runner/.udocker
Info: udocker command line interface 1.3.4
Info: searching for udockertools 1.2.8
Info: installing udockertools 1.2.8
Info: installation of udockertools successful
Info: downloading layer sha256:8d602e635a7063b254ddcd64997153b2e8f74c29ff4648089ae116a4ca3ea8e3
Info: downloading layer sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4
Info: downloading layer sha256:45b0cb5bfff7921055b3160e463c0cbbd0da8804c54c0e81870e32789de17696
Info: downloading layer sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4
Info: downloading layer sha256:31aaf5b382af90e713d7581c352ac81060358c641b90a3708b45268486ae3911
Info: downloading layer sha256:5713db526a481e662cb137cca84372e8433d562ce47cab6f445157cd465a6caf
Info: downloading layer sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4
Info: downloading layer sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4
Info: downloading layer sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4
Info: downloading layer sha256:a8a43101ae4292a3536f04251309008da5dbec2da6fb32802dca83a617d2688e
Info: downloading layer sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4
INFO [job arguments.cwl] /tmp/79ytorac$ udocker \
--quiet \
run \
--volume=/tmp/79ytorac:/TVruGk \
--volume=/tmp/j5d5enaw:/tmp \
--volume=/home/runner/work/user_guide/user_guide/src/_includes/cwl/additional-arguments-and-parameters/Hello.java:/var/lib/cwl/stgdf3981c7-9dae-46a0-8694-2f9e0d5ee9d7/Hello.java \
--workdir=/TVruGk \
--rm \
--env=TMPDIR=/tmp \
--env=HOME=/TVruGk \
openjdk:9.0.1-11-slim \
javac \
-d \
/TVruGk \
/var/lib/cwl/stgdf3981c7-9dae-46a0-8694-2f9e0d5ee9d7/Hello.java
INFO [job arguments.cwl] Max memory used: 19MiB
INFO [job arguments.cwl] completed success
{
"classfile": {
"location": "file:///home/runner/work/user_guide/user_guide/src/_includes/cwl/additional-arguments-and-parameters/Hello.class",
"basename": "Hello.class",
"class": "File",
"checksum": "sha1$fdb876b40ad9ebc7fee873212e02d5940588642e",
"size": 184,
"path": "/home/runner/work/user_guide/user_guide/src/_includes/cwl/additional-arguments-and-parameters/Hello.class"
}
}
INFO Final process status is success
Here we use the arguments
field to add an additional argument to the
command line that isn’t tied to a specific input parameter.
arguments: ["-d", $(runtime.outdir)]
This example references a runtime parameter. Runtime parameters provide
information about the hardware or software environment when the tool is
actually executed. The $(runtime.outdir)
parameter is the path to the
designated output directory. Other parameters include $(runtime.tmpdir)
,
$(runtime.ram)
, $(runtime.cores)
, $(runtime.outdirSize)
, and
$(runtime.tmpdirSize)
. See the Runtime Environment section of the
CWL specification for details.