SAM to BAM Conversion (samtools view)
samtools view is used to convert SAM
(Sequence Alignment/Map) files into BAM
(Binary Alignment/Map) format. BAM files are compressed,
binary versions of SAM files that require less storage space
and provide faster processing for downstream bioinformatics
analyses.
.sam)
.bam)
# Convert SAM to BAM
samtools view -b sample.sam > sample.bam
# Convert and retain header
samtools view -b -h sample.sam > sample.bam
# Count alignments in SAM file
samtools view -c sample.sam
Input:
sample.sam
Output:
sample.bam
The generated BAM file contains the same alignment information as the SAM file but in a compressed binary format.
Official Samtools Documentation: Samtools View Manual
Li, H., Handsaker, B., Wysoker, A., Fennell, T., Ruan, J., Homer, N., et al. (2009). The Sequence Alignment/Map (SAM) format and SAMtools. Bioinformatics, 25(16), 2078–2079. DOI: 10.1093/bioinformatics/btp352