Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions tools/regex_switch/.shed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
categories:
- Text Manipulation
description: Regex switch
long_description: |
Regex switch outputs a boolean from regex on element identifier.
name: regex_switch
owner: iuc
remote_repository_url: https://github.com/galaxyproject/tools-iuc/tree/master/tools/regex_switch
Comment thread
npinter marked this conversation as resolved.
Outdated
homepage_url: https://github.com/galaxyproject/tools-iuc/tree/master/tools/regex_switch
type: unrestricted
77 changes: 77 additions & 0 deletions tools/regex_switch/regex_switch.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<tool name="Regex switch" id="regex_switch" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" tool_type="expression">
<description>boolean from regex on element identifier</description>
<macros>
<token name="@TOOL_VERSION@">1.0.0</token>
<token name="@VERSION_SUFFIX@">0</token>
</macros>
<expression type="ecma5.1"><![CDATA[{
var name = $job.input.name;
Comment thread
bernt-matthias marked this conversation as resolved.
var pat = $job.pattern;
var matched = false;

try {
if (pat !== "") {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a empty_field validator instead to the param?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Added!

var re = new RegExp(pat);
matched = re.test(name);
Comment thread
bernt-matthias marked this conversation as resolved.
Outdated
}
} catch (e) {
return { "__error_message": "Invalid regular expression: " + (e && e.message ? e.message : String(e)) };
}

return { "matched": matched, "unmatched": !matched };
}]]></expression>
<inputs>
<param name="input" type="data" format="data"
label="Dataset" />
<param name="pattern" sanitize="false" type="text" label="Regex pattern"
help="Example: \.csv$">
<sanitizer>
<valid>
<add preset="string.printable"/>
<add value="\"/>
<add value="$"/>
</valid>
</sanitizer>
</param>
</inputs>
<outputs>
<output type="boolean" name="matched" from="matched" label="Match result"/>
<output type="boolean" name="unmatched" from="unmatched" label="Unmatched result"/>
</outputs>
<tests>
<test expect_num_outputs="2">
<param name="input" value="sample.csv"/>
<param name="pattern" value="\.csv$"/>
<output name="matched">
<assert_contents>
<has_line line="true"/>
</assert_contents>
</output>
<output name="unmatched">
<assert_contents>
<has_line line="false"/>
</assert_contents>
</output>
</test>
<test expect_num_outputs="2">
<param name="input" value="table.tsv"/>
<param name="pattern" value="\.csv$"/>
<output name="matched">
<assert_contents>
<has_line line="false"/>
</assert_contents>
</output>
<output name="unmatched">
<assert_contents>
<has_line line="true"/>
</assert_contents>
</output>
</test>
</tests>
<help><![CDATA[
**Regex switch**

Matches a regular expression against an element name. It emits two booleans:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guess "element name" needs better explanation. I guess you assume that the tool is mapped over a collection.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the name of the dict element (job["input"]["name"]) of cwl (?), which looks like that:

    "engineConfig": [],
    "job": {
        "input": {
            "file_ext": "tabular",
            "file_size": 14,
            "name": "table.tsv",
            "metadata": {
                "dbkey": "?",
                "data_lines": 2,
                "comment_lines": 0,
                "columns": 2,
                "column_types": [
                    "int",
                    "int"
                ],
                "column_names": [],
                "delimiter": "__tc__"
            },
            "src": {
                "src": "hda",
                "id": 4
            }
        },
        "pattern": "\.csv$"
    },
    "context": null,
    "outdir": null,
    "tmpdir": null,

Not sure if this name comes either of the element identifier or the element name (I guessed the latter).

`matched` (the match result) and `unmatched` (its negation). Connect either to a step's **Conditionally skip step?** input.
]]></help>
</tool>
2 changes: 2 additions & 0 deletions tools/regex_switch/test-data/sample.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
col1,col2
1,2
2 changes: 2 additions & 0 deletions tools/regex_switch/test-data/table.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
col1 col2
1 2
Loading