Skip to content

Commit b0b867e

Browse files
committed
Add simple parsing of integer, float, and string parameters to tool builder.
Works for CWL builder - but should be back ported to Galaxy is possible.
1 parent 4cd571c commit b0b867e

File tree

2 files changed

+57
-4
lines changed

2 files changed

+57
-4
lines changed

planemo/tool_builder.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
Galaxy and CWL tool descriptions.
55
"""
66
from collections import namedtuple
7+
import re
78
import shlex
89
import subprocess
910

@@ -148,7 +149,7 @@
148149
inputs:
149150
{%- for input in inputs %}
150151
- id: {{ input.id }}
151-
type: File
152+
type: {{ input.type }}
152153
description: |
153154
TODO
154155
inputBinding:
@@ -388,6 +389,11 @@ def cwl_lex_list(self):
388389
output_count += 1
389390
output = CwlOutput("output%d" % output_count, position, prefix)
390391
parse_list.append(output)
392+
elif prefix:
393+
param_id = prefix.prefix.lower().rstrip("=")
394+
type_ = param_type(value)
395+
input = CwlInput(param_id, position, prefix, type_=type_)
396+
parse_list.append(input)
391397
else:
392398
part = CwlCommandPart(value, position, prefix)
393399
parse_list.append(part)
@@ -489,10 +495,11 @@ def is_token(self, value):
489495

490496
class CwlInput(object):
491497

492-
def __init__(self, id, position, prefix):
498+
def __init__(self, id, position, prefix, type_="File"):
493499
self.id = id
494500
self.position = position
495501
self.prefix = prefix
502+
self.type = type_
496503

497504
def is_token(self, value):
498505
return False
@@ -726,6 +733,15 @@ def __str__(self):
726733
return base.format(attrs, self.name)
727734

728735

736+
def param_type(value):
737+
if re.match("^\d+$", value):
738+
return "int"
739+
elif re.match("^\d+?\.\d+?$", value):
740+
return "float"
741+
else:
742+
return "string"
743+
744+
729745
class Container(object):
730746

731747
def __init__(self, image_id):

tests/test_command_io.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ def test_example_cwl_simple_redirect():
6464

6565

6666
def test_prefixes_separated():
67-
command_io = _example("seqtk convert -i '1.bed' --output '1.bam'", example_outputs=["1.bam"], example_inputs=["1.bed"])
67+
command_io = _example(
68+
"seqtk convert -i '1.bed' --output '1.bam'",
69+
example_outputs=["1.bam"],
70+
example_inputs=["1.bed"]
71+
)
6872
cwl_properties = command_io.cwl_properties()
6973
_assert_eq(cwl_properties["base_command"], ["seqtk", "convert"])
7074
_assert_eq(cwl_properties["inputs"][0].position, 1)
@@ -78,7 +82,11 @@ def test_prefixes_separated():
7882

7983

8084
def test_prefixes_joined():
81-
command_io = _example("seqtk convert INPUT=1.bed OUTPUT=1.bam", example_outputs=["1.bam"], example_inputs=["1.bed"])
85+
command_io = _example(
86+
"seqtk convert INPUT=1.bed OUTPUT=1.bam",
87+
example_outputs=["1.bam"],
88+
example_inputs=["1.bed"]
89+
)
8290
cwl_properties = command_io.cwl_properties()
8391
_assert_eq(cwl_properties["base_command"], ["seqtk", "convert"])
8492
_assert_eq(cwl_properties["inputs"][0].position, 1)
@@ -91,6 +99,35 @@ def test_prefixes_joined():
9199
_assert_eq(cwl_properties["stdout"], None)
92100

93101

102+
def test_integer_parameters():
103+
command_io = _example(
104+
"seqtk convert --size 100 -i '1.bed' --threshold 2.0 --output_type bam > '1.bam'",
105+
example_outputs=["1.bam"],
106+
example_inputs=["1.bed"]
107+
)
108+
cwl_properties = command_io.cwl_properties()
109+
_assert_eq(cwl_properties["base_command"], ["seqtk", "convert"])
110+
_assert_eq(len(cwl_properties["inputs"]), 4)
111+
_assert_eq(cwl_properties["inputs"][0].position, 1)
112+
_assert_eq(cwl_properties["inputs"][0].type, "int")
113+
_assert_eq(cwl_properties["inputs"][0].prefix.prefix, "--size")
114+
115+
_assert_eq(cwl_properties["inputs"][1].position, 2)
116+
_assert_eq(cwl_properties["inputs"][1].type, "File")
117+
_assert_eq(cwl_properties["inputs"][1].prefix.prefix, "-i")
118+
119+
_assert_eq(cwl_properties["inputs"][2].position, 3)
120+
_assert_eq(cwl_properties["inputs"][2].type, "float")
121+
_assert_eq(cwl_properties["inputs"][2].prefix.prefix, "--threshold")
122+
123+
_assert_eq(cwl_properties["inputs"][3].position, 4)
124+
_assert_eq(cwl_properties["inputs"][3].type, "string")
125+
_assert_eq(cwl_properties["inputs"][3].prefix.prefix, "--output_type")
126+
127+
_assert_eq(cwl_properties["outputs"][0].glob, "out")
128+
_assert_eq(cwl_properties["stdout"], "out")
129+
130+
94131
def _example(example_command, example_outputs=[], example_inputs=[]):
95132
"""Build a CommandIO object for test cases."""
96133
kwds = {}

0 commit comments

Comments
 (0)