~ubuntu-branches/ubuntu/raring/bedtools/raring

« back to all changes in this revision

Viewing changes to docs/content/bamToBed.rst

  • Committer: Package Import Robot
  • Author(s): Charles Plessy
  • Date: 2012-11-04 17:59:41 UTC
  • mfrom: (1.1.9)
  • Revision ID: package-import@ubuntu.com-20121104175941-hahqzy1w8uy650z0
Tags: 2.17.0-1
bb9012e Imported Upstream version 2.16.2.
9006b23 Imported Upstream version 2.17.0.
9112569 Documented BEDTools license as a whole.
325689c Removed Pre-Depends: dpkg (>= 1.15.6).
a781b14 Conforms with Policy 3.9.4.
84b1167 Use Debhelper 9. 
0bf572d Distribute the test suite.
422cd34 Bash completion for BEDTools.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
###############
 
2
5.4 bamToBed
 
3
###############
 
4
 
 
5
**bamToBed** is a general purpose tool that will convert sequence alignments in BAM format to either
 
6
BED6, BED12 or BEDPE format. This enables one to convert BAM files for use with all of the other
 
7
BEDTools. The CIGAR string is used to compute the alignment end coordinate in an "ungapped"
 
8
fashion. That is, match ("M"), deletion ("D"), and splice ("N") operations are observed when computing
 
9
alignment ends.
 
10
 
 
11
============================================
 
12
5.4.1 Usage and option summary
 
13
============================================
 
14
**Usage:**
 
15
::
 
16
  bamToBed [OPTIONS] -i <BAM>
 
17
  
 
18
 
 
19
======================           =========================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================
 
20
Option                              Description
 
21
======================           =========================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================
 
22
**-bedpe**                                       Write BAM alignments in BEDPE format. Only one alignment from paired-end reads will be reported. Specifically, it 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*.                                                                                                                                
 
23
                                                                 **NOTE: When using this option, it is required that the BAM file is sorted/grouped by the read name. This allows bamToBed to extract correct alignment coordinates for each end based on their respective CIGAR strings. It also assumes that the alignments for a given pair come in groups of twos. There is not yet a standard method for reporting multiple alignments using BAM. bamToBed will fail if an aligner does not report alignments in pairs**.                                                   
 
24
                                 BAM files may be piped to bamToBed by specifying "-i stdin". See example below.
 
25
**-bed12**                                           Write "blocked" BED (a.k.a. BED12) format. This will convert "spliced" BAM alignments (denoted by the "N" CIGAR operation) to BED12.
 
26
**-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.                                            
 
27
**-tag**                                             Use other *numeric* BAM alignment tag for BED score. Default for BED is to use mapping quality. Disallowed with BEDPE output.
 
28
**-color**                                           An R,G,B string for the color used with BED12 format. Default is (255,0,0).                              
 
29
**-split**                                           Report each portion of a "split" BAM (i.e., having an "N" CIGAR operation) alignment as a distinct BED intervals.                              
 
30
======================           =========================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================
 
31
 
 
32
By default, each alignment in the BAM file is converted to a 6 column BED. The BED "name" field is
 
33
comprised of the RNAME field in the BAM alignment. If mate information is available, the mate (e.g.,
 
34
"/1" or "/2") field will be appended to the name. The "score" field is the mapping quality score from the
 
35
BAM alignment, unless the **-ed** option is used.
 
36
 
 
37
Examples:
 
38
::
 
39
  bamToBed -i reads.bam | head -5
 
40
  chr7   118970079   118970129   TUPAC_0001:3:1:0:1452#0/1   37   -
 
41
  chr7   118965072   118965122   TUPAC_0001:3:1:0:1452#0/2   37   +
 
42
  chr11  46769934    46769984    TUPAC_0001:3:1:0:1472#0/1   37   -
 
43
  
 
44
  bamToBed -i reads.bam -tag NM | head -5
 
45
  chr7   118970079   118970129   TUPAC_0001:3:1:0:1452#0/1   1    -
 
46
  chr7   118965072   118965122   TUPAC_0001:3:1:0:1452#0/2   3    +
 
47
  chr11  46769934    46769984    TUPAC_0001:3:1:0:1472#0/1   1    -
 
48
  
 
49
  bamToBed -i reads.bam -bedpe | head -3
 
50
  chr7   118965072   118965122   chr7   118970079   118970129
 
51
         TUPAC_0001:3:1:0:1452#0 37     +     -
 
52
  chr11  46765606    46765656    chr11  46769934    46769984
 
53
         TUPAC_0001:3:1:0:1472#0 37     +     -
 
54
  chr20  54704674    54704724    chr20  54708987    54709037
 
55
         TUPAC_0001:3:1:1:1833#0 37     +    
 
56
 
 
57
                 
 
58
One can easily use samtools and bamToBed together as part of a UNIX pipe. In this example, we will
 
59
only convert properly-paired (BAM flag == 0x2) reads to BED format.
 
60
::
 
61
  samtools view -bf 0x2 reads.bam | bamToBed -i stdin | head
 
62
  chr7   118970079   118970129   TUPAC_0001:3:1:0:1452#0/1   37   -
 
63
  chr7   118965072   118965122   TUPAC_0001:3:1:0:1452#0/2   37   +
 
64
  chr11  46769934    46769984    TUPAC_0001:3:1:0:1472#0/1   37   -
 
65
  chr11  46765606    46765656    TUPAC_0001:3:1:0:1472#0/2   37   +
 
66
  chr20  54704674    54704724    TUPAC_0001:3:1:1:1833#0/1   37   +
 
67
  chr20  54708987    54709037    TUPAC_0001:3:1:1:1833#0/2   37   -
 
68
  chrX   9380413     9380463     TUPAC_0001:3:1:1:285#0/1    0    -
 
69
  chrX   9375861     9375911     TUPAC_0001:3:1:1:285#0/2    0    +
 
70
  chrX   131756978   131757028   TUPAC_0001:3:1:2:523#0/1    37   +
 
71
  chrX   131761790   131761840   TUPAC_0001:3:1:2:523#0/2    37   -
 
72
 
 
73
  
 
74
==================================================================
 
75
5.4.2 (-split)Creating BED12 features from "spliced" BAM entries. 
 
76
==================================================================
 
77
bamToBed will, by default, create a BED6 feature that represents the entire span of a spliced/split
 
78
BAM alignment. However, when using the **-split** command, a BED12 feature is reported where BED
 
79
blocks will be created for each aligned portion of the sequencing read.
 
80
::
 
81
  Chromosome  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
82
             
 
83
  Exons       ***************                                    **********
 
84
  
 
85
  BED/BAM A      ^^^^^^^^^^^^....................................^^^^
 
86
  
 
87
  Result      ===============                                    ====
 
88