pitagora-network / DAT2-cwl

Common Workflow Language definition files for workflows introduced in DAT2
Apache License 2.0
11 stars 10 forks source link

JS expression bug #44

Closed inutano closed 2 years ago

inutano commented 2 years ago

In short: CWL Expression が JS Expression と解釈されて参照できずに死ぬエラーっぽい。

何が問題か: Workflow の inputs で指定された fastq のファイル名を改変してツールの出力名に指定しようとして valueFrom: $(inputs.fastq.nameroot) をしたら JS が走って TypeError: Cannot read properties of undefined (reading 'nameroot') というエラーを吐いて死ぬ。

問題の箇所: https://github.com/pitagora-network/DAT2-cwl/blob/0cd20e1be620ae0817a1aa4286d73b78c89809f0/workflow/epigenome-chip-seq/macs2/macs2.cwl#L74

        valueFrom: $(inputs.fastq.nameroot).trim.uniq.bam

実行時のエラー:

ERROR Expecting value: line 1 column 1 (char 0)
script was:
01 "use strict";
02 var inputs = {
03     "filter_alignments": "0x4",
04     "ignore_previous_version": true,
05     "include_header": true,
06     "input_file": {
07         "location": "file:///Users/inutano/work/machima/cache/fb8c843f8643626cef3a7377e298f7ad/SRR2078969_1.trim.sam",
08         "basename": "SRR2078969_1.trim.sam",
09         "nameroot": "SRR2078969_1.trim",
10         "nameext": ".sam",
11         "class": "File",
12         "checksum": "sha1$f9900f5d66035755bdd245c20d7cb148ff3cddaf",
13         "size": 1317267819,
14         "http://commonwl.org/cwltool#generation": 0
15     },
16     "output_bam": true,
17     "output_filename": "aln.bam",
18     "skip_alignments": 42,
19     "threads": 4
20 };
21 var self = "aln.bam";
22 var runtime = {
23     "tmpdir": null,
24     "outdir": null
25 };
26 (function(){return ((inputs.fastq.nameroot));})()
stdout was: ''
stderr was: 'evalmachine.<anonymous>:26
(function(){return ((inputs.fastq.nameroot));})()
                                  ^

TypeError: Cannot read properties of undefined (reading 'nameroot')
    at evalmachine.<anonymous>:26:35
    at evalmachine.<anonymous>:26:48
    at Script.runInContext (node:vm:139:12)
    at Script.runInNewContext (node:vm:144:17)
    at Object.runInNewContext (node:vm:298:38)
    at Socket.<anonymous> ([eval]:11:57)
    at Socket.emit (node:events:527:28)
    at addChunk (node:internal/streams/readable:324:12)
    at readableAddChunk (node:internal/streams/readable:293:11)
    at Socket.Readable.push (node:internal/streams/readable:234:10)'

環境:

cwltool --version 
/Users/inutano/.venv/bin/cwltool 3.1.20220224085855

cc. @suecharo @tom-tan @manabuishii

inutano commented 2 years ago

ちなみに、これしか使わんのなら標準のExpressionでいけるから InlineJSExpression の requirements いらんのではと思って外すとこんなメッセージが出てくる。

ERROR [step samtools-view] Cannot make job: Expression evaluation error:
Syntax error in parameter reference 'inputs.fastq.nameroot': inputs does not contain key 'fastq'. This could be due to using Javascript code without specifying InlineJavascriptRequirement.

以前は動いていたが cwltool のバージョンを上げたので、Workflow の inputs を step の invalueFrom して参照できないように cwltool の仕様が変更した、あるいは以前通っていたのはバグだった、、、?

inutano commented 2 years ago

The value of inputs in the parameter reference or expression must be the input object to the workflow step after assigning the source values, applying default, and then scattering. The order of evaluating valueFrom among step input parameters is undefined and the result of evaluating valueFrom on a parameter must not be visible to evaluation of valueFrom on other parameters. https://www.commonwl.org/v1.2/Workflow.html#WorkflowStepInput

なので Workflow の inputs が取れないのが仕様っぽい。じゃあ Workflow.inputs を取るにはどうすれば?

tom-tan commented 2 years ago

WorkflowStepInput.valueFrom の記述を確認すると

The value of inputs in the parameter reference or expression must be the input object to the workflow step after assigning the source values, applying default, and then scattering.

かぶった!

tom-tan commented 2 years ago

対象のステップの引数の sourcefastq を渡せばいけると思います。

      output_filename:
        source: fastq
        valueFrom: $(self.nameroot).trim.uniq.bam
inutano commented 2 years ago
in:
  fastq: fastq
  output_filename:
    valueFrom: $(inputs.fastq.nameroot).trim.uniq.bam

かなと思ったらそっちの方がいいですね!ありがとうございます!

inutano commented 2 years ago

しかし何故前は動いていたのか、、

tom-tan commented 2 years ago

https://github.com/common-workflow-language/cwltool/issues/1330 もそうですが、ネストされた expression 中の inputs の伝播周りの挙動はちょっと怪しい…