Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escaping #11

Closed
drtconway opened this issue Mar 26, 2020 · 3 comments
Closed

Escaping #11

drtconway opened this issue Mar 26, 2020 · 3 comments

Comments

@drtconway
Copy link

Hi Janis,

I think the tool is actually irrelevant, but I'm attaching it anyway. (oh. I can't attach Python? I'm pasting the code down the bottom.)

When I run:

$ janis run -o wibble regex_search.py --expression '([^/]*)[.]fastq([.]gz)?' --replacement '\1' --text '/foo/bar/baz.fastq.gz’

Execution fails, and the following can be seen in the engine.log file:

    python RegexSearch-script.py \
      --expression ([^/]*)[.]fastq([.]gz)? \
      --replacement \1 \
      --text /foo/bar/baz.fastq.gz`

It's obvious why this fails - the arguments are not being escaped.

from typing import List

from janis_core import String, TOutput
from janis_bioinformatics.tools.bioinformaticstoolbase import BioinformaticsPythonTool

class RegexSearch(BioinformaticsPythonTool):
    @staticmethod
    def code_block(expression: String, replacement: String, text: String):
        import re
        m = re.search(expression, text)
        if m is None:
            raise Exception(
                f"No match for the expression '{expression}' in the text '{text}'"
            )
        res = m.expand(replacement)
        return {'result': res}

    def outputs(self) -> List[TOutput]:
        return [TOutput("result", String)]

    def id(self) -> str:
        return "RegexSearch"

    def friendly_name(self):
        return "Apply a regular expression template"

    def version(self):
        return "v0.1.0"

    def tool_provider(self):
        return "Peter MacCallum Cancer Centre"

    def bind_metadata(self):
        self.metadata.documentation = (
            "repack the filenames from splitting fastq files."
        )
        self.metadata.creator = "Thomas Conway"
        self.metadata.dateCreated = "2020-03-25"
        self.metadata.version = "0.1.0"
@illusional
Copy link
Member

After a little investigation, this is actually a problem with the WDL command template generation: I'll tag this issue (PMCC-BioinformaticsCore/python-wdlgen#2) because I intend to fix this soon.

@illusional
Copy link
Member

Hey @drtconway, later update to this. I've redone the parameter quoting in the the Expressions PR (#10).

I'm still waiting on a few related PRs before I can release that set of features, but it's coming!

@illusional
Copy link
Member

This has been released in v0.10.x.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants