changeset 2:538933d9fccc draft

"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/regex_find_replace commit 8871a847daed1f996c0a2069c3e876685bf8d220"
author galaxyp
date Tue, 07 Apr 2020 11:31:27 -0400
parents 209b7c5ee9d7
children ae8c4b2488e7
files regex.py regex.xml regex_tabular.xml
diffstat 3 files changed, 63 insertions(+), 51 deletions(-) [+]
line wrap: on
line diff
--- 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()
--- a/regex.xml	Thu Jan 19 11:26:15 2017 -0500
+++ b/regex.xml	Tue Apr 07 11:31:27 2020 -0400
@@ -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>
--- 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"/>