Samtools: SAM-to-BAM

Accepted format: .sam

SAM to BAM Conversion (samtools view)

Function:

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.

Input Format:

  • SAM File (.sam)

Output Format:

  • BAM File (.bam)
  • Compressed binary alignment file suitable for indexing, sorting, and downstream analysis.

Example Usage:

# 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

Applications:

  • Reduce storage requirements for alignment files.
  • Prepare files for sorting and indexing.
  • Improve processing speed in NGS pipelines.
  • Enable visualization in genome browsers.
  • Facilitate downstream analyses such as variant calling.
  • Standardize alignment file formats.

Output Example:

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.

Tips:

  • Upload valid SAM files only.
  • Large files may require additional processing time.
  • Preview displays only a subset of records.
  • Download the full BAM file for downstream analysis.
  • Sorting and indexing are recommended after conversion.

Suggested Reading:

Official Samtools Documentation: Samtools View Manual

Citation:

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