Skip to content

Commit

Permalink
Add simple parsing of integer, float, and string parameters to tool b…
Browse files Browse the repository at this point in the history
…uilder.

Works for CWL builder - but should be back ported to Galaxy is possible.
  • Loading branch information
jmchilton committed May 10, 2016
1 parent 4cd571c commit b0b867e
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 deletions.
20 changes: 18 additions & 2 deletions planemo/tool_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Galaxy and CWL tool descriptions.
"""
from collections import namedtuple
import re
import shlex
import subprocess

Expand Down Expand Up @@ -148,7 +149,7 @@
inputs:
{%- for input in inputs %}
- id: {{ input.id }}
type: File
type: {{ input.type }}
description: |
TODO
inputBinding:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
41 changes: 39 additions & 2 deletions tests/test_command_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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 = {}
Expand Down

0 comments on commit b0b867e

Please sign in to comment.