-
Notifications
You must be signed in to change notification settings - Fork 508
Add regex switch expression tool #7314
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
Changes from 5 commits
0285823
edf2b1e
915c1e0
c220d1f
4199ec9
7851c28
e2e5097
767e9f5
2da8ced
e4dfb0c
64f78fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
| homepage_url: https://github.com/galaxyproject/tools-iuc/tree/master/tools/regex_switch | ||
| type: unrestricted | ||
| 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; | ||
|
bernt-matthias marked this conversation as resolved.
|
||
| var pat = $job.pattern; | ||
| var matched = false; | ||
|
|
||
| try { | ||
| if (pat !== "") { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! Added! |
||
| var re = new RegExp(pat); | ||
| matched = re.test(name); | ||
|
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: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: 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> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| col1,col2 | ||
| 1,2 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| col1 col2 | ||
| 1 2 |
Uh oh!
There was an error while loading. Please reload this page.