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
|
1
|
28 # Don't explicitly set the location - Weeder2 from
|
|
29 # bioconda handles this automatically
|
|
30 freqfiles_dir=
|
0
|
31 else
|
|
32 # Alternative location
|
|
33 freqfiles_dir=$FREQFILES_DIR
|
|
34 fi
|
|
35 #
|
|
36 # Link to the FreqFiles directory as weeder2 executable
|
|
37 # expects it to be the same directory
|
1
|
38 if [ ! -z "$freqfiles_dir" ] ; then
|
|
39 if [ -d $freqfiles_dir ] ; then
|
|
40 echo "Linking to FreqFiles directory: $freqfiles_dir"
|
|
41 ln -s $freqfiles_dir FreqFiles
|
|
42 else
|
|
43 echo "ERROR FreqFiles directory not found" >&2
|
|
44 exit 1
|
|
45 fi
|
0
|
46 else
|
1
|
47 echo "WARNING FreqFiles directory not set" >&2
|
0
|
48 fi
|
|
49 #
|
|
50 # Construct names of input and output files
|
1
|
51 fasta=$(basename $FASTA_IN)
|
|
52 motifs_out=${fasta}.w2
|
|
53 matrix_out=${fasta}.matrix.w2
|
0
|
54 #
|
|
55 # Construct and run weeder command
|
|
56 # NB weeder logs output to stderr so redirect to stdout
|
|
57 # to prevent the Galaxy tool reporting failure
|
|
58 weeder_cmd="weeder2 -f $fasta -O $SPECIES_CODE $ARGS"
|
|
59 echo "Running $weeder_cmd"
|
|
60 $weeder_cmd 2>&1
|
|
61 status=$?
|
|
62 if [ $status -ne 0 ] ; then
|
|
63 echo weeder2 command finished with nonzero exit code $status >&2
|
|
64 echo Command was: $weeder_cmd
|
|
65 exit $status
|
|
66 fi
|
|
67 #
|
|
68 # Move outputs to final destinations
|
|
69 if [ -e $motifs_out ] ; then
|
|
70 /bin/mv $motifs_out $MOTIFS_OUT
|
1
|
71 else
|
|
72 echo ERROR missing output file: $motifs_out >&2
|
|
73 status=1
|
0
|
74 fi
|
|
75 if [ -e $matrix_out ] ; then
|
|
76 /bin/mv $matrix_out $MATRIX_OUT
|
1
|
77 else
|
|
78 echo ERROR missing output file: $matrix_out >&2
|
|
79 status=1
|
0
|
80 fi
|
|
81 #
|
|
82 # Done
|
1
|
83 exit $status
|