0
|
1 #!/bin/sh -e
|
|
2 #
|
|
3 # Wrapper script to run weeder2 as a Galaxy tool
|
|
4 #
|
|
5 # Usage: weeder_wrapper.sh FASTA_IN SPECIES_CODE FREQFILES_DIR MOTIFS_OUT MATRIX_OUT [ ARGS... ]
|
|
6 #
|
|
7 # ARGS: one or more arguments to supply directly to weeder2
|
|
8 #
|
|
9 # Process command line
|
|
10 FASTA_IN=$1
|
|
11 SPECIES_CODE=$2
|
|
12 FREQFILES_DIR=$3
|
|
13 MOTIFS_OUT=$4
|
|
14 MATRIX_OUT=$5
|
|
15 #
|
|
16 # Other arguments
|
|
17 ARGS=""
|
|
18 while [ ! -z "$6" ] ; do
|
|
19 ARGS="$ARGS $6"
|
|
20 shift
|
|
21 done
|
|
22 #
|
|
23 # Link to input file
|
|
24 ln -s $FASTA_IN
|
|
25 #
|
|
26 # Locate the FreqFiles directory
|
|
27 if [ $FREQFILES_DIR == "." ] ; then
|
|
28 # Use the files in the Weeder2 distribution
|
|
29 freqfiles_dir=$WEEDER_FREQFILES_DIR
|
|
30 else
|
|
31 # Alternative location
|
|
32 freqfiles_dir=$FREQFILES_DIR
|
|
33 fi
|
|
34 #
|
|
35 # Link to the FreqFiles directory as weeder2 executable
|
|
36 # expects it to be the same directory
|
|
37 if [ -d $freqfiles_dir ] ; then
|
|
38 echo "Linking to FreqFiles directory: $freqfiles_dir"
|
|
39 ln -s $freqfiles_dir FreqFiles
|
|
40 else
|
|
41 echo "ERROR FreqFiles directory not found" >&2
|
|
42 exit 1
|
|
43 fi
|
|
44 #
|
|
45 # Construct names of input and output files
|
|
46 fasta=`basename $FASTA_IN`
|
|
47 motifs_out=$fasta.w2
|
|
48 matrix_out=$fasta.matrix.w2
|
|
49 #
|
|
50 # Construct and run weeder command
|
|
51 # NB weeder logs output to stderr so redirect to stdout
|
|
52 # to prevent the Galaxy tool reporting failure
|
|
53 weeder_cmd="weeder2 -f $fasta -O $SPECIES_CODE $ARGS"
|
|
54 echo "Running $weeder_cmd"
|
|
55 $weeder_cmd 2>&1
|
|
56 status=$?
|
|
57 if [ $status -ne 0 ] ; then
|
|
58 echo weeder2 command finished with nonzero exit code $status >&2
|
|
59 echo Command was: $weeder_cmd
|
|
60 exit $status
|
|
61 fi
|
|
62 #
|
|
63 # Move outputs to final destinations
|
|
64 if [ -e $motifs_out ] ; then
|
|
65 /bin/mv $motifs_out $MOTIFS_OUT
|
|
66 fi
|
|
67 if [ -e $matrix_out ] ; then
|
|
68 /bin/mv $matrix_out $MATRIX_OUT
|
|
69 fi
|
|
70 #
|
|
71 # Done
|