FROM r-base:latest

WORKDIR /usr/src/app

# Install system dependencies
RUN apt-get update && apt-get install -y \
    git \
    libcurl4-gnutls-dev \
    libssl-dev \
    libxml2-dev \
    procps  # Adding procps for the 'ps' command

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

RUN conda install -y -n rpy2 -c anaconda pandas
RUN conda install -y -n rpy2 -c anaconda numpy

# Install R packages
RUN Rscript -e "install.packages('remotes', dependencies=TRUE)" \
    && Rscript -e "remotes::install_github('federicogiorgi/corto')" \
    && Rscript -e "install.packages('data.table', dependencies=TRUE)" \
    && Rscript -e "install.packages('BiocManager')" \
    && Rscript -e "BiocManager::install('DESeq2')"

# Test commands to validate installation
RUN Rscript -e "library(corto)"

# Clone the corto repository (optional, based on your needs)
RUN git clone https://github.com/federicogiorgi/corto.git

CMD ["/bin/bash"]
 
