#!/bin/bash

# get deps
sudo apt-get -qq update
sudo apt install -y -qq samtools tabix libjansson-dev automake libtool libncurses-dev libbz2-dev cmake libbison-dev bison libfl-dev flex raptor2-utils rasqal-utils rs libgoogle-perftools-dev pigz pv

# make sure we have dx
#wget https://wiki.dnanexus.com/images/files/dx-toolkit-v0.210.1-ubuntu-14.04-amd64.tar.gz
#tar vxzf dx-toolkit-v0.210.1-ubuntu-14.04-amd64.tar.gz
#echo 'source ~/dx-toolkit/environment' >>.bashrc
#source ~/dx-toolkit/environment

# get a cool jq version
wget https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64
sudo cp jq-linux64 /usr/local/bin/jq
sudo chmod +x /usr/local/bin/jq

# get the indexes
# yeast
dx cat ekg_vg_hacking:/SGRP2.tar | tar vx
# human pan
mkdir -p pan && cd pan && dx cat ekg_vg_hacking:/hs37d5.vg.index_l16St16e4k16Z6000X3.tar | tar vx && cd ~
# human ref
mkdir -p ref && cd ref && dx cat ekg_vg_hacking:/hs37d5.ref.vg.index_l16St16e4k16Z6000X3.tar | tar vx && cd ~
# human .fa and bwa indexes
dx cat ekg_vg_hacking:/hs37d5.tar | tar vx

# gcc fix
sudo rm -f /etc/apt/apt.conf.d/99dnanexus
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
sudo apt-get -qq update
sudo apt-get install -y -qq gcc-4.9 g++-4.9
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 100 --slave /usr/bin/g++ g++ /usr/bin/g++-4.9

# get vg
git clone --recursive https://github.com/vgteam/vg.git

# build vg
cd vg && source ./source_me.sh && make -j 32 static && sudo cp bin/vg /usr/local/bin/
sudo cp scripts/vg_sim_pos_compare.py /usr/local/bin/
cd ~

# get bwa
git clone https://github.com/lh3/bwa.git
cd bwa && make -j 32 && sudo cp bwa /usr/local/bin/
cd ~
