2.5. 追加の引数とパラメータ#
ツールには、入力パラメータに正確に対応しない追加のコマンドラインオプションが必要な場合があります。
この例では、Javaコンパイラを使用して、javaソースファイルをclassファイルにコンパイルするようにラップします。 デフォルトでは、"javac "はjavaファイルと同じディレクトリにclassファイルを作成します。 しかし、CWLの入力ファイル(およびそのディレクトリ)は読み取り専用である場合があるので、代わりに指定された出力ディレクトリにclassファイルを書き込むように「javac」に指示する必要があります。
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
次に、CommandLineToolで使用するサンプルJavaファイルを作成します。
$ echo "public class Hello {}" > Hello.java
そして、コマンドラインでツール定義と入力オブジェクトを渡してcwltool
を起動します:
$ 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/33lo43vd$ docker \
run \
-i \
--mount=type=bind,source=/tmp/33lo43vd,target=/hUVygi \
--mount=type=bind,source=/tmp/6d1n9u2p,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/stg46ab62ee-895f-4dc1-832d-db245ae30335/Hello.java,readonly \
--workdir=/hUVygi \
--read-only=true \
--net=none \
--user=1001:127 \
--rm \
--cidfile=/tmp/clzgxhtg/20240518114608-002140.cid \
--env=TMPDIR=/tmp \
--env=HOME=/hUVygi \
openjdk:9.0.1-11-slim \
javac \
-d \
/hUVygi \
/var/lib/cwl/stg46ab62ee-895f-4dc1-832d-db245ae30335/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
ここでは、arguments
フィールドを使用して、特定の入力パラメータに結びつかない追加の引数をコマンドラインに追加しています。
arguments: ["-d", $(runtime.outdir)]
この例では、runtimeパラメータを参照しています。 runtimeパラメータは、ツールが実際に実行されたときのハードウェアまたはソフトウェア環境に関する情報を提供します。 $(runtime.outdir)
パラメータは、指定された出力ディレクトリへのパスです。 その他、$(runtime.tmpdir)
,$(runtime.ram)
,$(runtime.cores)
,$(runtime.outdirSize)
,$(runtime.tmpdirSize)
などがあります。 詳細はCWL仕様書のRuntime Environmentの項を参照してください。