annotate weeder2_wrapper.sh @ 1:571cb77ab9e7 draft

Add citation tag and README file.
author pjbriggs
date Tue, 09 Dec 2014 11:27:19 -0500
parents 496bc4eff47e
children 3c5f10f7dd40
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
1 #!/bin/sh -e
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
2 #
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
3 # Wrapper script to run weeder2 as a Galaxy tool
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
4 #
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
5 # Usage: weeder_wrapper.sh FASTA_IN SPECIES_CODE MOTIFS_OUT MATRIX_OUT [ ARGS... ]
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
6 #
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
7 # ARGS: one or more arguments to supply directly to weeder2
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
8 #
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
9 # Process command line
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
10 FASTA_IN=$1
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
11 SPECIES_CODE=$2
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
12 MOTIFS_OUT=$3
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
13 MATRIX_OUT=$4
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
14 #
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
15 # Other arguments
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
16 ARGS=""
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
17 while [ ! -z "$5" ] ; do
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
18 ARGS="$ARGS $5"
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
19 shift
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
20 done
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
21 #
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
22 # Link to input file
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
23 ln -s $FASTA_IN
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
24 #
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
25 # Link to the FreqFiles directory as weeder2 executable
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
26 # expects it to be the same directory
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
27 freqfiles_dir=$WEEDER_FREQFILES_DIR
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
28 if [ -d $freqfiles_dir ] ; then
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
29 echo "Linking to FreqFiles directory"
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
30 ln -s $freqfiles_dir FreqFiles
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
31 else
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
32 echo "ERROR FreqFiles directory not found" >&2
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
33 exit 1
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
34 fi
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
35 #
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
36 # Construct names of input and output files
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
37 fasta=`basename $FASTA_IN`
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
38 motifs_out=$fasta.w2
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
39 matrix_out=$fasta.matrix.w2
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
40 #
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
41 # Construct and run weeder command
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
42 # NB weeder logs output to stderr so redirect to stdout
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
43 # to prevent the Galaxy tool reporting failure
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
44 weeder_cmd="weeder2 -f $fasta -O $SPECIES_CODE $ARGS"
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
45 echo "Running $weeder_cmd"
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
46 $weeder_cmd 2>&1
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
47 status=$?
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
48 if [ $status -ne 0 ] ; then
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
49 echo weeder2 command finished with nonzero exit code $status >&2
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
50 echo Command was: $weeder_cmd
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
51 exit $status
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
52 fi
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
53 #
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
54 # Move outputs to final destinations
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
55 if [ -e $motifs_out ] ; then
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
56 /bin/mv $motifs_out $MOTIFS_OUT
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
57 fi
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
58 if [ -e $matrix_out ] ; then
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
59 /bin/mv $matrix_out $MATRIX_OUT
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
60 fi
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
61 #
496bc4eff47e Initial version.
pjbriggs
parents:
diff changeset
62 # Done