| 1 | #!/bin/sh |
|---|
| 2 | |
|---|
| 3 | ## |
|---|
| 4 | ## Galaxy wrapper for cut command. |
|---|
| 5 | ## |
|---|
| 6 | |
|---|
| 7 | ## |
|---|
| 8 | ## command line arguments: |
|---|
| 9 | ## complement flag (might be empty string) |
|---|
| 10 | ## what to cut (fields or characters) |
|---|
| 11 | ## cut list (e.g. 1,2,3,4) |
|---|
| 12 | ## input_file |
|---|
| 13 | ## output_file |
|---|
| 14 | |
|---|
| 15 | COMPLEMENT="$1" |
|---|
| 16 | CUTWHAT="$2" |
|---|
| 17 | CUTLIST="$3" |
|---|
| 18 | INPUT="$4" |
|---|
| 19 | OUTPUT="$5" |
|---|
| 20 | |
|---|
| 21 | if [ -z "$OUTPUT" ]; then |
|---|
| 22 | echo "This script should be run from inside galaxy!" >&2 |
|---|
| 23 | exit 1 |
|---|
| 24 | fi |
|---|
| 25 | |
|---|
| 26 | if [ ! -r "$INPUT" ]; then |
|---|
| 27 | echo "error: input file ($INPUT) not found!" >&2 |
|---|
| 28 | exit 1 |
|---|
| 29 | fi |
|---|
| 30 | |
|---|
| 31 | # Messages printed to STDOUT will be displayed in the "INFO" field in the galaxy dataset. |
|---|
| 32 | # This way the user can tell what was the command |
|---|
| 33 | if [ -z "$COMPLEMENT" ]; then |
|---|
| 34 | echo -n "Extracting " |
|---|
| 35 | else |
|---|
| 36 | echo "Deleting " |
|---|
| 37 | fi |
|---|
| 38 | |
|---|
| 39 | case $CUTWHAT in |
|---|
| 40 | -f) echo -n "field(s) " |
|---|
| 41 | ;; |
|---|
| 42 | |
|---|
| 43 | -c) echo -n "character(s) " |
|---|
| 44 | ;; |
|---|
| 45 | esac |
|---|
| 46 | |
|---|
| 47 | echo "$CUTLIST" |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | cut $COMPLEMENT $CUTWHAT $CUTLIST < $INPUT > $OUTPUT |
|---|
| 51 | |
|---|
| 52 | exit |
|---|