upstream-extended/community/tools/text_processing/text_processing/awk.xml
1<tool id="tp_awk_tool" name="Text reformatting" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="@PROFILE@">
2 <description>with awk</description>
3 <macros>
4 <import>macros.xml</import>
5 </macros>
6 <expand macro="creator"/>
7 <requirements>
8 <requirement type="package" version="5.4.1">gawk</requirement>
9 </requirements>
10 <version_command>awk --version | head -n 1</version_command>
11 <command>
12<![CDATA[
13 env -i
14 \$(which awk)
15 --sandbox
16 -v FS=' '
17 -v OFS=' '
18 #for $i, $r in enumerate($variables, start=1)
19 -v VAR$i='$r.value'
20 #end for
21 --re-interval
22 -f '$awk_script'
23 '$infile'
24 > '$outfile'
25]]>
26 </command>
27 <configfiles>
28 <configfile name="awk_script">$code</configfile>
29 </configfiles>
30 <inputs>
31 <param name="infile" format="txt" type="data" label="File to process" />
32 <param name="code" type="text" area="true" size="5x35" label="AWK Program" help="">
33 <sanitizer>
34 <valid initial="string.printable">
35 <remove value="'"/>
36 </valid>
37 </sanitizer>
38 </param>
39 <repeat name="variables" min="0" default="0" title="Variables">
40 <param name="value" type="text" label="Value">
41 <validator type="regex">[a-zA-Z0-9 .]+</validator>
42 </param>
43 </repeat>
44 </inputs>
45 <outputs>
46 <data name="outfile" format_source="infile" metadata_source="infile"/>
47 </outputs>
48 <tests>
49 <test>
50 <param name="infile" value="awk1.txt"/>
51 <!-- commas are not allowed in a value field. Values with comma will be splitted -->
52 <param name="code" value='$2>0.5 { print $2*9"\t"$1 }' />
53 <output name="outfile" file="awk_results1.txt" />
54 </test>
55 <test>
56 <param name="infile" value="awk1.txt"/>
57 <!-- commas are not allowed in a value field. Values with comma will be splitted -->
58 <param name="code" value='$2>VAR2 { print VAR1"\t"$2*9"\t"$1 }' />
59 <repeat name="variables">
60 <param name="value" value="xyz"/>
61 </repeat>
62 <repeat name="variables">
63 <param name="value" value="0.1"/>
64 </repeat>
65 <output name="outfile">
66 <assert_contents>
67 <has_line_matching expression="^xyz.*" n="6"/>
68 </assert_contents>
69 </output>
70 </test>
71 </tests>
72 <help>
73<![CDATA[
74**What it does**
75
76This tool runs the unix **awk** command on the selected data file.
77
78.. class:: infomark
79
80**TIP:**
81
82This tool uses the **extended regular** expression syntax (not the perl syntax).
83**\\d**, **\\w**, **\\s** etc. are **not** supported.
84
85
86**Further reading**
87
88- Awk by Example (http://www.ibm.com/developerworks/linux/library/l-awk1/index.html)
89- Long AWK tutorial (http://www.grymoire.com/Unix/Awk.html)
90
91-----
92
93**AWK programs**
94
95Most AWK programs consist of **patterns** (i.e. rules that match lines of text) and **actions** (i.e. commands to execute when a pattern matches a line).
96
97The basic form of AWK program is::
98
99 pattern { action 1; action 2; action 3; }
100
101**Variables**
102
103In order to allow parametrization in workflows, the tool allows to specify values for variables that can be used in AWK program.
104that will be named **VAR1**, **VAR2**, ...
105
106
107**Pattern Examples**
108
109- **$2 == "chr3"** will match lines whose second column is the string 'chr3'
110- **$5-$4>23** will match lines that after subtracting the value of the fourth column from the value of the fifth column, gives value alrger than 23.
111- **/AG..AG/** will match lines that contain the regular expression **AG..AG** (meaning the characeters AG followed by any two characeters followed by AG). (This is the way to specify regular expressions on the entire line, similar to GREP.)
112- **$7 ~ /A{4}U/** will match lines whose seventh column contains 4 consecutive A's followed by a U. (This is the way to specify regular expressions on a specific field.)
113- **10000 < $4 && $4 < 20000** will match lines whose fourth column value is larger than 10,000 but smaller than 20,000
114- **BEGIN** will be executed once only, before the first input record is read.
115- If no pattern is specified, all lines match (meaning the **action** part will be executed on all lines).
116
117
118
119**Action Examples**
120
121- **{ print }** or **{ print $0 }** will print the entire input line (the line that matched in **pattern**). **$0** is a special marker meaning 'the entire line'.
122- **{ print $1, $4, $5 }** will print only the first, fourth and fifth fields of the input line.
123- **{ print $4, $5-$4 }** will print the fourth column and the difference between the fifth and fourth column. (If the fourth column was start-position in the input file, and the fifth column was end-position - the output file will contain the start-position, and the length).
124- **{ FS = "," }** can be used to change the field separator (delimeter) for parsing the input file.
125- If no action part is specified (not even the curly brackets) - the default action is to print the entire line.
126
127
128**AWK's Regular Expression Syntax**
129
130The 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.
131
132- **( ) { } [ ] . * ? + \ ^ $** are all special characters. **\\** can be used to "escape" a special character, allowing that special character to be searched for.
133- **^** matches the beginning of a string(but not an internal line).
134- **(** .. **)** groups a particular pattern.
135- **{** n or n, or n,m **}** specifies an expected number of repetitions of the preceding pattern.
136
137 - **{n}** The preceding item is matched exactly n times.
138 - **{n,}** The preceding item ismatched n or more times.
139 - **{n,m}** The preceding item is matched at least n times but not more than m times.
140
141- **[** ... **]** 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**.
142- **.** Matches any single character except a newline.
143- ***** The preceding item will be matched zero or more times.
144- **?** The preceding item is optional and matched at most once.
145- **+** The preceding item will be matched one or more times.
146- **^** has two meaning:
147 - matches the beginning of a line or string.
148 - indicates negation in a character class. For example, [^...] matches every character except the ones inside brackets.
149- **$** matches the end of a line or string.
150- **\|** Separates alternate possibilities.
151
152]]>
153 </help>
154 <expand macro="citations" />
155</tool>