ARG CUDA=11.7
FROM nvidia/cuda:${CUDA}.1-cudnn8-devel-ubuntu22.04

USER root
SHELL ["/bin/bash", "-c"]

WORKDIR /home
RUN mkdir -p /home/omic
WORKDIR /home/omic

ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update -y && apt-get install -y --no-install-recommends \
    build-essential \
    cmake \
    curl \
    git \
    wget \
    ca-certificates \
    hmmer \
    kalign \
    tzdata \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

# Add the NVIDIA GPG key directly
RUN wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.0-1_all.deb
RUN dpkg -i cuda-keyring_1.0-1_all.deb && rm cuda-keyring_1.0-1_all.deb
RUN apt-get -y update && \
    apt-get install -y --no-install-recommends cuda-command-line-tools-11-7

RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh \
    && bash miniconda.sh -b -p /opt/conda \
    && rm miniconda.sh \
    && ln -s /opt/conda/etc/profile.d/conda.sh /etc/profile.d/conda.sh \
    && echo ". /opt/conda/etc/profile.d/conda.sh" >> ~/.bashrc \
    && echo "conda activate base" >> ~/.bashrc \
    && find /opt/conda/ -follow -type f -name '*.a' -delete \
    && find /opt/conda/ -follow -type f -name '*.js.map' -delete \
    && /opt/conda/bin/conda clean -afy

ENV PATH /opt/conda/bin:$PATH
RUN conda update -y -n base -c defaults conda

# main conda env (conplex)
RUN conda create -n conplex-dti python=3.9
ENV PATH "$PATH:/opt/conda/envs/conplex-dti/bin"
RUN echo "source activate conplex-dti" >> ~/.bashrc
RUN conda clean --all -f -y

# main conda env (secse)
#RUN conda create --name secse -c conda-forge parallel tqdm biopandas openbabel chemprop xlrd=2 pandarallel python=3.9 perl=5.32
#RUN conda install -y -n secse -c conda-forge pandas=1.3.5
#RUN conda install -y -n secse -c conda-forge rdkit=2022.03.5
#RUN echo "conda activate secse" >> ~/.bashrc
#ENV PATH="$PATH:/opt/conda/envs/secse/bin"
#ARG PATH="$PATH:/opt/conda/envs/secse/bin"

RUN git clone https://github.com/samsledje/ConPLex.git
WORKDIR /home/omic/ConPLex

# Install conplex
RUN apt-get -y update && apt-get install -y ca-certificates && update-ca-certificates
RUN /opt/conda/envs/conplex-dti/bin/python3 -m pip install conplex-dti
RUN conplex-dti --help

# Package into python script for running in nextflow
COPY conplex.py /home/omic/ConPLex/conplex.py
RUN chmod +x /home/omic/ConPLex/conplex.py

# Install pretrained models
RUN mkdir -p /home/omic/ConPLex/models
RUN wget --no-check-certificate -O /home/omic/ConPLex/models/ConPLex_v1_BindingDB.pt https://cb.csail.mit.edu/cb/conplex/data/models/BindingDB_ExperimentalValidModel.pt

# Test
RUN conplex-dti predict --data-file /home/omic/ConPLex/tests/toy_predict.tsv --model-path /home/omic/ConPLex/models/ConPLex_v1_BindingDB.pt --outfile ./results.tsv

#copy protein reference trascipt fasta file
COPY ensemble_reference.fasta .
COPY MANE_referent_transcipt_reference.fasta .
COPY MANE_all_transcipts.csv .
COPY get_round_2.py .
RUN chmod +x /home/omic/ConPLex/get_round_2.py
#new model weights
COPY Run_best_model_epoch46.pt /home/omic/ConPLex/models/


# Fix predict.py not working on single protein-ligand complex
#COPY predict.py /home/omic/ConPLex/conplex_dti/cli/predict.py
#COPY predict.py /opt/conda/envs/conplex-dti/lib/python3.9/site-packages/conplex_dti/cli/predict.py
#RUN chmod +x /home/omic/ConPLex/conplex_dti/cli/predict.py
#RUN chmod +x /opt/conda/envs/conplex-dti/lib/python3.9/site-packages/conplex_dti/cli/predict.py

# Clone secse
#RUN git clone https://github.com/KeenThera/SECSE.git
#RUN mv /home/omic/ConPLex/SECSE/secse /home/omic/ConPLex/secse && rm -r /home/omic/ConPLex/SECSE && rm -r /home/omic/ConPLex/secse/scoring
#COPY secse/scoring /home/omic/ConPLex/secse/scoring
#COPY secse/grow_processes.py /home/omic/ConPLex/secse/scoring/grow_processes.py
#RUN chmod +x /home/omic/ConPLex/secse/grow_processes.py
#RUN chmod +x /home/omic/ConPLex/secse/scoring/ranking.py
#RUN chmod +x /home/omic/ConPLex/secse/growing/mutation/mutation.py

# Add missing boost
#RUN conda install -n secse -c conda-forge boost

# Install CREM for chemical growth
#RUN git clone https://github.com/DrrDom/crem.git
#RUN /opt/conda/envs/conplex-dti/bin/python3 -m pip install crem pandas numpy

#WORKDIR /home/omic/ConPLex
#RUN chmod -R +x /home/omic/ConPLex

#ENV PATH="$PATH:/opt/conda/envs/secse/bin:/home/omic/ConPLex/secse"
#ENV SECSE="/home/omic/ConPLex/secse"
#ENV PYTHONPATH="PYTHONPATH=/home/omic/ConPLex/secse:/home/omic/ConPLex:/home/omic/ConPLex/crem"
#ARG PYTHONPATH="PYTHONPATH=/home/omic/ConPLex/secse:/home/omic/ConPLex:/home/omic/ConPLex/crem"

# Package into python script for running in nextflow
#COPY conplex.py /home/omic/ConPLex/conplex.py
#RUN chmod +x /home/omic/ConPLex/conplex.py

#Mutation file
#RUN /opt/conda/envs/conplex-dti/bin/python3 -m pip install crem
#RUN wget https://www.dropbox.com/s/4r48ohopechsd59/replacements02_sa2.db.gz?dl=0
#RUN mv replacements02_sa2.db.gz?dl=0 replacements02_sa2.db.gz
#RUN gzip -d replacements02_sa2.db.gz
#COPY fragment_mutations.py /home/omic/ConPLex/fragment_mutations.py
#RUN chmod +x /home/omic/ConPLex/fragment_mutations.py
