bamtobed¶
bedtools bamtobed
is a conversion utility that converts sequence alignments
in BAM format into BED, BED12, and/or BEDPE records.
Usage and option summary¶
Usage:
bedtools bamtobed [OPTIONS] -i <BAM>
(or):
bamToBed [OPTIONS] -i <BAM>
Option |
Description |
---|---|
-bedpe |
Write BAM alignments in BEDPE format. Only one alignment from paired-end reads will be reported. Specifically, if each mate is aligned to the same chromosome, the BAM alignment reported will be the one where the BAM insert size is greater than zero. When the mate alignments are interchromosomal, the lexicographically lower chromosome will be reported first. Lastly, when an end is unmapped, the chromosome and strand will be set to “.” and the start and end coordinates will be set to -1. By default, this is disabled and the output will be reported in BED format. |
-mate1 |
When writing BEDPE (-bedpe) format, always report mate one as the first BEDPE “block”. |
-bed12 |
Write “blocked” BED (a.k.a. BED12) format. This will convert “spliced” BAM alignments (denoted by the “N” CIGAR operation) to BED12. Forces -split. |
-split |
Report each portion of a “split” BAM (i.e., having an “N” CIGAR operation) alignment as a distinct BED intervals. |
-splitD |
Report each portion of a “split” BAM while obeying both “N” CIGAR and “D” operation. Forces -split. |
-ed |
Use the “edit distance” tag (NM) for the BED score field. Default for BED is to use mapping quality. Default for BEDPE is to use the minimum of the two mapping qualities for the pair. When -ed is used with -bedpe, the total edit distance from the two mates is reported. |
-tag |
Use other numeric BAM alignment tag for BED score. Default for BED is to use mapping quality. Disallowed with BEDPE output. |
-color |
An R,G,B string for the color used with BED12 format. Default is (255,0,0). |
-cigar |
Add the CIGAR string to the BED entry as a 7th column. |
Default behavior¶
By default, each alignment in the BAM file is converted to a 6 column BED. The BED “name” field is comprised of the RNAME field in the BAM alignment. If mate information is available, the mate (e.g., “/1” or “/2”) field will be appended to the name.
$ bedtools bamtobed -i reads.bam | head -3
chr7 118970079 118970129 TUPAC_0001:3:1:0:1452#0/1 37 -
chr7 118965072 118965122 TUPAC_0001:3:1:0:1452#0/2 37 +
chr11 46769934 46769984 TUPAC_0001:3:1:0:1472#0/1 37 -
-split
Creating BED12 features from “spliced” BAM entries.¶
bedtools bamtobed
will, by default, create a BED6 feature that represents
the entire span of a spliced/split BAM alignment. However, when using the
-split
command, a BED12 feature is reported where BED blocks will be
created for each aligned portion of the sequencing read.
Chromosome ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Exons *************** **********
BED/BAM A ^^^^^^^^^^^^....................................^^^^
Result =============== ====