annotate tools/unix_tools/awk_wrapper.sh @ 0:9071e359b9a3

Uploaded
author xuebing
date Fri, 09 Mar 2012 19:37:19 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
1 #!/bin/sh
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
2
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
3 ##
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
4 ## Galaxy wrapper for AWK command
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
5 ##
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
6
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
7 ##
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
8 ## command line arguments:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
9 ## input_file
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
10 ## output_file
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
11 ## awk-program
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
12 ## input-field-separator
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
13 ## output-field-separator
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
14
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
15 INPUT="$1"
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
16 OUTPUT="$2"
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
17 PROG="$3"
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
18 FS="$4"
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
19 OFS="$5"
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
20
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
21 shift 5
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
22
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
23 if [ -z "$OFS" ]; then
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
24 echo usage: $0 INPUTFILE OUTPUTFILE AWK-PROGRAM FS OFS>&2
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
25 exit 1
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
26 fi
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
27
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
28 if [ ! -r "$INPUT" ]; then
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
29 echo "error: input file ($INPUT) not found!" >&2
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
30 exit 1
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
31 fi
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
32
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
33 if [ "$FS" == "tab" ]; then
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
34 FS="\t"
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
35 fi
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
36 if [ "$OFS" == "tab" ]; then
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
37 OFS="\t"
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
38 fi
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
39
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
40 # Messages printed to STDOUT will be displayed in the "INFO" field in the galaxy dataset.
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
41 # This way the user can tell what was the command
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
42 echo "awk" "$PROG"
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
43
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
44 awk --sandbox -v OFS="$OFS" -v FS="$FS" --re-interval "$PROG" "$INPUT" > "$OUTPUT"
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
45 if (( $? )); then exit; fi
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
46
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
47 exit 0