Entering edit mode
Depending on your chromosomes, something like:
for chrom in `seq 1 22` X Y
do
samtools view -bh $BAM chr${chrom} | samtools sort - chr${chrom}
samtools index chr${chrom}.bam
done
bamtools has a "split" command for exactly this purpose.
You can use this tool to do exactly that.
Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
do we need to sort bam everytime we split it...or are we doing it to be on the safe side? Thanks for your response.
if your input bam is sorted, then you don't need to resort.