upstream-extended/community/tools/text_processing/text_processing/replace_text_in_column.xml
1<tool id="tp_replace_in_column" name="Replace Text" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="@PROFILE@">
2 <description>in a specific column</description>
3 <macros>
4 <import>macros.xml</import>
5 </macros>
6 <expand macro="creator"/>
7 <requirements>
8 <requirement type="package" version="5.4.1">gawk</requirement>
9 </requirements>
10 <version_command>awk --version | head -n 1</version_command>
11 <command>
12<![CDATA[
13 awk
14 -v OFS="\t"
15 -v FS="\t"
16 --re-interval
17 --sandbox
18 '{
19 #for $replacement in $replacements:
20 \$$replacement.column = gensub( /$replacement.find_pattern/, "$replacement.replace_pattern", "g", \$$replacement.column ) ;
21 #end for
22 print \$0 ; }'
23 '$infile'
24 > '$outfile'
25]]>
26 </command>
27 <inputs>
28 <param format="tabular" name="infile" type="data" label="File to process" />
29 <repeat name="replacements" title="Replacement" min="1">
30 <param name="column" label="in column" type="data_column" data_ref="infile" accept_default="true" />
31
32 <param name="find_pattern" type="text" label="Find pattern" help="Use simple text, or a valid regular expression (without backslashes // ) " >
33 <sanitizer>
34 <valid initial="string.printable">
35 <remove value="'"/>
36 </valid>
37 </sanitizer>
38 </param>
39 <param name="replace_pattern" type="text" label="Replace with" help="Use simple text, or & (ampersand) and \\1 \\2 \\3 to refer to matched text. See examples below." >
40 <sanitizer>
41 <valid initial="string.printable">
42 <remove value="'"/>
43 </valid>
44 </sanitizer>
45 </param>
46 </repeat>
47 </inputs>
48 <outputs>
49 <data name="outfile" format_source="infile" metadata_source="infile" />
50 </outputs>
51 <tests>
52 <test>
53 <param name="infile" value="replace_text_in_column1.txt" ftype="tabular" />
54 <repeat name="replacements">
55 <param name="column" value="4" />
56 <param name="find_pattern" value=".+_(R.)" />
57 <param name="replace_pattern" value="\\1" />
58 </repeat>
59 <output name="outfile" file="replace_text_in_column_results1.txt" />
60 </test>
61 <test>
62 <param name="infile" value="replace_text_in_column1.txt" ftype="tabular" />
63 <repeat name="replacements">
64 <param name="column" value="1" />
65 <param name="find_pattern" value="[a-z]{2}([a-z])" />
66 <param name="replace_pattern" value="\\1" />
67 </repeat>
68 <repeat name="replacements">
69 <param name="column" value="4" />
70 <param name="find_pattern" value=".+_(R.)" />
71 <param name="replace_pattern" value="\\1" />
72 </repeat>
73 <output name="outfile" file="replace_text_in_column_results2.txt" />
74 </test>
75 </tests>
76 <help>
77<![CDATA[
78**What it does**
79
80This tool performs find & replace operation on a specified column in a given file.
81
82.. class:: infomark
83
84The **pattern to find** uses the **extended regular** expression syntax (same as running 'awk --re-interval').
85
86.. class:: infomark
87
88**TIP:** If you need more complex patterns, use the *awk* tool.
89
90-----
91
92
93**Examples of Find Patterns**
94
95- **HELLO** The word 'HELLO' (case sensitive).
96- **AG.T** The letters A,G followed by any single character, followed by the letter T.
97- **A{4,}** Four or more consecutive A's.
98- **chr2[012]\\t** The words 'chr20' or 'chr21' or 'chr22' followed by a tab character.
99- **hsa-mir-([^ ]+)** The text 'hsa-mir-' followed by one-or-more non-space characters. When using parenthesis, the matched content of the parenthesis can be accessed with **\1** in the **replace** pattern.
100
101
102**Examples of Replace Patterns**
103
104- **WORLD** The word 'WORLD' will be placed whereever the find pattern was found.
105- **FOO-&-BAR** Each time the find pattern is found, it will be surrounded with 'FOO-' at the begining and '-BAR' at the end. **&** (ampersand) represents the matched find pattern.
106- **\\1** The text which matched the first parenthesis in the Find Pattern.
107
108
109-----
110
111**Example 1**
112
113**Find Pattern:** HELLO
114**Replace Pattern:** WORLD
115
116Every time the word HELLO is found, it will be replaced with the word WORLD. This operation affects only the selected column.
117
118-----
119
120**Example 2**
121
122**Find Pattern:** ^(.{4})
123**Replace Pattern:** &\\t
124
125Find the first four characters in each line, and replace them with the same text, followed by a tab character. In practice - this will split the first line into two columns. This operation affects only the selected column.
126
127
128-----
129
130**Extened Regular Expression Syntax**
131
132The select tool searches the data for lines containing or not containing a match to the given pattern. A Regular Expression is a pattern descibing a certain amount of text.
133
134- **( ) { } [ ] . * ? + \ ^ $** are all special characters. **\\** can be used to "escape" a special character, allowing that special character to be searched for.
135- **^** matches the beginning of a string(but not an internal line).
136- **(** .. **)** groups a particular pattern.
137- **{** n or n, or n,m **}** specifies an expected number of repetitions of the preceding pattern.
138
139 - **{n}** The preceding item is matched exactly n times.
140 - **{n,}** The preceding item ismatched n or more times.
141 - **{n,m}** The preceding item is matched at least n times but not more than m times.
142
143- **[** ... **]** creates a character class. Within the brackets, single characters can be placed. A dash (-) may be used to indicate a range such as **a-z**.
144- **.** Matches any single character except a newline.
145- ***** The preceding item will be matched zero or more times.
146- **?** The preceding item is optional and matched at most once.
147- **+** The preceding item will be matched one or more times.
148- **^** has two meaning:
149 - matches the beginning of a line or string.
150 - indicates negation in a character class. For example, [^...] matches every character except the ones inside brackets.
151- **$** matches the end of a line or string.
152- **\|** Separates alternate possibilities.
153
154
155**Note**: AWK uses extended regular expression syntax, not Perl syntax. **\\d**, **\\w**, **\\s** etc. are **not** supported.
156
157]]>
158 </help>
159 <expand macro="citations" />
160</tool>