annotate replace_text_in_column.xml @ 3:7068d1548234 draft

Uploaded
author bgruening
date Sun, 06 Oct 2013 08:22:36 -0400
parents
children 56e80527c482
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
7068d1548234 Uploaded
bgruening
parents:
diff changeset
1 <tool id="tp_replace_in_column" name="Replace Text" version="0.1">
7068d1548234 Uploaded
bgruening
parents:
diff changeset
2 <description>in a specific column</description>
7068d1548234 Uploaded
bgruening
parents:
diff changeset
3 <requirements>
7068d1548234 Uploaded
bgruening
parents:
diff changeset
4 <requirement type="package" version="4.1.0">gnu_awk</requirement>
7068d1548234 Uploaded
bgruening
parents:
diff changeset
5 </requirements>
7068d1548234 Uploaded
bgruening
parents:
diff changeset
6 <command interpreter="sh">
7068d1548234 Uploaded
bgruening
parents:
diff changeset
7 #adapt to awk's quirks - to pass an acutal backslash - two backslashes are required (just like in a C string)
7068d1548234 Uploaded
bgruening
parents:
diff changeset
8 REPLACE_PATTERN=\${$replace_pattern//\\/\\\\};
7068d1548234 Uploaded
bgruening
parents:
diff changeset
9 awk -v OFS="\t" --re-interval --sandbox "{ \$$column = gensub( /$find_pattern/, \"$replace_pattern\", \"g\", \$$column ) ; print \$0 ; }" "$input" &gt; "$output"
7068d1548234 Uploaded
bgruening
parents:
diff changeset
10 </command>
7068d1548234 Uploaded
bgruening
parents:
diff changeset
11 <inputs>
7068d1548234 Uploaded
bgruening
parents:
diff changeset
12 <param format="tabular" name="input" type="data" label="File to process" />
7068d1548234 Uploaded
bgruening
parents:
diff changeset
13 <param name="column" label="in column" type="data_column" data_ref="input" accept_default="true" />
7068d1548234 Uploaded
bgruening
parents:
diff changeset
14
7068d1548234 Uploaded
bgruening
parents:
diff changeset
15 <param name="find_pattern" type="text" size="20" label="Find pattern" help="Use simple text, or a valid regular expression (without backslashes // ) " >
7068d1548234 Uploaded
bgruening
parents:
diff changeset
16 <sanitizer>
7068d1548234 Uploaded
bgruening
parents:
diff changeset
17 <valid initial="string.printable">
7068d1548234 Uploaded
bgruening
parents:
diff changeset
18 <remove value="&apos;"/>
7068d1548234 Uploaded
bgruening
parents:
diff changeset
19 </valid>
7068d1548234 Uploaded
bgruening
parents:
diff changeset
20 </sanitizer>
7068d1548234 Uploaded
bgruening
parents:
diff changeset
21 </param>
7068d1548234 Uploaded
bgruening
parents:
diff changeset
22
7068d1548234 Uploaded
bgruening
parents:
diff changeset
23 <param name="replace_pattern" type="text" size="20" label="Replace with" help="Use simple text, or &amp; (ampersand) and \\1 \\2 \\3 to refer to matched text. See examples below." >
7068d1548234 Uploaded
bgruening
parents:
diff changeset
24 <sanitizer>
7068d1548234 Uploaded
bgruening
parents:
diff changeset
25 <valid initial="string.printable">
7068d1548234 Uploaded
bgruening
parents:
diff changeset
26 <remove value="&apos;"/>
7068d1548234 Uploaded
bgruening
parents:
diff changeset
27 </valid>
7068d1548234 Uploaded
bgruening
parents:
diff changeset
28 </sanitizer>
7068d1548234 Uploaded
bgruening
parents:
diff changeset
29 </param>
7068d1548234 Uploaded
bgruening
parents:
diff changeset
30
7068d1548234 Uploaded
bgruening
parents:
diff changeset
31 </inputs>
7068d1548234 Uploaded
bgruening
parents:
diff changeset
32 <tests>
7068d1548234 Uploaded
bgruening
parents:
diff changeset
33 <test>
7068d1548234 Uploaded
bgruening
parents:
diff changeset
34 <param name="input" value="replace_text_in_column_in1.txt" ftype="tabular" />
7068d1548234 Uploaded
bgruening
parents:
diff changeset
35 <output name="output" file="replace_text_in_column_output1.txt" />
7068d1548234 Uploaded
bgruening
parents:
diff changeset
36 <param name="column" value="4" />
7068d1548234 Uploaded
bgruening
parents:
diff changeset
37 <param name="url_paste" value=".+_(R.)" />
7068d1548234 Uploaded
bgruening
parents:
diff changeset
38 <param name="file_data" value="\1" />
7068d1548234 Uploaded
bgruening
parents:
diff changeset
39 </test>
7068d1548234 Uploaded
bgruening
parents:
diff changeset
40 </tests>
7068d1548234 Uploaded
bgruening
parents:
diff changeset
41 <outputs>
7068d1548234 Uploaded
bgruening
parents:
diff changeset
42 <data format="input" name="output" metadata_source="input" />
7068d1548234 Uploaded
bgruening
parents:
diff changeset
43 </outputs>
7068d1548234 Uploaded
bgruening
parents:
diff changeset
44 <help>
7068d1548234 Uploaded
bgruening
parents:
diff changeset
45
7068d1548234 Uploaded
bgruening
parents:
diff changeset
46 **What it does**
7068d1548234 Uploaded
bgruening
parents:
diff changeset
47
7068d1548234 Uploaded
bgruening
parents:
diff changeset
48 This tool performs find &amp; replace operation on a specified column in a given file.
7068d1548234 Uploaded
bgruening
parents:
diff changeset
49
7068d1548234 Uploaded
bgruening
parents:
diff changeset
50 .. class:: infomark
7068d1548234 Uploaded
bgruening
parents:
diff changeset
51
7068d1548234 Uploaded
bgruening
parents:
diff changeset
52 The **pattern to find** uses the **extended regular** expression syntax (same as running 'awk --re-interval').
7068d1548234 Uploaded
bgruening
parents:
diff changeset
53
7068d1548234 Uploaded
bgruening
parents:
diff changeset
54 .. class:: infomark
7068d1548234 Uploaded
bgruening
parents:
diff changeset
55
7068d1548234 Uploaded
bgruening
parents:
diff changeset
56 **TIP:** If you need more complex patterns, use the *awk* tool.
7068d1548234 Uploaded
bgruening
parents:
diff changeset
57
7068d1548234 Uploaded
bgruening
parents:
diff changeset
58 -----
7068d1548234 Uploaded
bgruening
parents:
diff changeset
59
7068d1548234 Uploaded
bgruening
parents:
diff changeset
60
7068d1548234 Uploaded
bgruening
parents:
diff changeset
61 **Examples of Find Patterns**
7068d1548234 Uploaded
bgruening
parents:
diff changeset
62
7068d1548234 Uploaded
bgruening
parents:
diff changeset
63 - **HELLO** The word 'HELLO' (case sensitive).
7068d1548234 Uploaded
bgruening
parents:
diff changeset
64 - **AG.T** The letters A,G followed by any single character, followed by the letter T.
7068d1548234 Uploaded
bgruening
parents:
diff changeset
65 - **A{4,}** Four or more consecutive A's.
7068d1548234 Uploaded
bgruening
parents:
diff changeset
66 - **chr2[012]\\t** The words 'chr20' or 'chr21' or 'chr22' followed by a tab character.
7068d1548234 Uploaded
bgruening
parents:
diff changeset
67 - **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.
7068d1548234 Uploaded
bgruening
parents:
diff changeset
68
7068d1548234 Uploaded
bgruening
parents:
diff changeset
69
7068d1548234 Uploaded
bgruening
parents:
diff changeset
70 **Examples of Replace Patterns**
7068d1548234 Uploaded
bgruening
parents:
diff changeset
71
7068d1548234 Uploaded
bgruening
parents:
diff changeset
72 - **WORLD** The word 'WORLD' will be placed whereever the find pattern was found.
7068d1548234 Uploaded
bgruening
parents:
diff changeset
73 - **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;** (ampersand) represents the matched find pattern.
7068d1548234 Uploaded
bgruening
parents:
diff changeset
74 - **\\1** The text which matched the first parenthesis in the Find Pattern.
7068d1548234 Uploaded
bgruening
parents:
diff changeset
75
7068d1548234 Uploaded
bgruening
parents:
diff changeset
76
7068d1548234 Uploaded
bgruening
parents:
diff changeset
77
7068d1548234 Uploaded
bgruening
parents:
diff changeset
78
7068d1548234 Uploaded
bgruening
parents:
diff changeset
79 -----
7068d1548234 Uploaded
bgruening
parents:
diff changeset
80
7068d1548234 Uploaded
bgruening
parents:
diff changeset
81 **Example 1**
7068d1548234 Uploaded
bgruening
parents:
diff changeset
82
7068d1548234 Uploaded
bgruening
parents:
diff changeset
83 **Find Pattern:** HELLO
7068d1548234 Uploaded
bgruening
parents:
diff changeset
84 **Replace Pattern:** WORLD
7068d1548234 Uploaded
bgruening
parents:
diff changeset
85
7068d1548234 Uploaded
bgruening
parents:
diff changeset
86 Every time the word HELLO is found, it will be replaced with the word WORLD. This operation affects only the selected column.
7068d1548234 Uploaded
bgruening
parents:
diff changeset
87
7068d1548234 Uploaded
bgruening
parents:
diff changeset
88 -----
7068d1548234 Uploaded
bgruening
parents:
diff changeset
89
7068d1548234 Uploaded
bgruening
parents:
diff changeset
90 **Example 2**
7068d1548234 Uploaded
bgruening
parents:
diff changeset
91
7068d1548234 Uploaded
bgruening
parents:
diff changeset
92 **Find Pattern:** ^(.{4})
7068d1548234 Uploaded
bgruening
parents:
diff changeset
93 **Replace Pattern:** &amp;\\t
7068d1548234 Uploaded
bgruening
parents:
diff changeset
94
7068d1548234 Uploaded
bgruening
parents:
diff changeset
95 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. This operation affects only the selected column.
7068d1548234 Uploaded
bgruening
parents:
diff changeset
96
7068d1548234 Uploaded
bgruening
parents:
diff changeset
97
7068d1548234 Uploaded
bgruening
parents:
diff changeset
98 -----
7068d1548234 Uploaded
bgruening
parents:
diff changeset
99
7068d1548234 Uploaded
bgruening
parents:
diff changeset
100 **Extened Regular Expression Syntax**
7068d1548234 Uploaded
bgruening
parents:
diff changeset
101
7068d1548234 Uploaded
bgruening
parents:
diff changeset
102 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.
7068d1548234 Uploaded
bgruening
parents:
diff changeset
103
7068d1548234 Uploaded
bgruening
parents:
diff changeset
104 - **( ) { } [ ] . * ? + \ ^ $** are all special characters. **\\** can be used to "escape" a special character, allowing that special character to be searched for.
7068d1548234 Uploaded
bgruening
parents:
diff changeset
105 - **^** matches the beginning of a string(but not an internal line).
7068d1548234 Uploaded
bgruening
parents:
diff changeset
106 - **(** .. **)** groups a particular pattern.
7068d1548234 Uploaded
bgruening
parents:
diff changeset
107 - **{** n or n, or n,m **}** specifies an expected number of repetitions of the preceding pattern.
7068d1548234 Uploaded
bgruening
parents:
diff changeset
108
7068d1548234 Uploaded
bgruening
parents:
diff changeset
109 - **{n}** The preceding item is matched exactly n times.
7068d1548234 Uploaded
bgruening
parents:
diff changeset
110 - **{n,}** The preceding item ismatched n or more times.
7068d1548234 Uploaded
bgruening
parents:
diff changeset
111 - **{n,m}** The preceding item is matched at least n times but not more than m times.
7068d1548234 Uploaded
bgruening
parents:
diff changeset
112
7068d1548234 Uploaded
bgruening
parents:
diff changeset
113 - **[** ... **]** 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**.
7068d1548234 Uploaded
bgruening
parents:
diff changeset
114 - **.** Matches any single character except a newline.
7068d1548234 Uploaded
bgruening
parents:
diff changeset
115 - ***** The preceding item will be matched zero or more times.
7068d1548234 Uploaded
bgruening
parents:
diff changeset
116 - **?** The preceding item is optional and matched at most once.
7068d1548234 Uploaded
bgruening
parents:
diff changeset
117 - **+** The preceding item will be matched one or more times.
7068d1548234 Uploaded
bgruening
parents:
diff changeset
118 - **^** has two meaning:
7068d1548234 Uploaded
bgruening
parents:
diff changeset
119 - matches the beginning of a line or string.
7068d1548234 Uploaded
bgruening
parents:
diff changeset
120 - indicates negation in a character class. For example, [^...] matches every character except the ones inside brackets.
7068d1548234 Uploaded
bgruening
parents:
diff changeset
121 - **$** matches the end of a line or string.
7068d1548234 Uploaded
bgruening
parents:
diff changeset
122 - **\|** Separates alternate possibilities.
7068d1548234 Uploaded
bgruening
parents:
diff changeset
123
7068d1548234 Uploaded
bgruening
parents:
diff changeset
124
7068d1548234 Uploaded
bgruening
parents:
diff changeset
125 **Note**: AWK uses extended regular expression syntax, not Perl syntax. **\\d**, **\\w**, **\\s** etc. are **not** supported.
7068d1548234 Uploaded
bgruening
parents:
diff changeset
126
7068d1548234 Uploaded
bgruening
parents:
diff changeset
127 </help>
7068d1548234 Uploaded
bgruening
parents:
diff changeset
128 </tool>