0
|
1 <tool id="cshl_find_and_replace" name="Find and Replace" version="0.1.1">
|
|
2 <description>text</description>
|
|
3 <command interpreter="perl">
|
|
4 find_and_replace
|
|
5 #if $searchwhere.choice == "column":
|
|
6 -c $searchwhere.column
|
|
7 #end if
|
|
8 -o $output
|
|
9 $caseinsensitive
|
|
10 $wholewords
|
|
11 $skip_first_line
|
|
12 $is_regex
|
|
13 '$url_paste'
|
|
14 '$file_data'
|
|
15 '$input'
|
|
16 </command>
|
|
17 <inputs>
|
|
18 <param format="txt" name="input" type="data" label="File to process" />
|
|
19 <param name="url_paste" type="text" size="20" label="Find pattern" help="Use simple text, or a valid regular expression (without backslashes // ) " >
|
|
20 <sanitizer>
|
|
21 <valid initial="string.printable">
|
|
22 <remove value="'"/>
|
|
23 </valid>
|
|
24 </sanitizer>
|
|
25 </param>
|
|
26
|
|
27 <param name="file_data" type="text" size="20" label="Replace with" help="Use simple text, or $& (dollar-ampersand) and $1 $2 $3 to refer to matched text. See examples below." >
|
|
28 <sanitizer>
|
|
29 <valid initial="string.printable">
|
|
30 <remove value="'"/>
|
|
31 </valid>
|
|
32 </sanitizer>
|
|
33 </param>
|
|
34
|
|
35 <param name="is_regex" type="boolean" checked="false" truevalue="-r" falsevalue="" label="Find-Pattern is a regular expression"
|
|
36 help="see help section for details." />
|
|
37
|
|
38 <param name="caseinsensitive" type="boolean" checked="false" truevalue="-i" falsevalue="" label="Case-Insensitive search"
|
|
39 help="" />
|
|
40
|
|
41 <param name="wholewords" type="boolean" checked="false" truevalue="-w" falsevalue="" label="find whole-words"
|
|
42 help="ignore partial matches (e.g. 'apple' will not match 'snapple') " />
|
|
43
|
|
44 <param name="skip_first_line" type="boolean" checked="false" truevalue="-s" falsevalue="" label="Ignore first line"
|
|
45 help="Select this option if the first line contains column headers. Text in the line will not be replaced. " />
|
|
46
|
|
47 <conditional name="searchwhere">
|
|
48 <param name="choice" type="select" label="Replace text in">
|
|
49 <option value="line" selected="true">entire line</option>
|
|
50 <option value="column">specific column</option>
|
|
51 </param>
|
|
52 <when value="line" />
|
|
53
|
|
54 <when value="column">
|
|
55 <param name="column" label="in column" type="data_column" data_ref="input" accept_default="true" />
|
|
56 </when>
|
|
57 </conditional>
|
|
58 </inputs>
|
|
59
|
|
60 <outputs>
|
|
61 <data format="input" name="output" metadata_source="input" />
|
|
62 </outputs>
|
|
63
|
|
64 <help>
|
|
65
|
|
66 **What it does**
|
|
67
|
|
68 This tool finds & replaces text in an input dataset.
|
|
69
|
|
70 .. class:: infomark
|
|
71
|
|
72 The **pattern to find** can be a simple text string, or a perl **regular expression** string (depending on *pattern is a regex* check-box).
|
|
73
|
|
74 .. class:: infomark
|
|
75
|
|
76 When using regular expressions, the **replace pattern** can contain back-references ( e.g. \\1 )
|
|
77
|
|
78 .. class:: infomark
|
|
79
|
|
80 This tool uses Perl regular expression syntax.
|
|
81
|
|
82 -----
|
|
83
|
|
84 **Examples of *regular-expression* Find Patterns**
|
|
85
|
|
86 - **HELLO** The word 'HELLO' (case sensitive).
|
|
87 - **AG.T** The letters A,G followed by any single character, followed by the letter T.
|
|
88 - **A{4,}** Four or more consecutive A's.
|
|
89 - **chr2[012]\\t** The words 'chr20' or 'chr21' or 'chr22' followed by a tab character.
|
|
90 - **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.
|
|
91
|
|
92
|
|
93 **Examples of Replace Patterns**
|
|
94
|
|
95 - **WORLD** The word 'WORLD' will be placed whereever the find pattern was found.
|
|
96 - **FOO-&-BAR** Each time the find pattern is found, it will be surrounded with 'FOO-' at the begining and '-BAR' at the end. **$&** (dollar-ampersand) represents the matched find pattern.
|
|
97 - **$1** The text which matched the first parenthesis in the Find Pattern.
|
|
98
|
|
99
|
|
100 -----
|
|
101
|
|
102 **Example 1**
|
|
103
|
|
104 **Find Pattern:** HELLO
|
|
105 **Replace Pattern:** WORLD
|
|
106 **Regular Expression:** no
|
|
107 **Replace what:** entire line
|
|
108
|
|
109 Every time the word HELLO is found, it will be replaced with the word WORLD.
|
|
110
|
|
111 -----
|
|
112
|
|
113 **Example 2**
|
|
114
|
|
115 **Find Pattern:** ^chr
|
|
116 **Replace Pattern:** (empty)
|
|
117 **Regular Expression:** yes
|
|
118 **Replace what:** column 11
|
|
119
|
|
120 If column 11 (of every line) begins with ther letters 'chr', they will be removed. Effectively, it'll turn "chr4" into "4" and "chrXHet" into "XHet"
|
|
121
|
|
122
|
|
123 -----
|
|
124
|
|
125 **Perl's Regular Expression Syntax**
|
|
126
|
|
127 The Find & Replace 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.
|
|
128
|
|
129 - **( ) { } [ ] . * ? + \\ ^ $** are all special characters. **\\** can be used to "escape" a special character, allowing that special character to be searched for.
|
|
130 - **^** matches the beginning of a string(but not an internal line).
|
|
131 - **(** .. **)** groups a particular pattern.
|
|
132 - **{** n or n, or n,m **}** specifies an expected number of repetitions of the preceding pattern.
|
|
133
|
|
134 - **{n}** The preceding item is matched exactly n times.
|
|
135 - **{n,}** The preceding item ismatched n or more times.
|
|
136 - **{n,m}** The preceding item is matched at least n times but not more than m times.
|
|
137
|
|
138 - **[** ... **]** 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**.
|
|
139 - **.** Matches any single character except a newline.
|
|
140 - ***** The preceding item will be matched zero or more times.
|
|
141 - **?** The preceding item is optional and matched at most once.
|
|
142 - **+** The preceding item will be matched one or more times.
|
|
143 - **^** has two meaning:
|
|
144 - matches the beginning of a line or string.
|
|
145 - indicates negation in a character class. For example, [^...] matches every character except the ones inside brackets.
|
|
146 - **$** matches the end of a line or string.
|
|
147 - **\\|** Separates alternate possibilities.
|
|
148 - **\\d** matches a single digit
|
|
149 - **\\w** matches a single letter or digit or an underscore.
|
|
150 - **\\s** matches a single white-space (space or tabs).
|
|
151
|
|
152
|
|
153 </help>
|
|
154
|
|
155 </tool>
|