#! /bin/bash


if wget --version >/dev/null 2>&1; then
    eval "WGET='`which wget` -c --passive'" 
elif test -z `curl --version >/dev/null 2>&1`; then
    eval "WGET=`which curl` -L -O" 
else
    echo "You need at least wget or curl to fetch the packages." >&2
    exit 1
fi

cd ./external

echo "download picard"
$WGET http://sourceforge.net/projects/picard/files/picard-tools/1.89/picard-tools-1.89.zip 
unzip picard-tools-1.89.zip
mv picard-tools-1.89/* ./
rm -rf picard-tools-1.89 picard-tools-1.89.zip

echo "downloading samtools"
wget https://sourceforge.net/projects/samtools/files/samtools/1.3.1/samtools-1.3.1.tar.bz2
tar -jxf samtools-1.3.1.tar.bz2
cd samtools-1.3.1 && make && cd ..
cp samtools-1.3.1/samtools ./
cp samtools-1.3.1//misc/maq2sam-long ./
rm -rf samtools-1.3.1 samtools-1.3.1.tar.bz2


echo "download BWA"
$WGET https://sourceforge.net/projects/bio-bwa/files/bwa-0.7.15.tar.bz2
tar -jxf bwa-0.7.15.tar.bz2
cd bwa-0.7.15 && make && cd ..
cp bwa-0.7.15/bwa ./
rm -rf  bwa-0.7.15  bwa-0.7.15.tar.bz2


#$WGET http://sourceforge.net/projects/bio-bwa/files/bwa-0.5.10.tar.bz2
#tar -jxf bwa-0.5.10.tar.bz2
#cd bwa-0.5.10 && make && cd ..
#cp bwa-0.5.10/bwa ./
#rm -rf  bwa-0.5.10 bwa-0.5.10.tar.bz2

echo "downloading SOAPdenovo"
$WGET http://sourceforge.net/projects/soapdenovo2/files/SOAPdenovo2/bin/r240/SOAPdenovo2-bin-LINUX-generic-r240.tgz
tar -zxf SOAPdenovo2-bin-LINUX-generic-r240.tgz
mv SOAPdenovo*mer ./
rm SOAPdenovo2-bin-LINUX-generic-r240.tgz

echo "Please downloading stampy by yourself"
cd ./external/
$WGET http://www.well.ox.ac.uk/~gerton/software/Stampy/stampy-1.0.21r1715.tgz
tar -zxf stampy-1.0.21r1715.tgz
cd stampy-1.0.21 && make && cd ..
ln -s stampy-1.0.21/stampy.py .
rm stampy-1.0.21r1715.tgz


cd ..
echo "please download the error profile file for your genome from http://mus.well.ox.ac.uk/imrdenom/simbam/ by yourself" 

