#!/bin/bash
#SBATCH -t 6:00:00
#SBATCH --nodes=1 --ntasks-per-node=1
#SBATCH --export=NONE
#SBATCH --mail-user=kramsey@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
    echo $PREFIX
#for f in *-sorted.bam;
	 
#do
#    PREFIX="${f%-sorted.bam}"
    DIRPATH=data/kramseylab/bam/2106_RNA-Seq_bam  #Define the working directory
    echo $DIRPATH
    
#    bedtools genomecov -bg -du -split -strand - -trackline -trackopts 'name='$PREFIX'_plus color=0,0,255' -ibam $DIRPATH/$PREFIX\-sorted.bam -g /data/kramseylab/genomefiles/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\-sorted.bam -g /data/kramseylab/genomefiles/LVS_genomefile.txt > $DIRPATH/tracks/$PREFIX\_minus.bedGraph

shift
done

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