#!/bin/sh

check_for_presence() 
{
    if [ ! -s $1 ]
    then
        echo '    Download was unsuccesful.'
    fi 
}     

# Downloads libsvm
printf "\nDownloading SVM library\n"
curl -L -o 'libsvm.tar.gz' 'http://www.csie.ntu.edu.tw/~cjlin/cgi-bin/libsvm.cgi?+http://www.csie.ntu.edu.tw/~cjlin/libsvm+tar.gz' 
check_for_presence libsvm.tar.gz

# Downloads Glimmer
printf "\nDownloading Glimmer3\n"
curl -o 'glimmer.tar.gz' 'https://ccb.jhu.edu/software/glimmer/glimmer302b.tar.gz' 
check_for_presence glimmer.tar.gz 

# Downloads librf
printf "\nDownloading random forests library\n"
curl -o 'librf.tar.gz' 'http://librf.googlecode.com/files/librf.0.1.tar.gz' 
check_for_presence librf.tar.gz

# Downloads Kohonen's LVQ_PAK
printf "\nDownloading Kohonen's learning vector quantization package\n"
curl -o 'lvq_pak.tar' 'http://www.cis.hut.fi/research/lvq_pak/lvq_pak-3.1.tar' 
check_for_presence lvq_pak.tar

# Downloads Blast executables
os=`uname -a`
os=`echo $os | tr '[:upper:]' '[:lower:]'`
if [[ $os =~ linux ]] 
then 
    printf "\nDownloading 64-bit Blast 2.2.26 executables (for blastclust)\n"
    curl -o 'blast.tar.gz' 'ftp://ftp.ncbi.nlm.nih.gov/blast/executables/legacy.NOTSUPPORTED/2.2.26/blast-2.2.26-x64-linux.tar.gz' 
    check_for_presence blast.tar.gz
elif [[ $os =~ freebsd ]] 
then
    printf "\nDownloading 32-bit Blast 2.2.26 executables (for blastclust)\n"
    curl -o 'blast.tar.gz' 'ftp://ftp.ncbi.nlm.nih.gov/blast/executables/legacy.NOTSUPPORTED/2.2.26/blast-2.2.26-ia32-freebsd.tar.gz' 
    check_for_presence blast.tar.gz
elif [[ $os =~ sunos || $os =~ solaris ]] 
then
    printf "\nDownloading 64-bit Blast 2.2.26 exectutables (for blastclust)\n"
    if [[ $os =~ sparc ]]
    then
        curl -o 'blast.tar.gz' 'ftp://ftp.ncbi.nlm.nih.gov/blast/executables/legacy.NOTSUPPORTED/2.2.26/blast-2.2.26-sparc64-solaris.tar.gz'    
    else 
        curl -o 'blast.tar.gz' 'ftp://ftp.ncbi.nlm.nih.gov/blast/executables/legacy.NOTSUPPORTED/2.2.26/blast-2.2.26-x64-solaris.tar.gz'
    fi 
    check_for_presence blast.tar.gz
elif [[ $os =~ darwin ]] 
then 
    printf "\nDownloading Blast 2.2.26 executables (for blastclust)\n"
    curl -o 'blast.tar.gz' 'ftp://ftp.ncbi.nlm.nih.gov/blast/executables/legacy.NOTSUPPORTED/2.2.26/blast-2.2.26-universal-macosx.tar.gz' 
    check_for_presence blast.tar.gz
elif [[ $os =~ cygwin ]]
then
    printf "\nDownloading 64-bit Blast 2.2.26 executables (for blastclust)\n"
    curl -o 'blast.win64.exe' 'ftp://ftp.ncbi.nlm.nih.gov/blast/executables/legacy.NOTSUPPORTED/2.2.26/blast-2.2.26-x64-win64.exe' 
    check_for_presence blast.win64.exe
else
    printf 'Prebuilt blastclust binaries are probably unavailable for your system. If you want to build classifiers, and not just test repeats, check the NCBI homepage for blastclust sources.\n'
fi

