comparison find_and_replace.xml @ 0:631dfde45073 draft default tip

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