#!/bin/bash
#SBATCH -t 1:00:00
#SBATCH --nodes=1 --ntasks-per-node=1
#SBATCH --export=NONE
#SBATCH --mail-user=jamie_wandzilak@uri.edu
#SBATCH --mail-type=BEGIN,END,FAIL

#this script will convert bam alignment files into bedGraph format 

module load BEDTools/2.27.1-foss-2018b


while [ ! -z "$1" ]

do
    PREFIX=$1  #Set the first argument to the experiment name
    DIRPATH=/data/kramseylab/bam/rnaseq_LVS_bam  #Define the working directory

    bedtools genomecov -bg -du -split -strand - -trackline -trackopts 'name='$PREFIX'_plus color=0,0,255' -ibam $DIRPATH/$PREFIX\.bam -g LVS_genomefile.txt > $DIRPATH/tracks/$PREFIX\_plus.bedGraph
    bedtools genomecov -bg -du -split -strand + -trackline -trackopts 'name='$PREFIX'_minus color=255,0,0' -ibam $DIRPATH/$PREFIX\.bam -g LVS_genomefile.txt > $DIRPATH/tracks/$PREFIX\_minus.bedGraph

shift
done

#the strand options have been reversed to account for how the library was prepared 
