Debian Codegraph @

docs/content/tools/window.rst

raw
1 .. _window:
2
3 ###############
4 *window*
5 ###############
6
7 |
8
9 .. image:: ../images/tool-glyphs/window-glyph.png
10 :width: 600pt
11
12 |
13
14 Similar to ``bedtools intersect``, ``window`` searches for overlapping features
15 in A and B. However, ``window`` adds a specified number (1000, by default) of
16 base pairs upstream and downstream of each feature in A. In effect, this allows
17 features in B that are "near" features in A to be detected.
18
19 ===============================
20 Usage and option summary
21 ===============================
22 **Usage**:
23 ::
24
25 bedtools window [OPTIONS] [-a|-abam] -b <BED/GFF/VCF>
26
27 **(or)**:
28 ::
29
30 bedtools window [OPTIONS] [-a|-abam] -b <BED/GFF/VCF>
31
32
33
34 =========================== =========================================================================================================================================================
35 Option Description
36 =========================== =========================================================================================================================================================
37 **-abam** BAM file A. Each BAM alignment in A is compared to B in search of overlaps. Use "stdin" if passing A with a UNIX pipe: For example: samtools view -b <BAM> | bedtools window -abam stdin -b genes.bed
38 **-ubam** Write uncompressed BAM output. The default is write compressed BAM output.
39 **-bed** When using BAM input (-abam), write output as BED. The default is to write output in BAM when using -abam. For example: bedtools window -abam reads.bam -b genes.bed -bed
40 **-w** Base pairs added upstream and downstream of each entry in A when searching for overlaps in B. *Default is 1000 bp*.
41 **-l** Base pairs added upstream (left of) of each entry in A when searching for overlaps in B. *Allows one to create asymmetrical "windows". Default is 1000bp*.
42 **-r** Base pairs added downstream (right of) of each entry in A when searching for overlaps in B. *Allows one to create asymmetrical "windows". Default is 1000bp*.
43 **-sw** Define -l and -r based on strand. For example if used, -l 500 for a negative-stranded feature will add 500 bp downstream. *By default, this is disabled*.
44 **-sm** Only report hits in B that overlap A on the same strand. *By default, overlaps are reported without respect to strand*.
45 **-Sm** Only report hits in B that overlap A on the opposite strand. *By default, overlaps are reported without respect to strand*.
46 **-u** Write original A entry once if any overlaps found in B. In other words, just report the fact at least one overlap was found in B.
47 **-c** For each entry in A, report the number of hits in B while restricting to -w, -l, and -r. Reports 0 for A entries that have no overlap with B.
48 **-v** Only report those entries in A that have *no overlaps* with B.
49 **-header** Print the header from the A file prior to results.
50 =========================== =========================================================================================================================================================
51
52
53 ==========================================================================
54 Default behavior
55 ==========================================================================
56 By default, ``bedtools window`` adds 1000 bp upstream and downstream of each A
57 feature and searches for features in B that overlap this "window". If an overlap
58 is found in B, both the *original* A feature and the *original* B feature are
59 reported.
60
61 .. code-block:: bash
62
63 $ cat A.bed
64 chr1 100 200
65
66 $ cat B.bed
67 chr1 500 1000
68 chr1 1300 2000
69
70 $ bedtools window -a A.bed -b B.bed
71 chr1 100 200 chr1 500 1000
72
73
74 ==========================================================================
75 ``-w`` Defining a custom window size
76 ==========================================================================
77 Instead of using the default window size of 1000bp, one can define a custom,
78 *symmetric* window around each feature in A using the **-w** option. One should
79 specify the window size in base pairs. For example, a window of 5kb should be
80 defined as ``-w 5000``.
81
82 For example (note that in contrast to the default behavior,
83 the second B entry is reported):
84
85 .. code-block:: bash
86
87 $ cat A.bed
88 chr1 100 200
89
90 $ cat B.bed
91 chr1 500 1000
92 chr1 1300 2000
93
94 $ bedtools window -a A.bed -b B.bed -w 5000
95 chr1 100 200 chr1 500 1000
96 chr1 100 200 chr1 1300 2000
97
98
99 ==========================================================================
100 ``-l and -r`` Defining *asymmetric* windows
101 ==========================================================================
102 One can also define asymmetric windows where a differing number of bases are
103 added upstream and downstream of each feature using the ``-l`` (upstream)
104 and ``-r`` (downstream)** options.
105
106 .. note::
107
108 By default, the ``-l`` and ``-r`` options ignore strand. If you want to define
109 *upstream* and *downstream* based on strand, use the ``-sw`` option (below)
110 with the ``-l`` and ``-r`` options.
111
112 For example (note the difference between -l 200 and -l 300):
113
114
115 .. code-block:: bash
116
117 $ cat A.bed
118 chr1 1000 2000
119
120 $ cat B.bed
121 chr1 500 800
122 chr1 10000 20000
123
124 $ bedtools window -a A.bed -b B.bed -l 200 -r 20000
125 chr1 1000 2000 chr1 10000 20000
126
127 $ bedtools window -a A.bed -b B.bed -l 300 -r 20000
128 chr1 1000 2000 chr1 500 800
129 chr1 1000 2000 chr1 10000 20000
130
131
132 ==========================================================================
133 ``-sw`` Defining asymmetric windows based on strand
134 ==========================================================================
135 Especially when dealing with gene annotations or RNA-seq experiments, you may
136 want to define asymmetric windows based on "strand". For example, you may want
137 to screen for overlaps that occur within 5000 bp upstream of a gene (e.g. a
138 promoter region) while screening only 1000 bp downstream of the gene.
139 By enabling the ``-sw`` ("stranded" windows) option, the windows are added
140 upstream or downstream according to strand. For example, imagine one
141 specifies ``-l 5000``, ``-r 1000`` as well as the ``-sw`` option. In this case,
142 forward stranded ("+") features will screen 5000 bp to the *left* (that is,
143 *lower* genomic coordinates) and 1000 bp to the *right* (that is, *higher*
144 genomic coordinates). By contrast, reverse stranded ("-") features will screen
145 5000 bp to the *right* (that is, *higher* genomic coordinates) and 1000 bp to
146 the *left* (that is, *lower* genomic coordinates).
147
148 For example (note the difference between ``-l 200`` and ``-l 300``):
149
150 .. code-block:: bash
151
152 $ cat A.bed
153 chr1 10000 20000 A.forward 1 +
154 chr1 10000 20000 A.reverse 1 -
155
156 $ cat B.bed
157 chr1 1000 8000 B1
158 chr1 24000 32000 B2
159
160 $ bedtools window -a A.bed -b B.bed -l 5000 -r 1000 -sw
161 chr1 10000 20000 A.forward 1 + chr1 1000 8000 B1
162 chr1 10000 20000 A.reverse 1 - chr1 24000 32000 B2
163
164
165
166 ==========================================================================
167 ``-sm`` Enforcing matches with the *same* "strandedness"
168 ==========================================================================
169 This option behaves the same as the ``-s`` option for ``bedtools intersect``
170 while scanning for overlaps within the "window" surrounding A. That is, overlaps
171 in B will only be included if the B interval is on the *same* strand as the A
172 interval.
173
174 ==========================================================================
175 ``-Sm`` Enforcing matches with the *opposite* "strandedness"
176 ==========================================================================
177 This option behaves the same as the ``-S`` option for ``bedtools intersect`` while
178 scanning for overlaps within the "window" surrounding A. That is, overlaps in
179 B will only be included if the B interval is on the *opposite* strand as the A
180 interval.
181
182
183 ==========================================================================
184 ``-u`` Reporting the presence/absence of at least one overlapping feature
185 ==========================================================================
186 This option behaves the same as for ``bedtools intersect``. That is, even if
187 multiple overlaps exist, each A interval will only be reported once.
188
189
190 ==========================================================================
191 ``-c`` Reporting the number of overlapping features
192 ==========================================================================
193 This option behaves the same as for ``bedtools intersect``. That is, it will
194 report the *count* of intervals in B that overlap each A interval.
195
196
197
198 ==========================================================================
199 ``-v`` Reporting the absence of any overlapping features
200 ==========================================================================
201 This option behaves the same as for ``bedtools intersect``. That is, it will
202 only report those intervals in A that have have *zero* overlaps in B.
203
204
205 ==========================================================================
206 ``-header`` Print the header for the A file before reporting results.
207 ==========================================================================
208 By default, if your A file has a header, it is ignored when reporting results.
209 This option will instead tell bedtools to first print the header for the
210 A file prior to reporting results.