CWL: How to return int or string[] from CommandLineTool?
1
2
Entering edit mode
6.1 years ago
uagrif ▴ 30

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 • 4.1k views
ADD COMMENT
2
Entering edit mode
6.1 years ago

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 COMMENT
0
Entering edit mode

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 REPLY
0
Entering edit mode

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

ADD REPLY
1
Entering edit mode

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 REPLY

Login before adding your answer.

Traffic: 2365 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6