PMCC-BioinformaticsCore / janis-core

Core python modules for Janis Pipeline workflow assistant
GNU General Public License v3.0
4 stars 9 forks source link

Int<->Str typing issue. #16

Closed drtconway closed 4 years ago

drtconway commented 4 years ago

Hi Janis,

I have a wrapper (code below) that takes a string argument to which I wish to pass the string 21.

As in:

janis run -o qux view_region.py --bam NA12878.bam --region 21

This fails with a stacktrace for the following error:

ValueError: There were errors in 1 inputs: {'region': "Value was of type <class 'int'>, expected string"}

I expect it's automagically converting the string argument into an int, because it looks like one, and then complaining when the horse has bolted.

For bonus marks, I tried using YAML for the inputs, and if you use

bam: NA12878.bam
region: 20

it fails (correctly), but if you use

bam: NA12878.bam
region: "20"

it succeeds. (There's a subtle round-tripping bug in the main Python YAML implementation, which I can explain if anyone cares, but it relates to integers and quoting.)

The code view_region.py:

from typing import List
from janis_core import InputSelector, Filename, String
from janis_core.tool.commandtool import ToolArgument, ToolInput, ToolOutput
from janis_bioinformatics.data_types import Bam, BamBai
from janis_bioinformatics.tools.bioinformaticstoolbase import BioinformaticsTool

class ViewRegion(BioinformaticsTool):
    def tool(self):
        return "ViewRegion"

    def friendly_name(self):
        return "samtools view with region"

    def tool_provider(self):
        return "common"

    def version(self):
        return "0.1.0"

    def container(self):
        return "quay.io/biocontainers/samtools:1.9--h8571acd_11"

    def inputs(self) -> List[ToolInput]:
        return [
            ToolInput("outputFile", Filename, position=3, prefix="-o"),
            ToolInput("bam", BamBai, position=4),
            ToolInput("region", String, position=5)
        ]

    def outputs(self) -> List[ToolOutput]:
        return [ToolOutput("out", Bam, glob=InputSelector("outputFile"))]

    def base_command(self):
        return None

    def arguments(self):
        return [
            ToolArgument("samtools",    position=0, shell_quote=False),
            ToolArgument("view",        position=1, shell_quote=False),
            ToolArgument("-b",          position=2, shell_quote=False),
            # BAM filename goes here.
            # Region goes here.
        ]
illusional commented 4 years ago

Hi @drtconway, thanks for the report. You're right the janis-assistant was guessing the type based on the value that it provided (and some order):

I've added some input value coercion to data types, and now the assistant will attempt to coerce an input value.