Debian Codegraph @

docs/content/tools/map.rst

raw
1 .. _map:
2
3 ###############
4 *map*
5 ###############
6
7 |
8
9 .. image:: ../images/tool-glyphs/map-glyph.png
10 :width: 600pt
11 :align: center
12
13 |
14
15 ``bedtools map`` allows one to map overlapping features in a B file onto
16 features in an A file and apply statistics and/or summary operations on those
17 features.
18
19 For example, one could use ``bedtools map`` to compute the average
20 score of BEDGRAPH records that overlap genes. Since the fourth column in
21 BEDGRAPH is the score, the following command illustrates how this would be done:
22
23 .. code-block:: bash
24
25 $ bedtools map -a genes.bed -b peaks.bedgraph -c 4 -o mean
26
27 Another example is discussed in this Biostars
28 `post <http://www.biostars.org/p/61653/>`_.
29
30
31 .. note::
32
33 ``bedtools map`` requires each input file to be sorted by genome coordinate.
34 For BED files, this can be done with ``sort -k1,1 -k2,2n``. Other sorting criteria are allowed if a genome file (`-g`) is provides that specifies the expected chromosome order.
35
36
37 .. note::
38
39 The ``map`` tool is substantially faster in versions 2.19.0 and later. The plot below demonstrates the increased speed when, for example, counting the number of exome alignments that align to each exon. The bedtools times are compared to the bedops `bedmap` utility as a point of reference.
40
41 |
42
43 .. image:: ../images/tool-glyphs/map-speed-comparo.png
44 :width: 500pt
45 :align: center
46
47 |
48
49
50
51
52
53 ==========================================================================
54 Usage and option summary
55 ==========================================================================
56 **Usage**:
57 ::
58
59 bedtools map [OPTIONS] -a <bed/gff/vcf> -b <bed/gff/vcf>
60
61 **(or)**:
62 ::
63
64 mapBed [OPTIONS] -a <bed/gff/vcf> -b <bed/gff/vcf>
65
66
67 =========================== ===============================================================================================================================================================================================================
68 Option Description
69 =========================== ===============================================================================================================================================================================================================
70 **-c** | Specify the column from the B file to map onto intervals in A.
71 | ``Default: 5``
72
73 **-o** Specify the operation that should be applied to ``-c``.
74
75 | Valid operations:
76
77 | **sum** - *numeric only*
78 | **count** - *numeric or text*
79 | **count_distinct** - *numeric or text*
80 | **min** - *numeric only*
81 | **max** - *numeric only*
82 | **absmin** - *numeric only*
83 | **absmax** - *numeric only*
84 | **mean** - *numeric only*
85 | **median** - *numeric only*
86 | **antimode** - *numeric or text*
87 | **collapse** (i.e., print a comma separated list) - *numeric or text*
88 | **distinct** (i.e., print a comma separated list) - *numeric or text*
89 | **concat** (i.e., print a comma separated list) - *numeric or text*
90
91 **-f** Minimum overlap required as a fraction of A. Default is 1E-9 (i.e. 1bp).
92 **-F** Minimum overlap required as a fraction of B. Default is 1E-9 (i.e., 1bp).
93 **-r** Require that the fraction of overlap be reciprocal for A and B. In other words, if -f is 0.90 and -r is used, this requires that B overlap at least 90% of A and that A also overlaps at least 90% of B.
94 **-e** Require that the minimum fraction be satisfied for A _OR_ B. In other words, if -e is used with -f 0.90 and -F 0.10 this requires that either 90% of A is covered OR 10% of B is covered. Without -e, both fractions would have to be satisfied.
95 **-s** Force "strandedness". That is, only report hits in B that overlap A on the same strand. By default, overlaps are reported without respect to strand.
96 **-S** Require different strandedness. That is, only report hits in B that overlap A on the _opposite_ strand. By default, overlaps are reported without respect to strand.
97 **-null** | The value to print if no overlaps are found for an A interval.
98 | ``Default: "."``
99
100 **-header** Print the header from the A file prior to results.
101 **-split** Treat "split" BAM (i.e., having an "N" CIGAR operation) or BED12 entries as distinct BED intervals.
102 When using -sorted, memory usage remains low even for very large files.
103 **-g** Specify a genome file the defines the expected chromosome order in the input files.
104 =========================== ===============================================================================================================================================================================================================
105
106
107
108 ================================================================================
109 Default behavior - compute the ``sum`` of the ``score`` column for all overlaps.
110 ================================================================================
111 By default, ``map`` computes the sum of the 5th column (the ``score`` field for
112 BED format) for all intervals in B that overlap each interval in A.
113
114 .. tip::
115
116 Records in A that have no overlap will, by default, return ``.`` for the
117 computed value from B. This can be changed with the ``-null`` option.
118
119 .. code-block:: bash
120
121 $ cat a.bed
122 chr1 10 20 a1 1 +
123 chr1 50 60 a2 2 -
124 chr1 80 90 a3 3 -
125
126 $ cat b.bed
127 chr1 12 14 b1 2 +
128 chr1 13 15 b2 5 -
129 chr1 16 18 b3 5 +
130 chr1 82 85 b4 2 -
131 chr1 85 87 b5 3 +
132
133 $ bedtools map -a a.bed -b b.bed
134 chr1 10 20 a1 1 + 12
135 chr1 50 60 a2 2 - .
136 chr1 80 90 a3 3 - 5
137
138
139 ================================================================================
140 ``mean`` Compute the mean of a column from overlapping intervals
141 ================================================================================
142
143 .. code-block:: bash
144
145 $ cat a.bed
146 chr1 10 20 a1 1 +
147 chr1 50 60 a2 2 -
148 chr1 80 90 a3 3 -
149
150 $ cat b.bed
151 chr1 12 14 b1 2 +
152 chr1 13 15 b2 5 -
153 chr1 16 18 b3 5 +
154 chr1 82 85 b4 2 -
155 chr1 85 87 b5 3 +
156
157 $ bedtools map -a a.bed -b b.bed -c 5 -o mean
158 chr1 10 20 a1 1 + 4
159 chr1 50 60 a2 2 - .
160 chr1 80 90 a3 3 - 2.5
161
162
163 ================================================================================
164 ``collapse`` List each value of a column from overlapping intervals
165 ================================================================================
166
167 .. code-block:: bash
168
169 $ bedtools map -a a.bed -b b.bed -c 5 -o collapse
170 chr1 10 20 a1 1 + 2,5,5
171 chr1 50 60 a2 2 - .
172 chr1 80 90 a3 3 - 2,3
173
174
175 ================================================================================
176 ``distinct`` List each *unique* value of a column from overlapping intervals
177 ================================================================================
178
179 .. code-block:: bash
180
181 $ bedtools map -a a.bed -b b.bed -c 5 -o distinct
182 chr1 10 20 a1 1 + 2,5
183 chr1 50 60 a2 2 - .
184 chr1 80 90 a3 3 - 2,3
185
186 ================================================================================
187 ``-s`` Only include intervals that overlap on the *same* strand.
188 ================================================================================
189
190 .. code-block:: bash
191
192 $ bedtools map -a a.bed -b b.bed -c 5 -o collapse -s
193 chr1 10 20 a1 1 + 2,5
194 chr1 50 60 a2 2 - .
195 chr1 80 90 a3 3 - 2
196
197 ================================================================================
198 ``-S`` Only include intervals that overlap on the *opposite* strand.
199 ================================================================================
200
201 .. code-block:: bash
202
203 $ bedtools map -a a.bed -b b.bed -c 5 -o collapse -S
204 chr1 10 20 a1 1 + 5
205 chr1 50 60 a2 2 - .
206 chr1 80 90 a3 3 - 3
207
208
209 ================================================================================
210 Multiple operations and columns at the same time.
211 ================================================================================
212
213 As of version 2.19.1, multiple columns and operations are allowed at the same time in a single run. This greatly expedites analyses by preventing one from having to process the same file over an over for each column/operation.
214
215 .. code-block:: bash
216
217 $ bedtools map -a a.bed -b b.bed -c 5,5,5,5 -o min,max,median,collapse
218
219 Or, apply the same function to multiple columns:
220
221 .. code-block:: bash
222
223 $ bedtools map -a a.bed -b b.bed -c 3,4,5,6 -o mean
224