Question: CWL: How to return int or string[] from CommandLineTool?
0
gravatar for uagrif
9 months ago by
uagrif10
uagrif10 wrote:

Hello guys,

I'm experimenting with scatter/gather feature of Common Workflow Language and I have troubles with return type that differs from string.

So, returning strings works good:

class: CommandLineTool
cwlVersion: "v1.0"
baseCommand: [bash, -c, "echo 42 > data.txt"]

inputs: []
outputs:
  value:
    type: string
    outputBinding:
      glob: data.txt
      loadContents: true
      outputEval: $(self[0].contents)

I run cwl in docker. The output for string evaluatuion is:

root@c9b274ac17d4:~/cwl/complex-out# cwl-runner complex.cwl
/usr/local/bin/cwl-runner 1.0.20181012180214
Resolved 'complex.cwl' to 'file:///root/cwl/complex-out/complex.cwl'
[job complex.cwl] /tmp/tmp557p7kqz$ bash \
    -c \
    'echo 42 > data.txt'
[job complex.cwl] completed success
{
    "value": "42\n"
}
Final process status is success

However, when I change output value type from string to int, cwl-runner reports permanentFail:

root@c9b274ac17d4:~/cwl/complex-out# cwl-runner complex.cwl
/usr/local/bin/cwl-runner 1.0.20181012180214
Resolved 'complex.cwl' to 'file:///root/cwl/complex-out/complex.cwl'
[job complex.cwl] /tmp/tmp8x40850b$ bash \
    -c \
    'echo 42 > data.txt'
[job complex.cwl] Job error:
Error validating output record. the `value` field is not valid because
  `'42\n'` is not int
 in {
    "value": "42\n"
}
[job complex.cwl] completed permanentFail
{}
Final process status is permanentFail

I also tried array of integers and array of strings; but I stuck event at the basic things.

I also tried to add JS requirements, but it didn't help.

requirements:
  InlineJavascriptRequirement: {}

Should I use ExpressionTool or SchemaDefRequirement/CommandOutputBinding to issue an integer from workflow processing unit?

Thanks!

cwl • 787 views
ADD COMMENTlink modified 9 months ago by Michael R. Crusoe1.6k • written 9 months ago by uagrif10
0
gravatar for Michael R. Crusoe
9 months ago by
Common Workflow Language project
Michael R. Crusoe1.6k wrote:

Hello uagrif,

The newline that echo outputs is the cause, so pass -n:

-n do not output the trailing newline

#!/usr/bin/env cwl-runner
class: CommandLineTool
cwlVersion: "v1.0"

requirements:
  InlineJavascriptRequirement: {}

baseCommand: [bash, -c, "echo -n 42 > data.txt"]

inputs: []
outputs:
  value:
    type: int
    outputBinding:
      glob: data.txt
      loadContents: true
      outputEval: $(parseInt(self[0].contents))

Or without the InlineJavascriptRequirement

#!/usr/bin/env cwl-runner
class: CommandLineTool
cwlVersion: "v1.0"

baseCommand: [bash, -c, "echo '{"value": 42}'"]

inputs: []

stdout: cwl.output.json
outputs:
  value: int
ADD COMMENTlink modified 9 months ago • written 9 months ago by Michael R. Crusoe1.6k

Hello Michael,

Thanks for replying!

I've tried your code sample but 42 is still read as string.

(cwl-runner) root@28d532f49b21:~/cwl/complex-out# cwl-runner complex.cwl
/root/python-dfab/cwl-runner/bin/cwl-runner 1.0.20181102182747
Resolved 'complex.cwl' to 'file:///root/cwl/complex-out/complex.cwl'
[job complex.cwl] /tmp/tmp4qS0RC$ bash \
    -c \
    'echo -n 42 > data.txt'
[job complex.cwl] Job error:
Error validating output record. the `value` field is not valid because
  `u'42'` is not int
 in {
    "value": "42"
}
[job complex.cwl] completed permanentFail
{}
Final process status is permanentFail
ADD REPLYlink modified 9 months ago • written 9 months ago by uagrif10

Thanks, I've fixed my answer and added a version without Javscript

ADD REPLYlink written 9 months ago by Michael R. Crusoe1.6k
1

Thank you Michael, that works!

Here is sample code without InlineJavascriptRequirement:

#!/usr/bin/env cwl-runner
class: CommandLineTool
cwlVersion: "v1.0"

baseCommand: [echo, "{\"value\": 42}"]

# redirect stdout into file with predefined name
stdout: cwl.output.json

inputs: []
outputs:
  value: int

And another sample with string array output:

#!/usr/bin/env cwl-runner
class: CommandLineTool
cwlVersion: "v1.0"

# write json with content {value: ["one", "two", "three"]} ...
baseCommand: [echo, "{\"value\": [\"one\", \"two\", \"three\"]}"]
# .. into file with predefined name "cwl.output.json"
stdout: cwl.output.json

inputs: []
outputs:
  value: string[]
ADD REPLYlink written 9 months ago by uagrif10
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1482 users visited in the last hour