diff find_and_replace.xml @ 18:d698c222f354 draft

"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/text_processing/text_processing commit 378e99cde623698fb44ee7ac9873f455fb51fdbc"
author bgruening
date Sat, 08 Oct 2022 21:01:33 +0000
parents fb4ff3c42cd3
children 12615d397df7
line wrap: on
line diff
--- a/find_and_replace.xml	Tue Jun 22 16:06:48 2021 +0000
+++ b/find_and_replace.xml	Sat Oct 08 21:01:33 2022 +0000
@@ -1,4 +1,4 @@
-<tool id="tp_find_and_replace" name="Replace" version="@BASE_VERSION@.3">
+<tool id="tp_find_and_replace" name="Replace" version="@BASE_VERSION@.4">
     <description>parts of text</description>
     <macros>
         <import>macros.xml</import>
@@ -8,106 +8,149 @@
     </requirements>
     <command>
 <![CDATA[
-        perl '$__tool_directory__/find_and_replace'
-            #if $searchwhere.searchwhere_select == "column":
-                -c $searchwhere.column
+        #for $i, $el in enumerate($find_and_replace)
+            #if $i == (len($find_and_replace) - 1)
+                #set $join = ""
+            #else 
+                #set $join = "|"
             #end if
-            -o $outfile
-            $global
-            $caseinsensitive
-            $wholewords
-            $skip_first_line
-            $is_regex
-            '$find_pattern'
-            '$replace_pattern'
-            '$infile'
+            perl '$__tool_directory__/find_and_replace'
+                #if $el.searchwhere.searchwhere_select == "column":
+                    -c $el.searchwhere.column
+                #end if
+                #if $i == (len($find_and_replace) - 1)
+                    -o '$outfile'
+                #end if
+                $el.global
+                $el.caseinsensitive
+                $el.wholewords
+                $el.skip_first_line
+                $el.is_regex
+                '$el.find_pattern'
+                '$el.replace_pattern'
+                #if $i == 0
+                    '$infile'
+                #end if
+                $join
+        #end for        
 ]]>
     </command>
     <inputs>
         <param name="infile" format="txt" type="data" label="File to process" />
-        <param name="find_pattern" type="text" label="Find pattern" help="Use simple text, or a valid regular expression (without backslashes // ) " >
-            <sanitizer>
-                <valid initial="string.printable">
-                    <remove value="&apos;"/>
-                </valid>
-            </sanitizer>
-        </param>
-        <param name="replace_pattern" type="text" label="Replace with"
-            help="Use simple text, or $&amp; (dollar-ampersand) and $1 $2 $3 to refer to matched text. See examples below." >
-            <sanitizer>
-                <valid initial="string.printable">
-                    <remove value="&apos;"/>
-                </valid>
-            </sanitizer>
-        </param>
-        <param name="is_regex" type="boolean" checked="false" truevalue="-r" falsevalue=""
-            label="Find-Pattern is a regular expression" help="see help section for details." />
+        <repeat name="find_and_replace" title="Find and Replace" min="1">
+            <param name="find_pattern" type="text" label="Find pattern" help="Use simple text, or a valid regular expression (without backslashes // ) " >
+                <sanitizer>
+                    <valid initial="string.printable">
+                        <remove value="&apos;"/>
+                    </valid>
+                </sanitizer>
+            </param>
+            <param name="replace_pattern" type="text" label="Replace with"
+                help="Use simple text, or $&amp; (dollar-ampersand) and $1 $2 $3 to refer to matched text. See examples below." >
+                <sanitizer>
+                    <valid initial="string.printable">
+                        <remove value="&apos;"/>
+                    </valid>
+                </sanitizer>
+            </param>
+            <param name="is_regex" type="boolean" checked="false" truevalue="-r" falsevalue=""
+                label="Find-Pattern is a regular expression" help="see help section for details." />
 
-        <param name="global" type="boolean" checked="false" truevalue="-g" falsevalue=""
-            label="Replace all occurences of the pattern" />
+            <param name="global" type="boolean" checked="false" truevalue="-g" falsevalue=""
+                label="Replace all occurences of the pattern" />
+
+            <param name="caseinsensitive" type="boolean" checked="false" truevalue="-i" falsevalue=""
+                label="Case-Insensitive search" help="" />
 
-        <param name="caseinsensitive" type="boolean" checked="false" truevalue="-i" falsevalue=""
-            label="Case-Insensitive search" help="" />
+            <param name="wholewords" type="boolean" checked="false" truevalue="-w" falsevalue=""
+                label="Find whole-words" help="ignore partial matches (e.g. 'apple' will not match 'snapple')" />
 
-        <param name="wholewords" type="boolean" checked="false" truevalue="-w" falsevalue=""
-            label="Find whole-words" help="ignore partial matches (e.g. 'apple' will not match 'snapple')" />
+            <param name="skip_first_line" type="boolean" checked="false" truevalue="-s" falsevalue=""
+                label="Ignore first line" help="Select this option if the first line contains column headers. Text in the line will not be replaced. " />
 
-        <param name="skip_first_line" type="boolean" checked="false" truevalue="-s" falsevalue=""
-            label="Ignore first line" help="Select this option if the first line contains column headers. Text in the line will not be replaced. " />
-
-        <conditional name="searchwhere">
-            <param name="searchwhere_select" type="select" label="Find and Replace text in">
-                <option value="line" selected="true">entire line</option>
-                <option value="column">specific column</option>
-            </param>
-            <when value="line" />
-            <when value="column">
-                <param name="column" label="in column" type="data_column" data_ref="infile" accept_default="true" />
-            </when>
-        </conditional>
+            <conditional name="searchwhere">
+                <param name="searchwhere_select" type="select" label="Find and Replace text in">
+                    <option value="line" selected="true">entire line</option>
+                    <option value="column">specific column</option>
+                </param>
+                <when value="line" />
+                <when value="column">
+                    <param name="column" label="in column" type="data_column" data_ref="infile" accept_default="true" />
+                </when>
+            </conditional>
+        </repeat>
     </inputs>
     <outputs>
         <data format_source="infile" name="outfile" metadata_source="infile" />
     </outputs>
     <tests>
-        <test>
+        <test expect_num_outputs="1">
             <param name="infile" value="find_and_replace1.txt" />
-            <param name="find_pattern" value="day" />
-            <param name="replace_pattern" value="great day" />
-            <param name="is_regex" value="False" />
-            <param name="global" value="true" />
-            <param name="caseinsensitive" value="False" />
-            <param name="wholewords" value="True" />
-            <output name="outfile" file="find_and_replace_results1.txt" />
+            <repeat name="find_and_replace">
+                <param name="find_pattern" value="day" />
+                <param name="replace_pattern" value="great day" />
+                <param name="is_regex" value="False" />
+                <param name="global" value="true" />
+                <param name="caseinsensitive" value="False" />
+                <param name="wholewords" value="True" />
+            </repeat>
+            <output name="outfile" file="find_and_replace_results1.txt" />    
         </test>
 	<!-- test that columns are split by tab not space. input has no tab loads of spaces 
 	     .. therefore the ftype needs to be set. 
              result should be the same as in test 1 which works on whole line -->
-        <test>
+        <test expect_num_outputs="1">
             <param name="infile" value="find_and_replace1.txt" ftype="tabular" />
-            <param name="find_pattern" value="day" />
-            <param name="replace_pattern" value="great day" />
-            <param name="is_regex" value="False" />
-            <param name="global" value="true" />
-            <param name="caseinsensitive" value="False" />
-            <param name="wholewords" value="True" />
-            <conditional name="searchwhere">
-                <param name="searchwhere_select" value="column"/>
-                <param name="column" value="1" />
-            </conditional>
+            <repeat name="find_and_replace">
+                <param name="find_pattern" value="day" />
+                <param name="replace_pattern" value="great day" />
+                <param name="is_regex" value="False" />
+                <param name="global" value="true" />
+                <param name="caseinsensitive" value="False" />
+                <param name="wholewords" value="True" />
+                <conditional name="searchwhere">
+                    <param name="searchwhere_select" value="column"/>
+                    <param name="column" value="1" />
+                </conditional>
+            </repeat>
             <output name="outfile" file="find_and_replace_results1.txt" />
         </test>
-        <test>
+        <test expect_num_outputs="1">
             <param name="infile" value="find_and_replace2.txt" />
-            <param name="find_pattern" value="^chr" />
-            <param name="replace_pattern" value="" />
-            <param name="is_regex" value="True" />
-            <param name="caseinsensitive" value="False" />
-            <param name="wholewords" value="False" />
-            <param name="searchwhere_select" value="column" />
-            <param name="column" value="3" />
+            <repeat name="find_and_replace">
+                <param name="find_pattern" value="^chr" />
+                <param name="replace_pattern" value="" />
+                <param name="is_regex" value="True" />
+                <param name="caseinsensitive" value="False" />
+                <param name="wholewords" value="False" />
+                <conditional name="searchwhere">
+                    <param name="searchwhere_select" value="column" />
+                    <param name="column" value="3" />
+                </conditional>
+            </repeat>
             <output name="outfile" file="find_and_replace_results2.txt" />
         </test>
+        <test expect_num_outputs="1">
+            <param name="infile" value="find_and_replace1.txt" />
+            <repeat name="find_and_replace">
+                <param name="find_pattern" value="day" />
+                <param name="replace_pattern" value="great day" />
+                <param name="is_regex" value="False" />
+                <param name="global" value="true" />
+                <param name="caseinsensitive" value="False" />
+                <param name="wholewords" value="True" />
+            </repeat>
+            <param name="infile" value="find_and_replace1.txt" />
+            <repeat name="find_and_replace">
+                <param name="find_pattern" value="great" />
+                <param name="replace_pattern" value="best" />
+                <param name="is_regex" value="False" />
+                <param name="global" value="False" />
+                <param name="caseinsensitive" value="False" />
+                <param name="wholewords" value="True" />
+            </repeat>
+            <output name="outfile" file="find_and_replace_results3.txt" />    
+        </test>
     </tests>
     <help>
 <![CDATA[
@@ -125,7 +168,7 @@
 
 .. class:: infomark
 
-This tool uses Perl regular expression syntax.
+This tool uses `Perl regular expression <https://perldoc.perl.org/perlre>`_ syntax.
 
 -----