1
|
1 #!/bin/sh
|
|
2
|
|
3 DIR="$( cd "$( dirname "$0" )" && pwd )"
|
|
4 source $DIR/rtg-galaxy.cfg
|
|
5
|
|
6 # Temporary storage for STDERR
|
|
7 # Temporary storage for mapping output
|
|
8 TMP_STDERR=$(mktemp) || exit 1
|
|
9
|
|
10 #echo "$(date) START $@" >>~/galaxy-rtg-wrapper.log
|
|
11
|
|
12 paired=$1
|
|
13 shift
|
|
14 outputfile=$1
|
|
15 shift
|
|
16 if [ $paired == "paired" ]; then
|
|
17 outputfile2=$1
|
|
18 fi
|
|
19 shift
|
|
20 outputdir=$1
|
|
21 shift
|
|
22
|
|
23 # Run the program, send STDERR to temporary file
|
|
24 tmpout=$outputdir/tmpout$$
|
|
25 $rtg "$@" -o $tmpout --legacy-cigars 2> $TMP_STDERR
|
|
26
|
|
27 #check program's exit code
|
|
28 if (( $? )); then
|
|
29 #echo "$(date) FAIL $@" >>~/galaxy-rtg-wrapper.log
|
|
30 #cat $TMP_STDERR >>~/galaxy-rtg-wrapper.log
|
|
31 #Program failed, send STDERR to real STDERR
|
|
32 cat $TMP_STDERR >&2
|
|
33 rm $TMP_STDERR
|
|
34 rm -rf $tmpout
|
|
35 exit 1
|
|
36 fi
|
|
37
|
|
38 if [ -f $tmpout/mated.sam.gz ]; then
|
|
39 mv $tmpout/mated.sam.gz $outputfile
|
|
40 [ "$outputfile2" ] && mv $tmpout/unmated.sam.gz $outputfile2
|
|
41 else
|
|
42 mv $tmpout/alignments.sam.gz $outputfile
|
|
43 fi
|
|
44
|
|
45 #echo "$(date) DONE $@" >>~/galaxy-rtg-wrapper.log
|
|
46
|
|
47 #Program succeeded, delete STDERR file
|
|
48 rm $TMP_STDERR
|
|
49 rm -rf $tmpout
|
|
50 exit 0
|