bam-to-fastq
Quick Start
- Command:
bamToFastq -i input.bam -fq reads.fq [options] - Local executable:
/home/vimalinx/miniforge3/envs/bio/bin/bamToFastq - Full reference: See
references/help.md
When To Use This Tool
- Recover FASTQ from BAM alignments for remapping, QC, or archival export.
- Split paired-end BAM into
R1andR2FASTQ files with-fqand-fq2. - Emit a single interleaved FASTQ stream by directing both mates to stdout.
- Reconstruct reads from mate tags with
-tagswhen the BAM carriesR2/Q2tags.
Common Patterns
# 1) Single-end BAM to FASTQ
bamToFastq \
-i reads.bam \
-fq reads.fq
# 2) Paired-end BAM to two FASTQ files
bamToFastq \
-i reads.qname.bam \
-fq reads_R1.fq \
-fq2 reads_R2.fq
# 3) Interleaved paired-end FASTQ
bamToFastq \
-i reads.qname.bam \
-fq /dev/stdout \
-fq2 /dev/stdout > reads.interleaved.fq
Recommended Workflow
- Decide whether the BAM is single-end, paired-end, or tag-based (
-tags) before selecting output mode. - For paired-end export, query-name sort or collate the BAM first so mates stay synchronized.
- Write to fresh FASTQ files and validate mate counts if the output will feed a new aligner.
- If you need more filtering and flag control, compare against
samtools fastqbefore standardizing the pipeline.
Guardrails
-iand-fqare required.- Paired-end export with
-fq2assumes the BAM is grouped or sorted by query name. -tagsis specialized behavior for BAMs that carry mate sequence / quality inR2andQ2; it is not a generic paired-end fix.- The interleaved
/dev/stdoutpattern is convenient but easy to misuse in shells and pipelines, so redirect carefully. - Prefer
-hfor help; the wrapper does not support clean GNU-style--help/--version.