bam-to-bed
Quick Start
- Command:
bamToBed -i input.bam [options] > output.bed - Local executable:
/home/vimalinx/miniforge3/envs/bio/bin/bamToBed - Full reference: See
references/help.md
When To Use This Tool
- Convert alignments from BAM into BED6, BED12, or BEDPE for downstream interval analysis.
- Represent split or spliced alignments as separate blocks with
-split,-splitD, or-bed12. - Export paired-end geometry with
-bedpe. - Preserve extra alignment context such as edit distance or CIGAR when BED output alone is too lossy.
Common Patterns
# 1) Basic BAM to BED6
bamToBed \
-i alignments.bam > alignments.bed
# 2) BED12 output for split alignments
bamToBed \
-i alignments.bam \
-bed12 > alignments.bed12
# 3) BEDPE for paired-end reads
bamToBed \
-i alignments.qname.bam \
-bedpe > alignments.bedpe
Recommended Workflow
- Choose the target representation first: BED6 for simple intervals, BED12 for blocked alignments, or BEDPE for read pairs.
- Query-name sort or group the BAM before using
-bedpe. - Add
-split/-splitDwhen the CIGAR structure matters for exon-aware or gapped alignments. - Redirect stdout to a file and sanity-check coordinates and column count before feeding the result into downstream tools.
Guardrails
-bedperequires BAM records to be grouped or sorted by query.-bed12forces-split.-splitDalso forces-splitand breaks on bothNandDCIGAR operators.-tagmust reference a numeric BAM tag and cannot be combined with BEDPE output.- Default BED score is mapping quality;
-edchanges that semantics, especially for BEDPE where the mate edit distances are combined.