FROM ubuntu:22.04

LABEL maintainer="Mustafa Tekpinar <tekpinar@buffalo.edu>"
LABEL description="PRESCOTT: Population awaRe Epistatic and StruCtural mOdel of muTational effecTs"

ENV DEBIAN_FRONTEND=noninteractive

WORKDIR /home/tekpinar/research/lcqb
ENV JET2_PATH=/usr/local/JET2
ENV PRESCOTT_PATH=/home/tekpinar/research/lcqb/PRESCOTT
COPY ./JET2/ /usr/local/JET2
COPY ./naccess2.1.1 /usr/local/naccess2.1.1

COPY ./PRESCOTT/prescott/escott.py ./PRESCOTT/prescott/escott.py
COPY ./PRESCOTT/prescott/prescott.py ./PRESCOTT/prescott/prescott.py
COPY ./PRESCOTT/prescott/alphabets ./PRESCOTT/prescott/alphabets
COPY ./PRESCOTT/prescott/__init__.py ./PRESCOTT/prescott/__init__.py
COPY ./PRESCOTT/setup.py ./PRESCOTT/setup.py
COPY ./PRESCOTT/requirements.txt ./PRESCOTT/requirements.txt
COPY ./PRESCOTT/README.md ./PRESCOTT/README.md 
COPY ./PRESCOTT/prescott/pred.R ./PRESCOTT/prescott/pred.R
COPY ./PRESCOTT/prescott/computePred.R ./PRESCOTT/prescott/computePred.R
COPY ./PRESCOTT/prescott/default.conf ./PRESCOTT/prescott/default.conf
COPY ./PRESCOTT/data/ ./PRESCOTT/data/
COPY ./PRESCOTT/examples/ ./PRESCOTT/examples/
COPY ./demust/ ./demust/

###################################################################
RUN apt-get update --fix-missing && \
apt-get install -y --no-install-recommends apt-utils &&\
apt-get install -y software-properties-common && \
apt-get install -y autotools-dev && \
apt-get install -y automake && \
apt-get install -y build-essential && \
apt-get install -y python3-dev && \
apt-get install -y python3-pip && \
apt-get install -y r-base r-base-core && \
apt-get install -y muscle && \
apt-get install -y default-jre && \
apt-get install -y ncbi-blast+ && \
apt-get install -y nano && \
apt-get install -y less && \
apt-get install -y wget && \
apt-get install csh && \
apt-get install -y hmmer && \
apt-get install -y libboost-all-dev && \
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
###################################################################

#Install naccess2.1.1
WORKDIR /usr/local/naccess2.1.1
RUN csh install.scr

WORKDIR /home/tekpinar/research/lcqb

#Install dssp v.3 because v.4 has some incompatibilites with biotite.
RUN wget https://github.com/cmbi/dssp/archive/refs/heads/master.zip
RUN unzip -o master.zip 
WORKDIR /home/tekpinar/research/lcqb/dssp-master/
RUN ./autogen.sh
RUN ./configure 
RUN make
RUN make install
RUN ln -s /usr/local/bin/mkdssp /usr/local/bin/dssp
WORKDIR /home/tekpinar/research/lcqb
RUN rm -rf dssp-master/
RUN rm -f master.zip

RUN wget https://github.com/soedinglab/hh-suite/releases/download/v3.3.0/hhsuite-3.3.0-AVX2-Linux.tar.gz
RUN mkdir hhsuite
RUN mv hhsuite-3.3.0-AVX2-Linux.tar.gz hhsuite/

WORKDIR /home/tekpinar/research/lcqb/hhsuite
RUN tar xvfz hhsuite-3.3.0-AVX2-Linux.tar.gz
ENV PATH="/home/tekpinar/research/lcqb/hhsuite/bin:/home/tekpinar/research/lcqb/hhsuite/scripts:$PATH"
RUN rm -f hhsuite-3.3.0-AVX2-Linux.tar.gz

WORKDIR /home/tekpinar/research/lcqb
RUN sed -i s#/home/tekpinar/research/lcqb/JET2/matrix#/usr/local/JET2/matrix#g ./PRESCOTT/prescott/default.conf
RUN sed -i s#/home/tekpinar/research/lcqb/naccess2.1.1/naccess#/usr/local/naccess2.1.1/naccess#g ./PRESCOTT/prescott/default.conf
RUN pip3 install scikit-learn
RUN pip3 install ./PRESCOTT/
RUN pip3 install -e ./demust/

RUN Rscript -e 'install.packages("seqinr", repos="http://cran.us.r-project.org", dependencies=TRUE)'

#PLMC and EVcouplings installation for obtaining sequences.
RUN wget https://github.com/debbiemarkslab/plmc/archive/refs/heads/master.zip
RUN unzip -o master.zip

WORKDIR /home/tekpinar/research/lcqb/plmc-master
RUN pwd
RUN make all-openmp32
RUN cp bin/plmc /usr/local/bin/
WORKDIR /home/tekpinar/research/lcqb
RUN rm -rf master.zip plmc-master
RUN pip3 install https://github.com/debbiemarkslab/EVcouplings/archive/develop.zip

# If run command on M1 Mac with macOS Monterey, you can remove sudo
# Build command
# sudo docker build -t tekpinar/prescott-docker:v1.6.0 .
# sudo docker login
# sudo docker push tekpinar/prescott-docker:v1.6.0 

# Pull command on M1 Mac with macOS Monterey
# sudo docker pull tekpinar/prescott-docker:v1.6.0

# Run commands
# sudo docker run -i -t -v $(pwd) --platform linux/amd64 tekpinar/prescott-docker:v1.6.0 /bin/bash

# Bind your current folder to a particular folder in docker.
# In this way, you fall into the bash terminal of the docker image. 
# docker run -ti --rm --mount type=bind,source=$PWD,target=/home/tekpinar/research/lcqb tekpinar/prescott-docker:v1.6.0

#If you want to use the docker image like an executable file:
# Please note that you must have aliBLAT.fasta and blat-af2.pdb inside your current folder and run this command!
# sudo docker run --rm -v $PWD:/home/tekpinar/research/lcqb tekpinar/prescott-docker:v1.6.0 escott aliBLAT.fasta --pdbfile blat-af2.pdb

