2.5. Argumentos e Parâmetros Adicionais#
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.
arguments.cwl
##!/usr/bin/env cwl-runner
cwlVersion: v1.2
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"
arguments-job.yml
#src:
class: File
path: Hello.java
Em seguida, crie um arquivo Java de exemplo para usar com a ferramenta de linha de comando.
$ echo "public class Hello {}" > Hello.java
E agora execute cwltool
utilizando a descrição de ferramenta e o objeto de input na linha de comando:
$ cwltool arguments.cwl arguments-job.yml
INFO /opt/hostedtoolcache/Python/3.9.19/x64/bin/cwltool 3.1.20240508115724
INFO Resolved 'arguments.cwl' to 'file:///home/runner/work/user_guide/user_guide/src/_includes/cwl/additional-arguments-and-parameters/arguments.cwl'
INFO [job arguments.cwl] /tmp/8v931a50$ docker \
run \
-i \
--mount=type=bind,source=/tmp/8v931a50,target=/RnfKKi \
--mount=type=bind,source=/tmp/1kvngyh2,target=/tmp \
--mount=type=bind,source=/home/runner/work/user_guide/user_guide/src/_includes/cwl/additional-arguments-and-parameters/Hello.java,target=/var/lib/cwl/stgd6d06bda-134e-49bb-abf0-2c35e3b71878/Hello.java,readonly \
--workdir=/RnfKKi \
--read-only=true \
--net=none \
--user=1001:127 \
--rm \
--cidfile=/tmp/xn_rrb_t/20240518114356-520580.cid \
--env=TMPDIR=/tmp \
--env=HOME=/RnfKKi \
openjdk:9.0.1-11-slim \
javac \
-d \
/RnfKKi \
/var/lib/cwl/stgd6d06bda-134e-49bb-abf0-2c35e3b71878/Hello.java
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.