#!/bin/sh
#$ -N bamindex
#$ -cwd
#$ -l m_mem_free=10G
#$ -V
#$ -pe threads 4

IN=$(head -n $SGE_TASK_ID samplelist.sorted.txt | tail -n 1)

## Generate bai index file to view aligments in IGV and/or UCSC browser:
samtools sort -@ 4 v03_"$IN"_Aligned.out.bam > v03_"$IN"_Aligned.sorted.bam
samtools index -@ 4 -b v03_"$IN"_Aligned.sorted.bam	## automatically generates output file

## After run, removed unsorted bam to save space.
