#################################################################
# Dockerfile
#
# Software:         hopach
# Software Version: v0.0.10
# Description:      Hierarchical Ordered Partitioning and Collapsing Hybrid (HOPACH)
# Website:          https://www.bioconductor.org/packages/release/bioc/html/hopach.html
# Provides:         hopach 2.46.0
# Base Image:       r-base:3.6.0
# Build Cmd:        docker build --rm -t biowardrobe2/hopach:v0.0.10 -f hopach-Dockerfile .
# Pull Cmd:         docker pull biowardrobe2/hopach:v0.0.10
# Run Cmd:          docker run --rm -ti biowardrobe2/hopach:v0.0.10 /bin/bash
#################################################################
#
# v0.0.10
#   Bug fix in hopach_order.R script.
#   - doesn't fail if any of the input has ' or "
#
# v0.0.9
#   Update hopach_order.R script.
#   - supports optional filtering by gene name
#
# v0.0.8
#   Update hopach_order.R script.
#   - Exports cdt, gtr and atr files
#
# v0.0.7
#   Add packages
#   - ggplot2
#   - reshape2
#
# v0.0.6
#   Update hopach_order.R script.
#   - Support three clustering methods: row, column, both
#
# v0.0.5
#   Update hopach_order.R script.
#   - Bug fix
#   - Center and normalize input data before clustering
#   - Optionally reorder heatmap columns
#   
# v0.0.4
#   Update hopach_order.R script.
#   Optionally exports heatmap, distance matrix and cluster variability plots.
#
# v0.0.3
#   switch to r-base:3.6.0
#   install
#     BiocManager   1.30.4
#     hopach        2.44.0
#     argparse      latest
#     gplots        latest
#     RColorBrewer  latest
#     pheatmap      latest
#
# v0.0.2
#   Update hopach_order.R script.
#   Only those rows are discarded, where all the elements are less
#   than the value set by --min argument
#
#   Hopach version depends on Bioconductor version.
#   For biowardrobe2/scidap-addons:v0.0.6 Bioconductor 3.2 is used,
#   so there is no way to set version for Hopach other than 2.30.0
#
#   Argparse, FindPython and jsonlite are set to the specific
#   versions to garantee that they will work on R 3.2.3-4 inherited
#   from the base image.
#################################################################


### Base Image
FROM r-base:3.6.0
LABEL maintainer="misha.kotliar@gmail.com"
ENV DEBIAN_FRONTEND noninteractive

################## BEGIN INSTALLATION ######################

WORKDIR /tmp

ENV VERSION_BIOCMANAGER 1.30.10
ENV URL_BIOCMANAGER "https://cran.r-project.org/src/contrib/BiocManager_${VERSION_BIOCMANAGER}.tar.gz"

COPY ./scripts/install_from_source.R /tmp/install_from_source.R
COPY ./scripts/hopach_order.R /usr/local/bin/hopach_order.R

### Installing dependencies
RUN apt-get update && \
    apt-get install -y libgcc-8-dev python3-dev python3-pip libxml2-dev libcurl4-openssl-dev && \
    pip3 install argparse && \
### Installing biocmanager, argparse, gplots, RColorBrewer, hopach, 
    Rscript /tmp/install_from_source.R "${URL_BIOCMANAGER}" && \
    R -e 'install.packages("argparse", repo = "https://cloud.r-project.org/")' && \
    R -e 'install.packages("gplots", repo = "https://cloud.r-project.org/")' && \
    R -e 'install.packages("RColorBrewer", repo = "https://cloud.r-project.org/")' && \
    R -e 'install.packages("pheatmap", repo = "https://cloud.r-project.org/")' && \
    R -e 'install.packages("ggplot2", repo = "https://cloud.r-project.org/")' && \
    R -e 'install.packages("reshape2", repo = "https://cloud.r-project.org/")' && \
    R -e "BiocManager::install(c('hopach'))" && \
### Installing hopach_order.R script
    chmod +x /usr/local/bin/hopach_order.R && \
### Cleaning
    apt-get clean && \
    apt-get purge && \
    rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/* && \
    strip /usr/local/bin/*; true
