changeset 0:224be21ac8c7

commit
author pitagora <yamanaka@genome.rcast.u-tokyo.ac.jp>
date Sun, 19 Oct 2014 15:04:49 +0900
parents
children 69fbeac761c2
files awk.xml awk_wrapper.sh
diffstat 2 files changed, 189 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/awk.xml	Sun Oct 19 15:04:49 2014 +0900
@@ -0,0 +1,141 @@
+<!--
+  This tool is based on 'cshl_awk_tool' from Hannon Lab CSHL
+  http://hannonlab.cshl.edu/galaxy_unix_tools/
+  Thanks. Pitagora
+-->
+<tool id="awk" name="awk">
+  <description></description>
+  <command interpreter="sh">awk_wrapper.sh $input $output '$file_data' '$FS' '$OFS'</command>
+  <inputs>
+    <param format="txt" name="input" type="data" label="File to process" />
+    <param name="FS" type="select" label="Input field-separator">
+	  <option value=",">comma (,)</option>
+	  <option value=":">colons (:) </option>
+	  <option value=" ">single space</option>
+	  <option value=".">dot (.)</option>
+	  <option value="-">dash (-)</option>
+	  <option value="|">pipe (|)</option>
+	  <option value="_">underscore (_)</option>
+	  <option selected="True" value="tab">tab</option>
+    </param>
+    <param name="OFS" type="select" label="Output field-separator">
+	  <option value=",">comma (,)</option>
+	  <option value=":">colons (:)</option>
+	  <option value=" ">space ( )</option>
+	  <option value="-">dash (-)</option>
+	  <option value=".">dot (.)</option>
+	  <option value="|">pipe (|)</option>
+	  <option value="_">underscore (_)</option>
+	  <option selected="True" value="tab">tab</option>
+    </param>
+    <param name="file_data" type="text" area="true" size="5x60" label="AWK Program" help=""> 
+      <sanitizer>
+        <valid initial="string.printable">
+          <remove value="&apos;"/>
+        </valid>
+        <mapping initial="none">
+          <add source="&apos;" target="__sq__"/>
+        </mapping>
+      </sanitizer>
+    </param>
+  </inputs>
+  <tests>
+	  <test>
+		  <param name="input" value="unix_awk_input1.txt" />
+		  <output name="output" file="unix_awk_output1.txt" />
+		  <param name="FS" value="tab" />
+		  <param name="OFS" value="tab" />
+		  <param name="file_data"  value="$2>0.5 { print $2*9, $1 }" />
+	  </test>
+  </tests>
+  <outputs>
+    <data format="input" name="output" metadata_source="input" />
+  </outputs>
+<help>
+
+**What it does**
+
+This tool runs the unix **awk** command on the selected data file.
+
+.. class:: infomark
+
+**TIP:** This tool uses the **extended regular** expression syntax (not the perl syntax).
+
+
+**Further reading**
+
+- Awk by Example (http://www.ibm.com/developerworks/linux/library/l-awk1.html)
+- Long AWK tutorial (http://www.grymoire.com/Unix/Awk.html)
+- Learn AWK in 1 hour (http://www.selectorweb.com/awk.html)
+- awk cheat-sheet (http://cbi.med.harvard.edu/people/peshkin/sb302/awk_cheatsheets.pdf)
+- Collection of useful awk one-liners (http://student.northpark.edu/pemente/awk/awk1line.txt)
+
+-----
+
+**AWK programs**
+
+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).
+
+The basic form of AWK program is::
+
+    pattern { action 1; action 2; action 3; }
+
+
+
+
+
+**Pattern Examples**
+
+- **$2 == "chr3"**  will match lines whose second column is the string 'chr3'
+- **$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.
+- **/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.)
+- **$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.)
+- **10000 &lt; $4 &amp;&amp; $4 &lt; 20000** will match lines whose fourth column value is larger than 10,000 but smaller than 20,000
+- If no pattern is specified, all lines match (meaning the **action** part will be executed on all lines).
+
+
+
+**Action Examples**
+
+- **{ 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'.
+- **{ print $1, $4, $5 }** will print only the first, fourth and fifth fields of the input line.
+- **{ 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).
+- If no action part is specified (not even the curly brackets) - the default action is to print the entire line.
+
+
+
+
+
+
+
+
+
+**AWK's Regular Expression Syntax**
+
+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. 
+
+- **( ) { } [ ] . * ? + \ ^ $** are all special characters. **\\** can be used to "escape" a special character, allowing that special character to be searched for.
+- **^** matches the beginning of a string(but not an internal line).
+- **(** .. **)** groups a particular pattern.
+- **{** n or n, or n,m **}** specifies an expected number of repetitions of the preceding pattern.
+
+  - **{n}** The preceding item is matched exactly n times.
+  - **{n,}** The preceding item ismatched n or more times. 
+  - **{n,m}** The preceding item is matched at least n times but not more than m times. 
+
+- **[** ... **]** 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**.
+- **.** Matches any single character except a newline.
+- ***** The preceding item will be matched zero or more times.
+- **?** The preceding item is optional and matched at most once.
+- **+** The preceding item will be matched one or more times.
+- **^** has two meaning:
+  - matches the beginning of a line or string. 
+  - indicates negation in a character class. For example, [^...] matches every character except the ones inside brackets.
+- **$** matches the end of a line or string.
+- **\|** Separates alternate possibilities. 
+
+
+**Note**: AWK uses extended regular expression syntax, not Perl syntax. **\\d**, **\\w**, **\\s** etc. are **not** supported.
+
+</help>
+</tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/awk_wrapper.sh	Sun Oct 19 15:04:49 2014 +0900
@@ -0,0 +1,48 @@
+#!/bin/sh
+
+##
+## Galaxy wrapper for AWK command
+##
+
+##
+## command line arguments:
+##   input_file
+##   output_file
+##   awk-program
+##   input-field-separator
+##   output-field-separator
+
+INPUT="$1"
+OUTPUT="$2"
+PROG="$3"
+FS="$4"
+OFS="$5"
+
+shift 5
+
+if [ -z "$OFS" ]; then
+	echo usage: $0 INPUTFILE OUTPUTFILE AWK-PROGRAM FS OFS>&2
+	exit 1
+fi
+
+if [ ! -r "$INPUT" ]; then
+	echo "error: input file ($INPUT) not found!" >&2
+	exit 1
+fi
+
+if [ "$FS" == "tab" ]; then
+	FS="\t"
+fi
+if [ "$OFS" == "tab" ]; then
+	OFS="\t"
+fi
+
+# Messages printed to STDOUT will be displayed in the "INFO" field in the galaxy dataset.
+# This way the user can tell what was the command
+echo "awk" "$PROG"
+
+#awk --sandbox -v OFS="$OFS" -v FS="$FS" --re-interval "$PROG" "$INPUT" > "$OUTPUT"
+awk -v OFS="$OFS" -v FS="$FS" --re-interval "$PROG" "$INPUT" > "$OUTPUT"
+if (( $? ));  then exit; fi
+
+exit 0