FROM debian:bullseye-slim

USER root

SHELL ["/bin/bash", "-c"]
WORKDIR /home
RUN mkdir -p /home/omic
WORKDIR /home/omic
ARG DEBIAN_FRONTEND=noninteractive

RUN apt update -y && apt-get install -y --no-install-recommends \
    build-essential \
    cmake \
    curl \
    git \
    wget \
    ca-certificates \
    default-jre \
    unzip \
  && apt-get clean \
  && rm -rf /var/lib/apt/lists/*

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

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

# Install RDKit
RUN conda install -y -n biotransformer -c conda-forge rdkit

WORKDIR /home/omic
# RUN wget https://bitbucket.org/wishartlab/biotransformer3.0jar/get/6432cf887ed7.zip && \
#     unzip 6432cf887ed7.zip && \
#     rm 6432cf887ed7.zip && \
#     mv wishartlab-biotransformer3.0jar-6432cf887ed7 biotransformer

# RUN git clone https://github.com/Wishartlab-openscience/Biotransformer.git && \
# mv Biotransformer biotransformer
RUN git clone https://bitbucket.org/wishartlab/biotransformer3.0jar biotransformer && mv biotransformer/BioTransformer3.0_20230525.jar biotransformer/biotransformer
WORKDIR /home/omic/biotransformer
# RUN wget https://bitbucket.org/wishartlab/biotransformer3.0jar/raw/6432cf887ed70c7c943c2dfeb60298ccdc788d7d/BioTransformer3.0_20230525.jar && \
#     mv BioTransformer3.0_20230525.jar biotransformer && \
#     chmod +x biotransformer
ENV PATH="$PATH:/home/omic/biotransformer"

# Create a symlink from /home/omic/biotransformer/database to /home/omic/biotransformer/btkb
RUN ln -s /home/omic/biotransformer/database /home/omic/biotransformer/btkb

## Test
# RUN java -jar biotransformer -multiThread "2 example.csv 36000 3 1 true"

#Download The Human Metabolome Database smiles
RUN wget https://hmdb.ca/system/downloads/current/structures.zip
RUN unzip structures.zip


#install pandas and requests
RUN conda install -y -n biotransformer -c conda-forge pandas requests
