changeset 25:cd83b5644eab 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 20:59:15 +0000
parents 5fef6d08de83
children f22a309187a3
files find_and_replace.xml test-data/find_and_replace_results3.txt
diffstat 2 files changed, 121 insertions(+), 77 deletions(-) [+]
line wrap: on
line diff
--- a/find_and_replace.xml	Tue Jun 22 16:03:26 2021 +0000
+++ b/find_and_replace.xml	Sat Oct 08 20:59:15 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.
 
 -----
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/find_and_replace_results3.txt	Sat Oct 08 20:59:15 2022 +0000
@@ -0,0 +1,1 @@
+I have a dream that one best day this nation will rise up, and live out the true meaning of its creed: ‘We hold these truths to be self-evident: that all men are created equal.’ I have a dream that one great day on the red hills of Georgia the sons of former slaves and the sons of former slave owners will be able to sit down together at a table of brotherhood. I have a dream that one great day even the state of Mississippi, a state sweltering with the heat of injustice and sweltering with the heat of oppression, will be transformed into an oasis of freedom and justice. I have a dream that my four little children will one great day live in a nation where they will not be judged by the color of their skin but by the content of their character. I have a dream today!