#!/bin/bash

#################################################################################################################
############# Next-Generation Sequencing Capture Assessment Tool (ngsCAT)
############# Developed by Genomics and Bioinformatics Platform of Andalusia, Seville, Spain
############# http://www.bioinfomgp.org/ngscat
############# This script downloads and installs ngsCAT and its dependecies for Fedora-based Linux distributions. It has been tested for Fedora 20
############# How to use (superuser mode): sudo -E ./setup_fedora.sh <targetAbsolutePath> , for example: sudo -E ./setup_fedora.sh /home/user/ngsCAT . Close session and log-in again so that ngsCAT is contained in PATH variable
#################################################################################################################


####### Miscellaneous
targetDirectory=$1 # Directory where ngsCAT and pysam will be downloaded and installed
# Create target directory if not exists
if [ ! -d "$targetDirectory" ]; then
	mkdir -p $targetDirectory
fi

# Update repositories
yum update

# If python is not installed, you can download RPM packages of python 7 from:
# 64 bits: http://mirror.uv.es/mirror/fedora/linux/releases/20/Everything/x86_64/os/Packages/p/python-2.7.5-9.fc20.x86_64.rpm
# rpm -ivh python-2.7.5-9.fc20.x86_64.rpm
# or
# 32 bits: http://mirror.uv.es/mirror/fedora/linux/releases/20/Everything/x86_64/os/Packages/p/python-2.7.5-9.fc20.i686.rpm
# rpm -ivh python-2.7.5-9.fc20.i686.rpm
# ngsCAT has been tested with python 2.6 and 2.7

###################
# Samtools
###################
# Some dependencies
yum install zlib-devel
# Install samtools
yum install samtools

################
# python-numpy and python-scipy
################
yum install numpy scipy

################
# python-xlwt
################
yum install python-xlwt

################
# python-matplotlib
################
yum install python-matplotlib
yum install python-matplotlib-qt4


################
# python-pysam
################
# Install dependencies for pysam
yum install gcc
# Get pysam
pysamVersion='pysam-0.7.5.tar.gz'
baseNamePysam='pysam-0.7.5'
newOutput=$targetDirectory'/'$pysamVersion
wget -O $newOutput https://pysam.googlecode.com/files/$pysamVersion

# Uncompress downloaded file
tar -xzvf $newOutput -C $targetDirectory'/'
rm $newOutput

# Install package
currentDir=$PWD
cd $targetDirectory'/'$baseNamePysam
python setup.py install
cd $currentDir

#####################
###### Download and install ngsCAT
#####################
currentVersionNGScat='ngscat.v0.1.tar.gz' # Will be changed for new releases
baseNameNGScat='ngscat.v0.1'
newOutput=$targetDirectory'/'$currentVersionNGScat
# Download ngsCAT from GBPA
wget -O $newOutput http://www.bioinfomgp.org/_media/ngscat/download/$currentVersionNGScat

# Uncompress downloaded file
tar -xzvf $newOutput -C $targetDirectory'/'
rm $newOutput
# Change permissions
chmod +x $targetDirectory'/'$baseNameNGScat'/ngscat.py'

################################
# Add ngsCAT to PATH
################################
echo 'PATH=${PATH}:'$targetDirectory'/'$baseNameNGScat'/'  >> ~/.bashrc
echo 'export PATH' >> ~/.bashrc

# ngsCAT can be run. Check some examples at http://www.bioinfomgp.org/ngscat
