bootstrap: docker
From: ubuntu:22.04

%help
    This container provides portable & reproducible components for TSRchitect,
    including upstream components for read quality control and mapping.

%post
    export DEBIAN_FRONTEND=noninteractive
    apt -y update
    apt -y install build-essential
    apt -y install bc curl git tcsh unzip zip wget
    apt -y install automake cmake
    apt -y install cpanminus
    apt -y install cython3
    apt -y install openjdk-11-jdk ant
    apt -y install software-properties-common
    apt -y install zlib1g-dev libbz2-dev liblzma-dev
    apt -y install libcairo2-dev libpango1.0-dev
    apt -y install libcurl4-openssl-dev
    apt -y install libcurl4-gnutls-dev
    apt -y install libgd-dev
    apt -y install libgdal-dev
    apt -y install libgtextutils-dev
    apt -y install libncurses-dev
    apt -y install libpq-dev
    apt -y install libproj-dev
    apt -y install libsodium-dev
    apt -y install libssl-dev
    apt -y install libtool
    apt -y install libtbb-dev
    apt -y install libudunits2-dev
    apt -y install libxml2-dev
    apt -y install libbz2-dev
    apt -y install m4
    apt -y install parallel
    apt -y install python2-minimal python-is-python3
    apt -y install python3-minimal
    apt -y install python3-pip
    apt -y install openmpi-bin openmpi-common openssh-client openssh-server
    apt -y install libopenmpi-dev

    cd /opt
    mkdir bin

###
# Utilities
#
    apt -y install python3-numpy python3-scipy
    pip3 install --upgrade dinopy HTSeq

# genometools:
#
    echo 'Installing GENOMETOOLS from from http://genometools.org/ '
    cd /opt
    wget http://genometools.org/pub/genometools-1.6.2.tar.gz
    tar -xzf genometools-1.6.2.tar.gz
    cd genometools-1.6.2/
    make && make install
    cd ..

# fastq-multx:
#
    echo 'Installing fastx_multx from https://github.com/brwnj/fastq-multx.git '
    git clone https://github.com/brwnj/fastq-multx.git
    cd fastq-multx/
    make
    cp fastq-multx /usr/local/bin/
    cd ..

# fastx_toolkit:
#
    echo 'Installing fastx_toolkit from https://github.com/agordon/fastx_toolkit.git '
    git clone https://github.com/agordon/fastx_toolkit.git
    cd fastx_toolkit/
    sed -i -e "s/usage();$/usage();exit(1);/" src/fasta_formatter/fasta_formatter.cpp
   ./reconf
   ./configure
   make
   make install
   cd  ..

# SAMTOOLS:
#
    echo 'Installing htslib from http://www.htslib.org/ '
    git clone https://github.com/samtools/htslib.git
    cd htslib
    make && make install
    cd ..

    echo 'Installing samtools from http://www.htslib.org/ '
    git clone https://github.com/samtools/samtools.git
    cd samtools
    make && make install
    cd ..

# NGSUtils:
#
    echo 'Installing ngsutilsj from https://github.com/compgen-io/ngsutilsj.git '
    git clone https://github.com/compgen-io/ngsutilsj
    cd ngsutilsj
    ant jar
    ln -s /opt/ngsutilsj/dist/ngsutilsj /usr/local/bin/ngsutilsj
    cd ../..

# SRATOOLKIT:
#
    echo 'Installing SRATOOLKIT from https://www.ncbi.nlm.nih.gov/books/NBK158900/ '
    wget https://ftp-trace.ncbi.nlm.nih.gov/sra/sdk/3.0.1/sratoolkit.3.0.1-ubuntu64.tar.gz
    tar -xzf sratoolkit.3.0.1-ubuntu64.tar.gz


###
# Evaluation and trimming of reads:
#

# FASTQC:
#
    echo 'Installing FASTQC from https://www.bioinformatics.babraham.ac.uk/projects/fastqc/ '
    wget http://www.bioinformatics.babraham.ac.uk/projects/fastqc/fastqc_v0.11.9.zip
    unzip fastqc_v0.11.9.zip
    chmod a+x FastQC/fastqc

# TRIM_GALORE:
    echo 'Installing TRIM_GALORE from http://www.bioinformatics.babraham.ac.uk/projects/trim_galore/ '
    #### Prerequisites
    pip install --upgrade cutadapt
    ### Install
    wget --content-disposition https://github.com/FelixKrueger/TrimGalore/archive/0.6.6.zip
    unzip TrimGalore-0.6.6.zip
    cp TrimGalore-0.6.6/trim_galore /opt/bin


# TagDust:
#
    echo 'Installing TagDust from https://sourceforge.net/projects/tagdust/files/latest/download '
    mkdir TagDust
    cd TagDust 
    wget --content-disposition https://sourceforge.net/projects/tagdust/files/tagdust-2.33.tar.gz/download
    tar -xzf tagdust-2.33.tar.gz*
    \rm tagdust-2.33.tar.gz*
    cd tagdust-2.33/
    ./configure CFLAGS=-fcommon
    make
    make install
    cd ../..


# TRIMMOMATIC:
#
     wget http://www.usadellab.org/cms/uploads/supplementary/Trimmomatic/Trimmomatic-0.39.zip
     unzip Trimmomatic-0.39.zip
#    Use:	java -jar /opt/Trimmomatic-0.39/trimmomatic-0.39.jar


###
# Read mapping tools:
#

# BOWTIE:
    apt -y install bowtie

# BOWTIE2:
    apt -y install bowtie2

# BWA:
    echo 'Installing bwa from https://sourceforge.net/projects/bio-bwa/files/bwa-0.7.17.tar.bz2/download '
    wget --content-disposition https://sourceforge.net/projects/bio-bwa/files/bwa-0.7.17.tar.bz2/download
    tar -xjf bwa-0.7.17.tar.bz2
    cd bwa-0.7.17/
    sed -i -e "s/CFLAGS=		-g -Wall -Wno-unused-function -O2/CFLAGS=	-g -Wall -Wno-unused-function -O2 -fcommon/" Makefile
    make
    cp bwa /opt/bin/
    cd ../

# HISAT2:
    echo 'Installing hisat2 from https://github.com/DaehwanKimLab/hisat2 '
    wget https://github.com/DaehwanKimLab/hisat2/archive/refs/tags/v2.2.1.tar.gz
    tar -xzf v2.2.1.tar.gz
    cd hisat2-2.2.1
    make
    cd ../

# STAR:
    echo 'Installing STAR from https://github.com/alexdobin/STAR '
    git clone https://github.com/alexdobin/STAR.git
    cd STAR
    cd source
    make STAR
    cp STAR /opt/bin
    cd ../..


###
# Spliced alignment tools:
#
    echo 'Installing GeneSeqer spliced aligner from https://github.com/BrendelGroup/GeneSeqer '
    git clone https://github.com/BrendelGroup/GeneSeqer.git
    cd GeneSeqer/src
    make linux
    make clean
    cp makefile.lnxMPI makefile.lnxMPIorig
    sed -e "s/^#MPICC/MPICC/" makefile.lnxMPI | sed -e "0,/^MPICC/s/^MPICC/#MPICC/" > makefile.lnxMPIu
    make -f makefile.lnxMPIu
    make clean
    make install
    cd ../..


###
# Motif identification:
#

# GHOSTSCRIPT:
#
    echo 'Installing ghostscript from https://ghostscript.readthedocs.io/en/gs10.0.0/ '
    wget https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs1000/ghostpcl-10.0.0-linux-x86_64.tgz
    tar -xzf ghostpcl-10.0.0-linux-x86_64.tgz
    cd ghostpcl-10.0.0-linux-x86_64
    chmod a+x gpcl6-1000-linux-x86_64
    cp gpcl6-1000-linux-x86_64 /opt/bin/gs
    cd ../

# MEME:
#
    echo 'Installing meme from https://meme-suite.org/meme/ '
    wget https://meme-suite.org/meme/meme-software/5.5.0/meme-5.5.0.tar.gz
    tar -xzf meme-5.5.0.tar.gz
    cd meme-5.5.0
    ./configure --prefix=/opt/meme \
	--enable-build-libxml2 --enable-build-libxslt --with-url="http://meme-suite.org"
    make
#    make test
    make install
    cd ../
    
# WEBLOGO:
#
    echo 'Installing weblogo from https://weblogo.berkeley.edu/ '
    wget https://weblogo.berkeley.edu/release/weblogo.2.8.2.tar.gz
    tar -xzf weblogo.2.8.2.tar.gz 

# HOMER:
    echo 'Installing home from http://homer.salk.edu/homer/ '
    mkdir HOMER; cd HOMER
    wget http://homer.salk.edu/homer/configureHomer.pl
    cpanm HTML::Template
    cpanm JSON
    cpanm XML::Simple
    cpanm XML::Compile::SOAP11
    cpanm XML::Compile::WSDL11
    cpanm XML::Compile::Transport::SOAPHTTP
    cpanm Log::Log4perl
    cpanm Math::CDF
    pip install --upgrade networkx
    perl configureHomer.pl -install homer
    chmod -R a+w data
    cd ../


###
# R and R packages, including TSRchitect
#
    apt -y update -qq
    apt install --no-install-recommends software-properties-common dirmngr
    wget -qO- https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | tee -a /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc
    add-apt-repository "deb https://cloud.r-project.org/bin/linux/ubuntu $(lsb_release -cs)-cran40/"
    apt -y install --no-install-recommends  r-base-core r-base-dev
    R CMD javareconf

    echo 'Installing CRAN packages'
    ######
    apt -y install r-cran-biocmanager
    apt -y install r-bioc-annotationhub
    apt -y install r-bioc-biocgenerics
    apt -y install r-bioc-genomicranges
    apt -y install r-bioc-biocversion
    apt -y install r-cran-dplyr
    apt -y install r-cran-gplots
    apt -y install r-cran-gridextra
    apt -y install r-cran-sqldf
    apt -y install r-cran-rcurl
    apt -y install r-cran-readxl
    apt -y install r-cran-statmod
    apt -y install r-cran-xml2

    echo 'Installing other CRAN and Bioconductor packages'
    ######
    echo 'install.packages(c("pastecs", "venneuler"), repos="http://ftp.ussg.iu.edu/CRAN", dependencies=TRUE)' > R2install
    echo 'BiocManager::install(version = "3.16", ask=FALSE)'                                                  >> R2install
    echo 'BiocManager::install(c("genomation","TSRchitect"), ask=FALSE)'                                      >> R2install
    echo 'BiocManager::install(c("bumphunter","seqLogo","ENCODExplorerData"), ask=FALSE)'                     >> R2install
    echo 'BiocManager::install(c("edgeR","R2HTML"), ask=FALSE)'                                               >> R2install

    Rscript R2install
    
    
# Install the last working version of ENCODExplorer (no 3.16 version is currently available):
#
    wget https://bioconductor.org/packages/3.12/bioc/src/contrib/ENCODExplorer_2.16.0.tar.gz
    tar -xzf ENCODExplorer_2.16.0.tar.gz
    R CMD INSTALL ENCODExplorer

# Use the git repository for installation of a TSRchitect version not yet in Bioconductor:
#
    git clone https://github.com/vpbrendel/TSRchitect.git
    R CMD INSTALL TSRchitect


%environment
    export LC_ALL=C
    export PATH=$PATH:/opt/bin
    export PATH=$PATH:/opt/FastQC
    export PATH=$PATH:/opt/hisat2-2.2.1
    export PATH=$PATH:/opt/HOMER/bin
    export PATH=$PATH:/opt/meme/bin
    export PATH=$PATH:/opt/sratoolkit.3.0.1-ubuntu64/bin

    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/:/usr/lib64/openmpi/lib

%labels
    Maintainer vpbrendel
    Version v1.1
