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

module load SAMtools/1.3.1-foss-2016b

cd /data/kramseylab/sam/2106_RNA-Seq_sam/

for f in *.sam;
do
    PREFIX1="${f%.sam}"

   samtools view -bT /data/kramseylab/NC_007880_short.fasta -o /data/kramseylab/bam/2106_RNA-Seq_bam/$PREFIX1.bam /data/kramseylab/sam/2106_RNA-Seq_sam/$PREFIX1.sam
   samtools sort -o /data/kramseylab/bam/2106_RNA-Seq_bam/$PREFIX1\-sorted.bam /data/kramseylab/bam/2106_RNA-Seq_bam/$PREFIX1.bam 
   samtools index /data/kramseylab/bam/2106_RNA-Seq_bam/$PREFIX1\-sorted.bam

rm /data/kramseylab/bam/2106_RNA-Seq_bam/$PREFIX1.bam

done


