#!/bin/sh
PATH=/mnt/data/home/herve.seitz/Natalia/src/cufflinks:"$PATH"
PATH=/mnt/data/home/herve.seitz/Natalia/src/tophat:"$PATH"
PATH=/mnt/data/home/herve.seitz/Natalia/src/bowtie2:"$PATH"
PATH=/mnt/data/home/herve.seitz/Natalia/src/bowtie:"$PATH"
PATH=/mnt/data/home/herve.seitz/Natalia/src/samtools:"$PATH"

# Usage: Wrapper_RNA-Seq.sh <fq> <library> <path_to_gene.gtf> <path_to_genome> <nb_procs> <output_name>
# $1: the fq files to analyze
# $2: library directory.
# $3: path to .gtf annotations file
# $4: path to genome.fa and genome.bt2 (genome and bowtie indexes) files
# $5: number of processors to use
# $6: name of annotations to put in the output directory
LIB=`basename ${2}`
FQ1=${1}
gtf_annotations_file=${3}
genome_index_path=${4}

PLACE=`pwd`
tophat_outdir="tophat_${6}_${LIB}_options_G"
tophat_log="logs/tophat_${6}_${LIB}.log"
cufflinks_outdir="cufflinks_${6}_${LIB}_options_G"
cufflinks_log="logs/cufflinks_${6}_${LIB}.log"
mkdir -p logs

echo ${PLACE} > ${tophat_log} 2>&1
date >> ${tophat_log} 2>&1
echo "tophat -p $5 -o ${tophat_outdir} -G ${gtf_annotations_file} ${genome_index_path}genome ${FQ1}" >> ${tophat_log} 2>&1
tophat -p $5 -o ${tophat_outdir} -G ${gtf_annotations_file} ${genome_index_path}genome ${FQ1} >> ${tophat_log} 2>&1
date >> ${tophat_log} 2>&1

echo ${PLACE} > ${cufflinks_log} 2>&1
date >> ${cufflinks_log} 2>&1
echo "cufflinks -p $5 --no-update-check -o ${cufflinks_outdir} -b ${genome_index_path}genome.fa -G ${gtf_annotations_file} ${tophat_outdir}/accepted_hits.bam" >> ${cufflinks_log} 2>&1
cufflinks -p $5 --no-update-check -o ${cufflinks_outdir} -b ${genome_index_path}genome.fa -G ${gtf_annotations_file} ${tophat_outdir}/accepted_hits.bam >> ${cufflinks_log} 2>&1
date >> ${cufflinks_log} 2>&1
