diff --git a/planemo/tool_builder.py b/planemo/tool_builder.py index 46b6b8e56..6c961c2d2 100644 --- a/planemo/tool_builder.py +++ b/planemo/tool_builder.py @@ -4,6 +4,7 @@ Galaxy and CWL tool descriptions. """ from collections import namedtuple +import re import shlex import subprocess @@ -148,7 +149,7 @@ inputs: {%- for input in inputs %} - id: {{ input.id }} - type: File + type: {{ input.type }} description: | TODO inputBinding: @@ -388,6 +389,11 @@ def cwl_lex_list(self): output_count += 1 output = CwlOutput("output%d" % output_count, position, prefix) parse_list.append(output) + elif prefix: + param_id = prefix.prefix.lower().rstrip("=") + type_ = param_type(value) + input = CwlInput(param_id, position, prefix, type_=type_) + parse_list.append(input) else: part = CwlCommandPart(value, position, prefix) parse_list.append(part) @@ -489,10 +495,11 @@ def is_token(self, value): class CwlInput(object): - def __init__(self, id, position, prefix): + def __init__(self, id, position, prefix, type_="File"): self.id = id self.position = position self.prefix = prefix + self.type = type_ def is_token(self, value): return False @@ -726,6 +733,15 @@ def __str__(self): return base.format(attrs, self.name) +def param_type(value): + if re.match("^\d+$", value): + return "int" + elif re.match("^\d+?\.\d+?$", value): + return "float" + else: + return "string" + + class Container(object): def __init__(self, image_id): diff --git a/tests/test_command_io.py b/tests/test_command_io.py index d0a4aa93a..d21eb7c29 100644 --- a/tests/test_command_io.py +++ b/tests/test_command_io.py @@ -64,7 +64,11 @@ def test_example_cwl_simple_redirect(): def test_prefixes_separated(): - command_io = _example("seqtk convert -i '1.bed' --output '1.bam'", example_outputs=["1.bam"], example_inputs=["1.bed"]) + command_io = _example( + "seqtk convert -i '1.bed' --output '1.bam'", + example_outputs=["1.bam"], + example_inputs=["1.bed"] + ) cwl_properties = command_io.cwl_properties() _assert_eq(cwl_properties["base_command"], ["seqtk", "convert"]) _assert_eq(cwl_properties["inputs"][0].position, 1) @@ -78,7 +82,11 @@ def test_prefixes_separated(): def test_prefixes_joined(): - command_io = _example("seqtk convert INPUT=1.bed OUTPUT=1.bam", example_outputs=["1.bam"], example_inputs=["1.bed"]) + command_io = _example( + "seqtk convert INPUT=1.bed OUTPUT=1.bam", + example_outputs=["1.bam"], + example_inputs=["1.bed"] + ) cwl_properties = command_io.cwl_properties() _assert_eq(cwl_properties["base_command"], ["seqtk", "convert"]) _assert_eq(cwl_properties["inputs"][0].position, 1) @@ -91,6 +99,35 @@ def test_prefixes_joined(): _assert_eq(cwl_properties["stdout"], None) +def test_integer_parameters(): + command_io = _example( + "seqtk convert --size 100 -i '1.bed' --threshold 2.0 --output_type bam > '1.bam'", + example_outputs=["1.bam"], + example_inputs=["1.bed"] + ) + cwl_properties = command_io.cwl_properties() + _assert_eq(cwl_properties["base_command"], ["seqtk", "convert"]) + _assert_eq(len(cwl_properties["inputs"]), 4) + _assert_eq(cwl_properties["inputs"][0].position, 1) + _assert_eq(cwl_properties["inputs"][0].type, "int") + _assert_eq(cwl_properties["inputs"][0].prefix.prefix, "--size") + + _assert_eq(cwl_properties["inputs"][1].position, 2) + _assert_eq(cwl_properties["inputs"][1].type, "File") + _assert_eq(cwl_properties["inputs"][1].prefix.prefix, "-i") + + _assert_eq(cwl_properties["inputs"][2].position, 3) + _assert_eq(cwl_properties["inputs"][2].type, "float") + _assert_eq(cwl_properties["inputs"][2].prefix.prefix, "--threshold") + + _assert_eq(cwl_properties["inputs"][3].position, 4) + _assert_eq(cwl_properties["inputs"][3].type, "string") + _assert_eq(cwl_properties["inputs"][3].prefix.prefix, "--output_type") + + _assert_eq(cwl_properties["outputs"][0].glob, "out") + _assert_eq(cwl_properties["stdout"], "out") + + def _example(example_command, example_outputs=[], example_inputs=[]): """Build a CommandIO object for test cases.""" kwds = {}