#! /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


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

echo "downloading samtools"
$WGET http://sourceforge.net/projects/samtools/files/samtools/0.1.18/samtools-0.1.18.tar.bz2
tar -jxf samtools-0.1.18.tar.bz2
cd samtools-0.1.18 && make && cd ..
cp samtools-0.1.18/samtools ./external/
cp samtools-0.1.18/misc/maq2sam-long ./external
rm -rf samtools-0.1.18 samtools-0.1.18.tar.bz2

echo "download BWA"
$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 ./external/
rm -rf  bwa-0.5.10 bwa-0.5.10.tar.bz2

echo "downloading SOAPdenovo"
$WGET http://soap.genomics.org.cn/down/x86_64.linux/SOAPdenovo31mer.tgz
tar -zxf SOAPdenovo31mer.tgz 

$WGET http://soap.genomics.org.cn/down/x86_64.linux/SOAPdenovo63mer.tgz
tar -zxf  SOAPdenovo63mer.tgz 

$WGET http://soap.genomics.org.cn/down/x86_64.linux/SOAPdenovo127mer.tgz
tar -zxf SOAPdenovo127mer.tgz 

mv SOAPdenovo*mer ./external
rm SOAPdenovo*mer.tgz

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