#################################################################
# Dockerfile
#
# Software:         Seurat script
# Software Version: v0.0.21
# Description:      Dockerized version of Seurat script
# Website:          https://satijalab.org/seurat/index.html
# Provides:         Seurat script
# Base Image:       satijalab/seurat:4.0.3
# Build Cmd:        docker build --no-cache --rm -t biowardrobe2/seurat:v0.0.21 -f seurat-Dockerfile .
# Pull Cmd:         docker pull biowardrobe2/seurat:v0.0.21
# Run Cmd:          docker run --rm -ti biowardrobe2/seurat:v0.0.21 /bin/bash
#################################################################
#
# v0.0.21
# - Updated run_seurat.R to optionally regress UMIs and/or Genes per cell
#
# v0.0.20
# - Updated run_seurat.R to generate select specific PCs
#
# v0.0.19
# - Updated run_seurat.R to generate PCA QC metrics plot
#
# v0.0.18
# - Updated run_seurat.R
#   * better debug logging
#   * export raw counts into UCSC genome browser
#   * added --memory parameter
# - Updated assign_cell_types.R
#   * support label transfer from the reference dataset --ref
#
# v0.0.17
# - Updated run_seurat.R and assign_cell_types.R script to show cells
#   with bigger radius and higher transparency
# - Use the latest UCSC Cell Browser
#
# v0.0.16
# - Added MiQC into run_seurat.R script
#
# v0.0.15
# - Added assign_cell_types.R script
#
# v0.0.14
# - Updated sc_diff_expr.R script to support pseudobulk differential
#   expression
#
# v0.0.13
# - Updated sc_diff_expr.R script to support pseudobulk differential
#   expression
#
# v0.0.12
# - Add --nosct parameter to use LogNormalize instead of SCTransform
#
# v0.0.11
# - Add --umetric, --umethod, and --ametric parameters for better
#   UMAP and clustering configuration
#
# v0.0.10
# - Critical bug fixes in sc_diff_expr.R
#
# v0.0.9
# - Added --exgenes param to sc_diff_expr.R
# - Bug fixes in run_seurat.R
#
# v0.0.8
# - Added sc_diff_expr.R script
#
# v0.0.7
# - Added --spread, --mindist, and --nneighbors to configure UMAP
#
# v0.0.6
# - Independent datasets filtering support
#
# v0.0.5
# - Support --features inputs to highlight genes of interest
#
# v0.0.4
# - Unified color theme of all produced plots. Refactored R script
# - Add --maxfeatures input to R script
# - Updated base image to use the latest 4.0.3 Seurat
# - make --cellcycle, --classifier and --species inputs optional
# - if --condition is not provided, use library_id as condition
#
# v0.0.3
# - added DESeq2 to be able to choose test type for gene marker
#   identification
# - Updated Seurat script to be able to prefilter input feature-
#   barcode matrices by cells. Add extra parameter --testuse to
#   set a different option for gene marker identification
#
# v0.0.2
# - added Garnett & Monocle for cell type prediction
#
#################################################################

### Base Image
FROM satijalab/seurat:4.0.3
LABEL maintainer="misha.kotliar@gmail.com"
ENV DEBIAN_FRONTEND noninteractive


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

WORKDIR /tmp

ENV R_MAX_VSIZE=200000000000
ENV CB_VERSION "1.1.1"

COPY ./scripts/sc_tools/run_seurat.R /usr/local/bin/run_seurat.R
COPY ./scripts/sc_tools/sc_diff_expr.R /usr/local/bin/sc_diff_expr.R
COPY ./scripts/sc_tools/assign_cell_types.R /usr/local/bin/assign_cell_types.R

### Installing dependencies
RUN apt-get update && \
    apt-get install libgcc-10-dev python3-dev python3-pip libxml2-dev libcurl4-openssl-dev libssl-dev pandoc libudunits2-dev libgdal-dev libcairo2-dev libharfbuzz-dev libfribidi-dev libbz2-dev -y && \
    pip3 install scipy && \
    pip3 install cellbrowser==${CB_VERSION} && \
    R -e 'install.packages("devtools", repo = "https://cloud.r-project.org/")' && \
    R -e 'install.packages("argparse", repo = "https://cloud.r-project.org/")' && \
    R -e 'install.packages("tidyverse", repo = "https://cloud.r-project.org/")' && \
    R -e 'install.packages("flexmix", repo = "https://cloud.r-project.org/")' && \
    R -e "BiocManager::install(c('BiocGenerics', 'DelayedArray', 'DelayedMatrixStats','limma', 'S4Vectors', 'SingleCellExperiment', 'SummarizedExperiment', 'batchelor', 'Matrix.utils', 'DESeq2', 'EnhancedVolcano', 'Rsamtools', 'rtracklayer'))" && \
    R -e "devtools::install_github('cole-trapnell-lab/leidenbase')" && \
    R -e "devtools::install_github('cole-trapnell-lab/monocle3')" && \
    R -e "BiocManager::install(c('org.Hs.eg.db', 'org.Mm.eg.db'))" && \
    R -e "devtools::install_github('cole-trapnell-lab/garnett', ref='monocle3')" && \
    R -e 'install.packages("Signac", repo = "https://cloud.r-project.org/")' && \
    R -e 'install.packages("bestNormalize", repo = "https://cloud.r-project.org/")' && \
    R -e "remotes::install_github('satijalab/seurat-wrappers')" && \
### Installing run_seurat.R, sc_diff_expr.R, and assign_cell_types.R scripts
    chmod +x /usr/local/bin/run_seurat.R && \
    chmod +x /usr/local/bin/sc_diff_expr.R && \
    chmod +x /usr/local/bin/assign_cell_types.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
