Previous changeset 1:209b7c5ee9d7 (2017-01-19) Next changeset 3:ae8c4b2488e7 (2020-05-08) |
Commit message:
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/regex_find_replace commit 8871a847daed1f996c0a2069c3e876685bf8d220" |
modified:
regex.py regex.xml regex_tabular.xml |
b |
diff -r 209b7c5ee9d7 -r 538933d9fccc regex.py --- a/regex.py Thu Jan 19 11:26:15 2017 -0500 +++ b/regex.py Tue Apr 07 11:31:27 2020 -0400 |
[ |
@@ -1,50 +1,47 @@ -import sys -import os +from optparse import OptionParser import re -import string -import commands -from optparse import OptionParser -from tempfile import NamedTemporaryFile + def main(): - parser = OptionParser() - parser.add_option("--input", dest="input") - parser.add_option("--output", dest="output") - parser.add_option("--input_display_name", dest="input_display_name") - parser.add_option("--pattern", dest="patterns", action="append", - help="regex pattern for replacement") - parser.add_option("--replacement", dest="replacements", action="append", - help="replacement for regex match") - parser.add_option("--column", dest="column", default=None) - (options, args) = parser.parse_args() + parser = OptionParser() + parser.add_option("--input", dest="input") + parser.add_option("--output", dest="output") + parser.add_option("--input_display_name", dest="input_display_name") + parser.add_option("--pattern", dest="patterns", action="append", + help="regex pattern for replacement") + parser.add_option("--replacement", dest="replacements", action="append", + help="replacement for regex match") + parser.add_option("--column", dest="column", default=None) + (options, args) = parser.parse_args() - mapped_chars = { '\'' :'__sq__', '\\' : '__backslash__' } + mapped_chars = {'\'': '__sq__', '\\': '__backslash__'} - column = None - if options.column is not None: - column = int(options.column) - 1 # galaxy tabular is 1-based, python array are zero-based + column = None + if options.column is not None: + # galaxy tabular is 1-based, python array are zero-based + column = int(options.column) - 1 - with open(options.input, 'r') as input: - with open(options.output, 'w') as output: - while True: - line = input.readline() - if line == "": - break - for (pattern, replacement) in zip(options.patterns, options.replacements): - for key, value in mapped_chars.items(): - pattern = pattern.replace(value, key) - replacement = replacement.replace(value, key) - replacement = replacement.replace("#{input_name}", options.input_display_name) - if column is None: - line = re.sub(pattern, replacement, line) - else: - cells = line.split("\t") - if cells and len(cells) > column: - cell = cells[column] - cell = re.sub(pattern, replacement, cell) - cells[column] = cell - line = "\t".join(cells) - output.write(line) + with open(options.input, 'r') as input, open(options.output, 'w') as output: + while True: + line = input.readline() + if line == "": + break + for (pattern, replacement) in zip(options.patterns, options.replacements): + for key, value in mapped_chars.items(): + pattern = pattern.replace(value, key) + replacement = replacement.replace(value, key) + replacement = replacement.replace("#{input_name}", options.input_display_name) + if column is None: + line = re.sub(pattern, replacement, line) + else: + cells = line.split("\t") + if cells and len(cells) > column: + cell = cells[column] + cell = re.sub(pattern, replacement, cell) + cells[column] = cell + line = "\t".join(cells) + output.write(line) + if __name__ == "__main__": main() |
b |
diff -r 209b7c5ee9d7 -r 538933d9fccc regex.xml --- a/regex.xml Thu Jan 19 11:26:15 2017 -0500 +++ b/regex.xml Tue Apr 07 11:31:27 2020 -0400 |
b |
@@ -1,8 +1,15 @@ -<tool id="regex1" name="Regex Find And Replace" version="1.0.0"> +<tool id="regex1" name="Regex Find And Replace" version="1.0.1"> <description></description> - <command interpreter="python">regex.py --input '$input' --output '$out_file1' --input_display_name '$input.display_name' + <requirements> + <requirement type="package" version="3.7">python</requirement> + </requirements> + <command> + python '$__tool_directory__/regex.py' + --input '$input' + --output '$out_file1' + --input_display_name '$input.display_name' #for $check in $checks: - --pattern='$check.pattern' --replacement='$check.replacement' + --pattern='$check.pattern' --replacement='$check.replacement' #end for </command> <inputs> |
b |
diff -r 209b7c5ee9d7 -r 538933d9fccc regex_tabular.xml --- a/regex_tabular.xml Thu Jan 19 11:26:15 2017 -0500 +++ b/regex_tabular.xml Tue Apr 07 11:31:27 2020 -0400 |
[ |
@@ -1,15 +1,23 @@ -<tool id="regexColumn1" name="Column Regex Find And Replace" version="1.0.0"> +<tool id="regexColumn1" name="Column Regex Find And Replace" version="1.0.1"> <description></description> - <command interpreter="python">regex.py --input '$input' --output '$out_file1' --column $field --input_display_name '$input.display_name' - #for $check in $checks: - --pattern='$check.pattern' --replacement='$check.replacement' - #end for + <requirements> + <requirement type="package" version="3.7">python</requirement> + </requirements> + <command> + python '$__tool_requirements__/regex.py' + --input '$input' + --output '$out_file1' + --column $field + --input_display_name '$input.display_name' + #for $check in $checks: + --pattern='$check.pattern' --replacement='$check.replacement' + #end for </command> <inputs> <param format="tabular" name="input" type="data" label="Select cells from"/> <param name="field" label="using column" type="data_column" data_ref="input" /> <repeat name="checks" title="Check"> - <param name="pattern" size="40" type="text" value="chr([0-9A-Za-z])+" label="Find Regex" help="here you can enter text or regular expression (for syntax check lower part of this frame)"> + <param name="pattern" type="text" value="chr([0-9A-Za-z])+" label="Find Regex" help="here you can enter text or regular expression (for syntax check lower part of this frame)"> <sanitizer> <valid> <add preset="string.printable"/> @@ -22,7 +30,7 @@ </mapping> </sanitizer> </param> - <param name="replacement" size="40" type="text" value="newchr\1" label="Replacement"> + <param name="replacement" type="text" value="newchr\1" label="Replacement"> <sanitizer> <valid> <add preset="string.printable"/> |