BAM to FASTA Conversion (samtools fasta)
samtools fasta is a command-line utility used to
extract nucleotide sequences from SAM, BAM, or CRAM alignment
files and convert them into FASTA format. FASTA is one of the
most widely used sequence formats in bioinformatics and is
suitable for sequence analysis, alignment, assembly, and
annotation workflows.
.sam)
.bam)
.cram)
.fasta or .fa)
# Convert BAM to FASTA
samtools fasta sample.bam > sample.fasta
# Convert SAM to FASTA
samtools fasta sample.sam > sample.fasta
# Convert CRAM to FASTA
samtools fasta sample.cram > sample.fasta
>Read_001
ATGCGTAGCTAGCTAGCTAGCTAGCTA
>Read_002
CGTACGTAGCTAGCTAGCGTAGCTAGC
Each FASTA record consists of a sequence identifier line
beginning with >, followed by the nucleotide
sequence.
Official Samtools Documentation: Samtools FASTA 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