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