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 (tissue)
RUN conda create -n tissue python=3.9
ENV PATH "$PATH:/opt/conda/envs/tissue/bin"
RUN echo "source activate tissue" >> ~/.bashrc
RUN conda clean --all -f -y

# Install packages
RUN apt-get -y update && apt-get install -y ca-certificates && update-ca-certificates
RUN /opt/conda/envs/tissue/bin/python3 -m pip install pandas numpy

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

# copy reference file
COPY HPA_normal_ihc_data.tsv .
COPY MANE_all_transcipts.csv .
