4. よくある質問#
4.1. "File
" 型をつかわず evalFrom
を使うにはどうしたらよいですか?#
cwlVersion: v1.0 # or v1.1
class: CommandLineTool
requirements:
InlineJavascriptRequirement: {}
baseCommand: [ echo, "42" ]
inputs: []
stdout: my_number.txt
outputs:
my_number:
type: int
outputBinding:
glob: my_number.txt
loadContents: True
outputEval: $(parselnt(self[0].contents))
my_number_as_string:
type: string
outputBinding:
glob: my_number.txt
loadContents: True
outputEval: $(self[0].contents)
4.2. 入力ファイルの名前を変更するにはどうしたらよいですか?#
この例では、ツール定義の一部として、入力ファイルの名前を変更する方法を説明します。これは、ワークフローの別のステップで作成されたファイルを使用する場合に、これらのファイルが作成されたときに与えられたデフォルトの名前を使用して作業したくない場合に便利です。
requirements:
InitialWorkDirRequirement:
listing:
- entry: $(inputs.src1)
entryName: newName
- entry: $(inputs.src2)
entryName: $(inputs.src1.basename)_custom_extension
4.3. 出力ファイルの名前を変更するにはどうしたらよいですか?#
この例では、出力ファイルの名前を、ツールから与えられたデフォルトの名前から変更する方法を示します:
cwlVersion: v1.0
class: CommandLineTool
requirements:
InlineJavascriptRequirement: {}
baseCommand: [ touch, otu_table.txt ]
inputs:
otu_table_name: string
outputs:
otu_table:
type: File
outputBinding:
glob: otu_table.txt
outputEval: ${self[0].basename=inputs.otu_table_name; return self;}
outputEval
フィールドのbasename
フィールドを変更することで、CWLワークフローエンジンは、後続のステップまたはワークフローレベルの出力として、新しい名前を使用してファイル名を変更します。
4.4. ローカルスクリプトを参照するにはどうしたらよいですか?#
ローカルスクリプトを参照するには、2つの方法があります:
最初の方法は、スクリプトの入ったフォルダを 環境変数PATH
に追加する方法です。これにより、sh
やbash
コマンドを使用せずに、シェルスクリプトを直接実行できます。
まず、ファイルの先頭に shebang を追加します:
#!/bin/bash
その後、chmod +x scriptname.sh
というコマンドでスクリプトを実行可能な状態にします
最後に、PATH
を変更し、スクリプトが置かれているディレクトリを追加します。($HOME/bin
を自分のスクリプトを保存するために使用するのは良い習慣です)。
export PATH=$PATH:$HOME/bin
これで、baseCommand: scriptname.sh
を使って、スクリプトを直接実行できるようになりました。
#!/bin/bash
cwlVersion: v1.0
class: CommandLineTool
baseCommand: scriptname.sh
後で作ったものを共有したいときは、スクリプトをDockerコンテナに入れることができます。
2つ目の方法は、type: File
をスクリプト自体に含める方法です:
class: CommandLineTool
inputs:
my_script:
type: File
inputBinding:
position: 0
# other inputs go here
baseCommand: sh
outputs: []
4.5. オプショナル入力のために self
-形式のInput Bindings をどのように設定しますか?#
現在、cwltool
は、入力バインディングがself
を使用している場合、オプション入力が見つからない事に対処することができません。以下は、より洗練された修正を待つ間の回避策の例です。
#!/usr/bin/env cwl-runner
cwlVersion: v1.0
class: CommandLineTool
requirements: { InlineJavascriptRequirement: {} }
inputs:
cfg:
type: File?
inputBinding:
prefix: -cfg
valueFrom: |
${ if(self === null) { return null;} else { return self.basename; } }
baseCommand: echo
outputs: []
4.6. 「一か八か」のパラメータをモデル化するにはどうしたらよいですか?#
以下は、Booleanパラメータの値によって、コマンドラインに追加する文字列を変える例を示しています。
cwlVersion: v1.0
class: CommandLineTool
requirements:
InlineJavascriptRequirement: {}
inputs:
fancy_bool:
type: boolean
default: false # or true
inputBinding:
valueFrom: ${if (self) { return "foo";} else { return "bar";}}
baseCommand: echo
outputs: []
4.7. ある型の配列を期待する入力に1つの値を与えるにはどうしたらよいでしょうか?#
MultipleInputFeatureRequirement
と linkMerge: merge_nested
を一緒に使います:
merge_nested
入力は、各入力リンクに対して正確に1つのエントリで構成される配列でなければなりません。"merge_nested"が1つのリンクで指定された場合、リンクからの値は1つのアイテムリストでラップされなければなりません。
つまり、"まさにこれらのソースを要素とするリストを作成する" ということです。
File[]
(File
の配列) で、ソースが単一のFile
の場合、MultipleInputFeatureRequirement
をワークフローレベルのrequirements
に追加し、linkMerge: merge_nested
を目的ステップのエントリの該当in
に追加します。
cwlVersion: v1.0
class: Workflow
requirements:
MultipleInputFeatureRequirement: {}
inputs:
readme: File
steps:
first:
run: tests/checker_wf/cat.cwl
in:
cat_in: # type is File[]
source: [ readme ] # but the source is of type File
linkMerge: merge_nested
out: [txt]
outputs:
result:
type: File
outputSource: first/txt
4.8. 入力パラメータをオプショナルにするにはどうしたらよいですか? 💯#
入力パラメータをオプションにするには、型宣言に疑問符を付けます。
inputs:
InputRead1:
type: File
inputBinding:
position: 100
#Optional Inputs
isCasava:
type: boolean?
inputBinding:
position: 1
prefix: "--casava"
4.9. どうやってあらかじめ定義された値のリストから入力を指定できますか(つまり、入力でenumを使うにはどうしたらよいですか)?#
引数として特定の入力を必要とするコマンドラインフラグについては、CWLで列挙型(enum type)を宣言することで実現できます。ここでnullを指定することは、ロングフォーム・スタイルとして知られています。他の入力のクエスチョンマークと同じ働きをします。
Format:
type:
- "null"
- type: enum
symbols:
- bam
- sam
- bam_mapped
- sam_mapped
- fastq
inputBinding:
position: 2
prefix: "--format"
4.10. 依存的または排他的な入力パラメータはどのように記述すればよいですか(例えば、レコード入力をどのように使用すればよいですか)?#
相互排他的 または依存的 のいずれかのコマンドラインフラグについては、特別なレコードタイプを定義できます。また、ここにnullを指定することで、オプションの入力を作成できます。
#Using record inputs to create mutually exclusive inputs
Strand:
type:
- "null"
- type: record
name: forward
fields:
forward:
type: boolean
inputBinding:
prefix: "--fr-stranded"
- type: record
name: reverse
fields:
reverse:
type: boolean
inputBinding:
prefix: "--rf-stranded"
PseudoBam:
type: boolean?
inputBinding:
prefix: "--pseudobam"
#Using record inputs to create dependent inputs
GenomeBam:
type:
- "null"
- type: record
name: genome_bam
fields:
genomebam:
type: boolean
inputBinding:
prefix: "--genomebam"
gtf:
type: File
inputBinding:
prefix: "--gtf"
chromosomes:
type: File
inputBinding:
prefix: "--chromosomes"
4.11. 相互に排他的なパラメータを設定するにはどうしたらよいでしょうか?#
レコード入力タイプのフィールドを適切に設定するには、入力に辞書を渡してパラメータを適切に設定する必要があります。これは、インラインJavaScriptを使用し、設定したいフィールドのキーを持つ辞書を返すことで実現します。sourceフィールドには、値として使用するワークフローからの入力を示すものが設定されます。
steps:
build_hisat2_index:
run: ../Tools/Hisat2-Index.cwl
in:
InputFiles:
source: FastaFiles
valueFrom : |
${return {"fasta": self};}
IndexName: IndexName
out: [indexes]
4.12. ブール値を設定するにはどうしたらよいでしょうか?#
デフォルトフィールドを使って、これらを設定します
input:
default: true
4.13. 入力された文字列を連結するにはどうしたら良いでしょうか?#
defaultフィールドの代わりにvalueFromフィールドを使用する必要があります。
input:
valueFrom: |
My String: $(input.stringvalue)
4.14. cwltool
ファイル名の中に空白文字があるために起こるエラーにはどのように対処したらよいでしょうか?#
cwltool
は、デフォルトではファイル名に一部の文字を許可していません。
例えば、a space is here.txt
というファイル名には、3つの空白文字が含まれています。
ERROR Workflow error, try again with --debug for more information:
Invalid filename: 'a space is here.txt' contains illegal characters
これらの危険な文字を避けられない場合は、--relax-path-checks
をcwltool
に渡してください。
4.15. 入力パラメータ名の中にハイフンがあるため、CWL Parameter Reference エラーが起こりました。どのようしたらよいでしょうか?#
cwltool --validate
の結果に問題ない場合
$ cwltool --validate cwl/qiime.cwl
INFO /usr/local/bin/cwltool 1.0.20190831161204
INFO Resolved 'cwl/qiime.cwl' to 'file:///workspace/cwl/qiime.cwl'
cwl/qiime.cwl is valid CWL.
しかし、実行すると以下のようなエラーが発生します:
$ cwltool cwl/qiime.cwl --sample-input metadata.tsv
INFO /usr/local/bin/cwltool 1.0.20190831161204
INFO Resolved 'cwl/qiime.cwl' to 'file:///workspace/cwl/qiime.cwl'
ERROR Workflow error, try again with --debug for more information:
cwl/qiime.cwl:14:5: Expression evaluation error:
Syntax error in parameter reference '(inputs.sample-input)'. This could be due
to using Javascript code without specifying InlineJavascriptRequirement.
ファイルはこちらです
cwlVersion: v1.0
class: CommandLineTool
baseCommand: [qiime, metadata, tabulate]
arguments:
- prefix: --m-input-file
valueFrom: $(inputs.sample-input)
inputs:
sample-input: File
outputs: []
-
(ハイフン文字、引き算の記号)が原因で発生した問題です。
valueFrom: $(inputs.sample-input)
# ^ this is problem
...
inputs:
sample-input: File
# ^ this is problem
このエラーを修正するには、-
(ハイフン) を_
(アンダースコア) に変更してください:
valueFrom: $(inputs.sample_input)
# ^ changed here
...
inputs:
sample_input: File
# ^ changed here
入力識別子を変更することができない場合は、別のCWLパラメータリファレンス構文を使用できます:
valueFrom: $(inputs["sample-input"])
4.16. SingularityをCWLとcwltoolで使うにはどうしたらよいでしょうか?#
CWL標準は、(オプションの)Docker形式のコンテナを中心に構築されています。リファレンスランナーや他のいくつかのCWL実装は、Singularityエンジンを使用してそれらのDockerフォーマットコンテナを実行することをサポートしています。Singularityフォーマットコンテナを直接指定することは、CWL標準ではありません。
4.17. CWLツールのJavaScriptをデバッグするには?#
cwltool
の –js-console
オプションを使用するか、または、あなたのコードのためのJavaScript または TypeScript プロジェクトを作成し、expressionLib
を使用して読み込んでみてください(例: https://github.com/common-workflow-language/common-workflow-language/blob/master/v1.0/v1.0/template-tool.cwl#L6-L8