Mercurial > repos > bgruening > text_processing
annotate replace_text_in_line.xml @ 10:c78b1767db2b draft
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/text_processing/text_processing commit 10052765d6b712cf7d38356af4251fcc38a339b6-dirty
author | bgruening |
---|---|
date | Fri, 26 Feb 2016 12:22:54 -0500 |
parents | d64eace4f9f3 |
children | 062ed2bb4f2e |
rev | line source |
---|---|
4 | 1 <tool id="tp_replace_in_line" name="Replace Text" version="@BASE_VERSION@.0"> |
3 | 2 <description>in entire line</description> |
4 | 3 <macros> |
4 <import>macros.xml</import> | |
5 </macros> | |
6 <expand macro="requirements"> | |
3 | 7 <requirement type="package" version="4.2.2-sandbox">gnu_sed</requirement> |
4 | 8 </expand> |
9 <version_command>sed --version | head -n 1</version_command> | |
6 | 10 <command> |
4 | 11 <![CDATA[ |
7 | 12 sed |
4 | 13 -r |
14 --sandbox | |
15 "s/$find_pattern/$replace_pattern/g" | |
6 | 16 "$infile" |
17 > "$outfile" | |
4 | 18 ]]> |
3 | 19 </command> |
20 <inputs> | |
6 | 21 <param format="txt" name="infile" type="data" label="File to process" /> |
10
c78b1767db2b
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/text_processing/text_processing commit 10052765d6b712cf7d38356af4251fcc38a339b6-dirty
bgruening
parents:
7
diff
changeset
|
22 <param name="find_pattern" type="text" label="Find pattern" help="Use simple text, or a valid regular expression (without backslashes // ) " > |
3 | 23 <sanitizer> |
24 <valid initial="string.printable"> | |
25 <remove value="'"/> | |
26 </valid> | |
27 </sanitizer> | |
28 </param> | |
10
c78b1767db2b
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/text_processing/text_processing commit 10052765d6b712cf7d38356af4251fcc38a339b6-dirty
bgruening
parents:
7
diff
changeset
|
29 <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." > |
3 | 30 <sanitizer> |
31 <valid initial="string.printable"> | |
32 <remove value="'"/> | |
33 </valid> | |
34 </sanitizer> | |
35 </param> | |
36 </inputs> | |
37 <outputs> | |
6 | 38 <data name="outfile" format_source="infile" metadata_source="infile"/> |
3 | 39 </outputs> |
4 | 40 <tests> |
41 <test> | |
6 | 42 <param name="infile" value="replace_text_in_line1.txt" /> |
4 | 43 <param name="find_pattern" value="CTC." /> |
44 <param name="replace_pattern" value="FOOBAR" /> | |
6 | 45 <output name="outfile" file="replace_text_in_line_results1.txt" /> |
4 | 46 </test> |
47 </tests> | |
3 | 48 <help> |
4 | 49 <![CDATA[ |
3 | 50 **What it does** |
51 | |
6 | 52 This tool performs find & replace operation on a specified file. |
3 | 53 |
54 .. class:: infomark | |
55 | |
56 The **pattern to find** uses the **extended regular** expression syntax (same as running 'sed -r'). | |
57 | |
58 .. class:: infomark | |
59 | |
60 **TIP:** If you need more complex patterns, use the *sed* tool. | |
61 | |
62 ----- | |
63 | |
64 **Examples of Find Patterns** | |
65 | |
66 - **HELLO** The word 'HELLO' (case sensitive). | |
67 - **AG.T** The letters A,G followed by any single character, followed by the letter T. | |
68 - **A{4,}** Four or more consecutive A's. | |
69 - **chr2[012]\\t** The words 'chr20' or 'chr21' or 'chr22' followed by a tab character. | |
70 - **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. | |
71 | |
72 | |
73 **Examples of Replace Patterns** | |
74 | |
75 - **WORLD** The word 'WORLD' will be placed whereever the find pattern was found. | |
6 | 76 - **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. |
3 | 77 - **\\1** The text which matched the first parenthesis in the Find Pattern. |
78 | |
79 | |
80 ----- | |
81 | |
82 **Example 1** | |
83 | |
84 **Find Pattern:** HELLO | |
85 **Replace Pattern:** WORLD | |
86 | |
87 Every time the word HELLO is found, it will be replaced with the word WORLD. | |
88 | |
89 | |
90 ----- | |
91 | |
92 **Example 2** | |
93 | |
7 | 94 **Find Pattern:** ^(.{4}) |
6 | 95 **Replace Pattern:** &\\t |
3 | 96 |
97 Find 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. | |
98 | |
99 | |
100 ----- | |
101 | |
102 **Extened Regular Expression Syntax** | |
103 | |
7 | 104 The 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. |
3 | 105 |
106 - **( ) { } [ ] . * ? + \ ^ $** are all special characters. **\\** can be used to "escape" a special character, allowing that special character to be searched for. | |
107 - **^** matches the beginning of a string(but not an internal line). | |
108 - **(** .. **)** groups a particular pattern. | |
109 - **{** n or n, or n,m **}** specifies an expected number of repetitions of the preceding pattern. | |
110 | |
111 - **{n}** The preceding item is matched exactly n times. | |
7 | 112 - **{n,}** The preceding item ismatched n or more times. |
113 - **{n,m}** The preceding item is matched at least n times but not more than m times. | |
3 | 114 |
115 - **[** ... **]** 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**. | |
116 - **.** Matches any single character except a newline. | |
117 - ***** The preceding item will be matched zero or more times. | |
118 - **?** The preceding item is optional and matched at most once. | |
119 - **+** The preceding item will be matched one or more times. | |
120 - **^** has two meaning: | |
7 | 121 - matches the beginning of a line or string. |
3 | 122 - indicates negation in a character class. For example, [^...] matches every character except the ones inside brackets. |
123 - **$** matches the end of a line or string. | |
7 | 124 - **\|** Separates alternate possibilities. |
3 | 125 |
126 | |
127 **Note**: SED uses extended regular expression syntax, not Perl syntax. **\\d**, **\\w**, **\\s** etc. are **not** supported. | |
128 | |
4 | 129 @REFERENCES@ |
130 ]]> | |
3 | 131 </help> |
132 </tool> |