BootStrap: docker
From: ubuntu:latest

%labels
	Author:Qi Yu (dryuqi@gmail.com), modified by Luc Cornet
%files
        # Downloading GeneMark-ES first, GeneMark requires license key for downloading.
        gmes_linux_64 /opt
        braker_companion.py /opt/

%post
	export DEBIAN_FRONTEND="noninteractive" 
	apt-get update
	apt-get -y install perl git python3-pip cpanminus wget build-essential 
        apt install software-properties-common -y
        pip3 install click
        pip3 install glob2

	cpanm File::Spec::Functions Hash::Merge List::Util Logger::Simple Module::Load::Conditional Parallel::ForkManager POSIX Scalar::Util::Numeric YAML Math::Utils MCE::Mutex threads File::HomeDir

	# Install dependence
	mkdir -p /opt
	cd /opt

        #hisat2
        apt install hisat2 -y
	
	# Install bamtools using apt to avoid path setting in Augustus  
	apt-get -y install bamtools

	# Install ncbi-blast
	apt-get -y install ncbi-blast+
	
	# Install diamond
	wget http://github.com/bbuchfink/diamond/releases/download/v0.9.24/diamond-linux64.tar.gz
	tar xzf diamond-linux64.tar.gz
	cp diamond /usr/local/bin/

	# Install ProtHint
	git clone https://github.com/gatech-genemark/ProtHint
	
	# Install htslib
	apt-get -y install zlib1g-dev libcurl4-openssl-dev liblzma-dev lzma-dev libbz2-dev libssl-dev autoconf 
	git clone https://github.com/samtools/htslib.git
	cd htslib
	git submodule update --init --recursive
        autoheader
	autoconf
	./configure 
	make
	make install
	cd /opt

	# Install bcftools 
	git clone https://github.com/samtools/bcftools.git
	cd bcftools
	autoheader
	autoconf
	./configure
	make
	make install
	cd /opt
	
	# Install samtools
        apt-get -y install libncurses5-dev
        git clone https://github.com/samtools/samtools.git
        cd samtools
        autoheader
        autoconf -Wno-syntax
        ./configure
        make
        make install
        cd /opt

	# Install Augustus
	# Augustus
        apt-get -y install libboost-iostreams-dev zlib1g-dev libgsl-dev libsuitesparse-dev liblpsolve55-dev libsqlite3-dev libmysql++-dev libbamtools-dev libboost-all-dev
        git clone https://github.com/Gaius-Augustus/Augustus
	cd Augustus
	#define env for build
	export TOOLDIR=/opt
        make
	make install

	cd /opt
	# Install biopython
	pip3 install biopython

	# Install cdbfasta
	apt-get -y install cdbfasta

	# Install Exonerate
	apt-get -y install exonerate

	# Install GenomeThreader
	wget http://genomethreader.org/distributions/gth-1.7.3-Linux_x86_64-64bit.tar.gz
	tar -zxvf gth-1.7.3-Linux_x86_64-64bit.tar.gz

	# Install MakeHub
	wget https://github.com/Gaius-Augustus/MakeHub/archive/1.0.5.tar.gz
	tar -zxvf 1.0.5.tar.gz

	# Install BRAKER
	git clone https://github.com/Gaius-Augustus/BRAKER.git
	
	
	# make hpc specific links, you may change the setting according to your cluster
        mkdir -p /gpfs /data /lscratch
        for i in $(seq 1 12); do ln -s /gpfs/gsfs${i} /gs${i}; done
	
        #gm_key
        cd /opt/gmes_linux_64/
        cp gm_key .gm_key
        cp gm_key ~/.gm_key

        #sratoolkit
        cd /opt/
        wget https://ftp-trace.ncbi.nlm.nih.gov/sra/sdk/2.9.6/sratoolkit.2.9.6-ubuntu64.tar.gz
        tar -xvzf sratoolkit.2.9.6-ubuntu64.tar.gz
        mv sratoolkit.2.9.6-ubuntu64 sratoolkit

	# clean up
	apt-get clean
	rm /opt/*.tar.gz

%environment

	# setting env for braker
	export PATH=/opt/BRAKER/scripts:$PATH
	export LC_ALL=C
	export GENEMARK_PATH=/opt/gmes_linux_64/
	# BRAKER has to write to Augustus_config, so it is moved outside of a container.
	export AUGUSTUS_CONFIG_PATH=~/Augustus/config/
	export AUGUSTUS_BIN_PATH=/opt/Augustus/bin/
	export AUGUSTUS_SCRIPTS_PATH=/opt/Augustus/scripts/
        export PATH=/opt/augustus-3.4.0/bin:$PATH
	export PYTHON3_PATH=/usr/bin/
	export SAMTOOLS_PATH=/opt/samtools/
	export DIAMOND_PATH=/opt/
	export PROTHINT_PATH=/opt/ProtHint/bin/
	export MAKEHUB_PATH=/opt/MakeHub-1.0.5/
        export PATH=/opt/sratoolkit/bin:$PATH

	# setting env for gth
	export PATH=/opt/gth-1.7.3-Linux_x86_64-64bit/bin:$PATH
	export BSSMDIR=/opt/gth-1.7.3-Linux_x86_64-64bit/bin/bssm
	export GTHDATADIR=/opt/gth-1.7.3-Linux_x86_64-64bit//bin/gthdata
