Tuesday, July 1, 2014

bash script to sort and index all the bam files in folder

for sample in *.sam
do
echo $sample
describer=$(echo ${sample} | sed ‘s/.sam//’)
echo $describer
# Convert file from SAM to BAM format
samtools view -b $sample > ${describer}.uns.bam
# Sort BAM file
samtools sort ${describer}.uns.bam ${describer}
# index the bam file
samtools index ${describer}.bam
# Remove intermediate files
rm ${describer}.uns.bam
done

No comments:

Post a Comment