Mercurial > repos > pitagora > unix_tools
comparison awk.xml @ 0:224be21ac8c7
commit
| author | pitagora <yamanaka@genome.rcast.u-tokyo.ac.jp> |
|---|---|
| date | Sun, 19 Oct 2014 15:04:49 +0900 |
| parents | |
| children | 69fbeac761c2 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:224be21ac8c7 |
|---|---|
| 1 <!-- | |
| 2 This tool is based on 'cshl_awk_tool' from Hannon Lab CSHL | |
| 3 http://hannonlab.cshl.edu/galaxy_unix_tools/ | |
| 4 Thanks. Pitagora | |
| 5 --> | |
| 6 <tool id="awk" name="awk"> | |
| 7 <description></description> | |
| 8 <command interpreter="sh">awk_wrapper.sh $input $output '$file_data' '$FS' '$OFS'</command> | |
| 9 <inputs> | |
| 10 <param format="txt" name="input" type="data" label="File to process" /> | |
| 11 <param name="FS" type="select" label="Input field-separator"> | |
| 12 <option value=",">comma (,)</option> | |
| 13 <option value=":">colons (:) </option> | |
| 14 <option value=" ">single space</option> | |
| 15 <option value=".">dot (.)</option> | |
| 16 <option value="-">dash (-)</option> | |
| 17 <option value="|">pipe (|)</option> | |
| 18 <option value="_">underscore (_)</option> | |
| 19 <option selected="True" value="tab">tab</option> | |
| 20 </param> | |
| 21 <param name="OFS" type="select" label="Output field-separator"> | |
| 22 <option value=",">comma (,)</option> | |
| 23 <option value=":">colons (:)</option> | |
| 24 <option value=" ">space ( )</option> | |
| 25 <option value="-">dash (-)</option> | |
| 26 <option value=".">dot (.)</option> | |
| 27 <option value="|">pipe (|)</option> | |
| 28 <option value="_">underscore (_)</option> | |
| 29 <option selected="True" value="tab">tab</option> | |
| 30 </param> | |
| 31 <param name="file_data" type="text" area="true" size="5x60" label="AWK Program" help=""> | |
| 32 <sanitizer> | |
| 33 <valid initial="string.printable"> | |
| 34 <remove value="'"/> | |
| 35 </valid> | |
| 36 <mapping initial="none"> | |
| 37 <add source="'" target="__sq__"/> | |
| 38 </mapping> | |
| 39 </sanitizer> | |
| 40 </param> | |
| 41 </inputs> | |
| 42 <tests> | |
| 43 <test> | |
| 44 <param name="input" value="unix_awk_input1.txt" /> | |
| 45 <output name="output" file="unix_awk_output1.txt" /> | |
| 46 <param name="FS" value="tab" /> | |
| 47 <param name="OFS" value="tab" /> | |
| 48 <param name="file_data" value="$2>0.5 { print $2*9, $1 }" /> | |
| 49 </test> | |
| 50 </tests> | |
| 51 <outputs> | |
| 52 <data format="input" name="output" metadata_source="input" /> | |
| 53 </outputs> | |
| 54 <help> | |
| 55 | |
| 56 **What it does** | |
| 57 | |
| 58 This tool runs the unix **awk** command on the selected data file. | |
| 59 | |
| 60 .. class:: infomark | |
| 61 | |
| 62 **TIP:** This tool uses the **extended regular** expression syntax (not the perl syntax). | |
| 63 | |
| 64 | |
| 65 **Further reading** | |
| 66 | |
| 67 - Awk by Example (http://www.ibm.com/developerworks/linux/library/l-awk1.html) | |
| 68 - Long AWK tutorial (http://www.grymoire.com/Unix/Awk.html) | |
| 69 - Learn AWK in 1 hour (http://www.selectorweb.com/awk.html) | |
| 70 - awk cheat-sheet (http://cbi.med.harvard.edu/people/peshkin/sb302/awk_cheatsheets.pdf) | |
| 71 - Collection of useful awk one-liners (http://student.northpark.edu/pemente/awk/awk1line.txt) | |
| 72 | |
| 73 ----- | |
| 74 | |
| 75 **AWK programs** | |
| 76 | |
| 77 Most 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). | |
| 78 | |
| 79 The basic form of AWK program is:: | |
| 80 | |
| 81 pattern { action 1; action 2; action 3; } | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 **Pattern Examples** | |
| 88 | |
| 89 - **$2 == "chr3"** will match lines whose second column is the string 'chr3' | |
| 90 - **$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. | |
| 91 - **/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.) | |
| 92 - **$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.) | |
| 93 - **10000 < $4 && $4 < 20000** will match lines whose fourth column value is larger than 10,000 but smaller than 20,000 | |
| 94 - If no pattern is specified, all lines match (meaning the **action** part will be executed on all lines). | |
| 95 | |
| 96 | |
| 97 | |
| 98 **Action Examples** | |
| 99 | |
| 100 - **{ 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'. | |
| 101 - **{ print $1, $4, $5 }** will print only the first, fourth and fifth fields of the input line. | |
| 102 - **{ 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). | |
| 103 - If no action part is specified (not even the curly brackets) - the default action is to print the entire line. | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 **AWK's Regular Expression Syntax** | |
| 114 | |
| 115 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. | |
| 116 | |
| 117 - **( ) { } [ ] . * ? + \ ^ $** are all special characters. **\\** can be used to "escape" a special character, allowing that special character to be searched for. | |
| 118 - **^** matches the beginning of a string(but not an internal line). | |
| 119 - **(** .. **)** groups a particular pattern. | |
| 120 - **{** n or n, or n,m **}** specifies an expected number of repetitions of the preceding pattern. | |
| 121 | |
| 122 - **{n}** The preceding item is matched exactly n times. | |
| 123 - **{n,}** The preceding item ismatched n or more times. | |
| 124 - **{n,m}** The preceding item is matched at least n times but not more than m times. | |
| 125 | |
| 126 - **[** ... **]** 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**. | |
| 127 - **.** Matches any single character except a newline. | |
| 128 - ***** The preceding item will be matched zero or more times. | |
| 129 - **?** The preceding item is optional and matched at most once. | |
| 130 - **+** The preceding item will be matched one or more times. | |
| 131 - **^** has two meaning: | |
| 132 - matches the beginning of a line or string. | |
| 133 - indicates negation in a character class. For example, [^...] matches every character except the ones inside brackets. | |
| 134 - **$** matches the end of a line or string. | |
| 135 - **\|** Separates alternate possibilities. | |
| 136 | |
| 137 | |
| 138 **Note**: AWK uses extended regular expression syntax, not Perl syntax. **\\d**, **\\w**, **\\s** etc. are **not** supported. | |
| 139 | |
| 140 </help> | |
| 141 </tool> |
