FROM ramonamela/guidancebase:latest

#Install qctool
RUN wget http://www.well.ox.ac.uk/~gav/resources/archive/qctool_v1.4-linux-x86_64.tgz && \
    tar zxvf qctool_v1.4-linux-x86_64.tgz && \
    rm qctool_v1.4-linux-x86_64.tgz && \
    chmod -R 755 /TOOLS/qctool_v1.4-linux-x86_64/ && \
    ln -s /TOOLS/qctool_v1.4-linux-x86_64/qctool /usr/bin/qctool1.4

#bcftools and samtools dependencies
RUN sudo apt-get update && \
    sudo apt-get install -y --no-install-recommends zlib1g-dev libbz2-dev liblzma-dev libncurses5-dev libncursesw5-dev && \
    rm -rf /var/lib/apt/lists/*

#Install bcftools
RUN wget https://github.com/samtools/bcftools/releases/download/1.8/bcftools-1.8.tar.bz2 -O bcftools.tar.bz2 && \
    tar -xjvf bcftools.tar.bz2 && \
    rm bcftools.tar.bz2 && \
    cd bcftools-1.8 && \
    make && \
    make prefix=/usr/local/ install && \
    ln -s /usr/local/bin/bcftools /usr/bin/bcftools

#Install samtools
RUN wget https://github.com/samtools/samtools/releases/download/1.5/samtools-1.5.tar.bz2 -O samtools.tar.bz2 && \
    tar -xjvf samtools.tar.bz2 && \
    rm samtools.tar.bz2 && \
    cd samtools-1.5 && \
    make && \
    make prefix=/usr/local/ install && \
    ln -s /usr/local/bin/samtools /usr/bin/samtools

#Install htslib
RUN wget https://github.com/samtools/htslib/releases/download/1.9/htslib-1.9.tar.bz2 -O htslib-1.9.tar.bz2 && \
    tar -xjvf htslib-1.9.tar.bz2 && \
    rm htslib-1.9.tar.bz2 && \
    cd htslib-1.9 && \
    make && \
    make prefix=//usr/local/ install && \
    ln -s /usr/local/bin/bgzip /usr/bin/bgzip && \
    ln -s /usr/local/bin/tabix /usr/bin/tabix

#Plink dependencies
RUN sudo add-apt-repository universe && \
    sudo apt-get update && \
    sudo apt-get install -y --no-install-recommends libatlas-base-dev libblas-dev liblapack-dev libatlas-base-dev && \
    rm -rf /var/lib/apt/lists/*

#Install plink
RUN git clone https://github.com/chrchang/plink-ng.git && \
    cd plink-ng && \
    rm -r 2.0 && \
    cd 1.9 && \
    ./plink_first_compile && \
    ln -s /TOOLS/plink-ng/1.9/plink /usr/bin/plink

#Install Eagle
#RUN wget https://data.broadinstitute.org/alkesgroup/Eagle/downloads/old/Eagle_v2.3.tar.gz && \
#    tar -zxvf Eagle_v2.3.tar.gz && \
#    rm Eagle_v2.3.tar.gz && \
#    rm -r Eagle_v2.3/example/ && \
#    ln -s /TOOLS/Eagle_v2.3/eagle /usr/bin/eagle
RUN wget https://data.broadinstitute.org/alkesgroup/Eagle/downloads/old/Eagle_v2.4.tar.gz && \
    tar -zxvf Eagle_v2.4.tar.gz && \
    rm -r Eagle_v2.4/example/ && \
    rm Eagle_v2.4.tar.gz && \
    ln -s /TOOLS/Eagle_v2.4/eagle /usr/bin/eagle

#Install Impute ### This step will stop working once they upgrade the program since only the last version is available
RUN wget https://mathgen.stats.ox.ac.uk/impute/impute_v2.3.2_x86_64_static.tgz && \
    tar -zxvf impute_v2.3.2_x86_64_static.tgz && \
    rm impute_v2.3.2_x86_64_static.tgz && \
    rm -r impute_v2.3.2_x86_64_static/Example/ && \
    ln -s /TOOLS/impute_v2.3.2_x86_64_static/impute2 /usr/bin/impute2

#Install snptest
RUN wget http://www.well.ox.ac.uk/~gav/resources/archive/snptest_v2.5_linux_x86_64_static.tgz && \
    tar -zxvf snptest_v2.5_linux_x86_64_static.tgz && \
    rm snptest_v2.5_linux_x86_64_static.tgz && \
    rm -r snptest_v2.5_linux_x86_64_static/example/ && \
    chmod -R 755 /TOOLS/snptest_v2.5_linux_x86_64_static/ && \
    ln -s /TOOLS/snptest_v2.5_linux_x86_64_static/snptest_v2.5 /usr/bin/snptest_v2.5

RUN wget https://mathgen.stats.ox.ac.uk/genetics_software/shapeit/shapeit.v2.r904.glibcv2.12.linux.tar.gz && \
    tar -zxvf shapeit.v2.r904.glibcv2.12.linux.tar.gz && \
    rm shapeit.v2.r904.glibcv2.12.linux.tar.gz  && \
    rm -r shapeit.v2.904.2.6.32-696.18.7.el6.x86_64/example/ && \
    chmod -R 775 /TOOLS/shapeit.v2.904.2.6.32-696.18.7.el6.x86_64/ && \
    ln -s /TOOLS/shapeit.v2.904.2.6.32-696.18.7.el6.x86_64/bin/shapeit /usr/bin/shapeit

#RUN wget http://www.well.ox.ac.uk/~gav/resources/snptest_v2.5.2_linux_x86_64_static.tgz && \
#    tar -zxvf snptest_v2.5.2_linux_x86_64_static.tgz && \
#    rm snptest_v2.5.2_linux_x86_64_static.tgz && \
#    rm -r snptest_v2.5.2_linux_x86_64_static/example/ && \
#    chmod -R 755 /TOOLS/snptest_v2.5.2_linux_x86_64_static/ && \
#    ln -s /TOOLS/snptest_v2.5.2_linux_x86_64_static/snptest_v2.5.2 /usr/bin/snptest_v2.5.2

#Install minimac3
#RUN git clone https://github.com/Santy-8128/Minimac3.git && \
#    cd Minimac3 && \
#    make -w && \
#    sudo ln -s /TOOLS/Minimac3/bin/Minimac3 /usr/bin/minimac3
RUN wget ftp://share.sph.umich.edu/minimac3/Minimac3Executable.tar.gz && \
    tar -zxvf Minimac3Executable.tar.gz && \
    rm Minimac3Executable.tar.gz && \
    chmod -R 755 /TOOLS/Minimac3Executable/bin && \
    ln -s /TOOLS/Minimac3Executable/bin/Minimac3-omp

#Minimac4 dependencies
RUN sudo apt-get update && \
    sudo apt-get install -y --no-install-recommends cmake python-pip python-dev && \
    pip install cget 

#Install minimac4
RUN git clone https://github.com/Santy-8128/Minimac4.git && \
    cd Minimac4 && \
    bash install.sh && \
    ln -s /TOOLS/Minimac4/release-build/minimac4 /usr/bin/minimac4
#    sudo ln -s /TOOLS/Minimac3/bin/Minimac3-omp /usr/bin/minimac3
#    sudo ln -s /TOOLS/Minimac3/bin/Minimac3 /usr/bin/minimac3



ENV SHAPEITBINARY "/usr/bin/shapeit"
ENV PLINKBINARY "/usr/bin/plink"
ENV QCTOOLBINARY "/usr/bin/qctool1.4"
ENV EAGLEBINARY "/usr/bin/eagle"
ENV IMPUTE2BINARY "/usr/bin/impute2"
ENV QCTOOLBINARY "/usr/bin/qctool1.4"
ENV SNPTESTBINARY "/usr/bin/snptest_v2.5"
ENV MINIMAC3BINARY "/usr/bin/minimac3"
ENV MINIMAC4BINARY "/usr/bin/minimac4"
ENV TABIXBINARY "/usr/bin/tabix"
ENV BGZIPBINARY "/usr/bin/bgzip"


ENV BCFTOOLSBINARY "/usr/bin/bcftools"
ENV SAMTOOLSBINARY "/usr/bin/samtools"

RUN echo "SHAPEITBINARY=\"/usr/bin/shapeit\"" >> /etc/environment
RUN echo "PLINKBINARY=\"/usr/bin/plink\"" >> /etc/environment
RUN echo "QCTOOLBINARY=\"/usr/bin/qctool1.4\"" >> /etc/environment
RUN echo "EAGLEBINARY=\"/usr/bin/eagle\"" >> /etc/environment
RUN echo "IMPUTE2BINARY=\"/usr/bin/impute2\"" >> /etc/environment
RUN echo "QCTOOLBINARY=\"/usr/bin/qctool1.4\"" >> /etc/environment
RUN echo "SNPTESTBINARY=\"/usr/bin/snptest_v2.5\"" >> /etc/environment
RUN echo "MINIMAC3BINARY=\"/usr/bin/minimac3\"" >> /etc/environment
RUN echo "MINIMAC4BINARY=\"/usr/bin/minimac4\"" >> /etc/environment
RUN echo "TABIXBINARY=\"/usr/bin/tabix\"" >> /etc/environment
RUN echo "BGZIPBINARY=\"/usr/bin/bgzip\"" >> /etc/environment
RUN echo "BCFTOOLSBINARY=\"/usr/bin/bcftools\"" >> /etc/environment
RUN echo "SAMTOOLSBINARY=\"/usr/bin/samtools\"" >> /etc/environment

WORKDIR /guidance
