upstream-extended/iuc/tools/bedtools/intersectBed.xml
1<tool id="bedtools_intersectbed" name="bedtools Intersect intervals" version="@TOOL_VERSION@+galaxy1" profile="@PROFILE@">
2 <description>find overlapping intervals in various ways</description>
3 <macros>
4 <import>macros.xml</import>
5 </macros>
6 <expand macro="bio_tools" />
7 <expand macro="requirements">
8 <requirement type="package" version="1.18">samtools</requirement>
9 </expand>
10 <expand macro="stdio" />
11 <command><![CDATA[
12#import re
13#set modes = ' '.join(str($overlap_mode).split(','))
14
15#if $modes == "None":
16 #set modes = ''
17#end if
18
19bedtools intersect
20-a '${inputA}'
21
22#if str($reduce_or_iterate.reduce_or_iterate_selector) == 'iterate':
23 -b '$reduce_or_iterate.inputB'
24#else:
25 -b
26 #for $file in $reduce_or_iterate.inputB
27 '$file'
28 #end for
29
30 #if $reduce_or_iterate.names:
31 #set namesB = "' '".join([re.sub('[^\s\w\-]', '_', str($file.element_identifier)) for $file in $reduce_or_iterate.inputB])
32 -names '$namesB'
33 #end if
34#end if
35$split
36$strand
37#if $fraction_cond.fraction_select == "specify":
38 #if str($fraction_cond.overlap)
39 -f $fraction_cond.overlap
40 #end if
41 $fraction_cond.reciprocal_cond.reciprocal
42 #if str($fraction_cond.reciprocal_cond.reciprocal) == '':
43 #if str($fraction_cond.reciprocal_cond.overlapB):
44 -F $fraction_cond.reciprocal_cond.overlapB
45 #end if
46 $fraction_cond.reciprocal_cond.disjoint
47 #end if
48#end if
49$invert
50$once
51$header
52$modes
53@SORTED@
54@GENOME_FILE@
55$bed
56$count
57> '${output}'
58 ]]></command>
59 <inputs>
60 <param name="inputA" type="data" format="bam,@STD_BEDTOOLS_INPUTS@" label="File A to intersect with B" help="BAM/@STD_BEDTOOLS_INPUT_LABEL@ format" />
61 <conditional name="reduce_or_iterate">
62 <param name="reduce_or_iterate_selector" type="select" label="Combined or separate output files">
63 <option value="iterate" selected="true">One output file per 'input B' file</option>
64 <option value="reduce">Single output containing intersections of any 'input B' lines with A</option>
65 </param>
66 <when value="iterate">
67 <param name="inputB" argument="-b" type="data" format="bam,@STD_BEDTOOLS_INPUTS@"
68 label="File B to intersect with A" help="BAM/@STD_BEDTOOLS_INPUT_LABEL@ format"/>
69 </when>
70 <when value="reduce">
71 <param name="inputB" argument="-b" type="data" format="bam,@STD_BEDTOOLS_INPUTS@" multiple="true"
72 label="File(s) B to intersect with A" help="BAM/@STD_BEDTOOLS_INPUT_LABEL@ format"/>
73 <param argument="-names" type="boolean" truevalue="yes" falsevalue="no" label="Add data set names instead of indices" />
74 </when>
75 </conditional>
76 <expand macro="strand2" />
77 <param name="overlap_mode" type="select" multiple="true" label="What should be written to the output file?">
78 <option value="-wa">Write the original entry in A for each overlap (-wa)</option>
79 <option value="-wb">Write the original entry in B for each overlap. Useful for knowing what A overlaps. Restricted by the fraction- and reciprocal option (-wb)</option>
80 <option value="-wo">Write the original A and B entries plus the number of base pairs of overlap between the two features. Only A features with overlap are reported. Restricted by the fraction- and reciprocal option (-wo)</option>
81 <option value="-wao">Write the original A and B entries plus the number of base pairs of overlap between the two features. However, A features w/o overlap are also reported with a NULL B feature and overlap = 0. Restricted by the fraction- and reciprocal option (-wao)</option>
82 <option value="-loj">Perform a "left outer join". That is, for each feature in A report each overlap with B. If no overlaps are found, report a NULL feature for B (-loj)</option>
83 </param>
84
85 <expand macro="split" />
86 <conditional name="fraction_cond">
87 <param name="fraction_select" type="select" label="Required overlap">
88 <option value="default" selected="true">Default: 1bp</option>
89 <option value="specify">Specify minimum overlap(s)</option>
90 </param>
91 <when value="default"/>
92 <when value="specify">
93 <expand macro="overlap" />
94 <conditional name="reciprocal_cond">
95 <expand macro="reciprocal" />
96 <when value="-r"/>
97 <when value="">
98 <expand macro="overlap" name="overlapB" argument="-F" fracof="B"/>
99 <param name="disjoint" argument="-e" type="boolean" truevalue="-e" falsevalue="" checked="false"
100 label="Require that the fraction of overlap is fulfilled for A OR B." help="If enabled, then for -f 0.90 and -F 0.10 this requires that either 90% of A is covered OR 10% of B is covered, otherwise, both fractions would have to be satisfied."/>
101 </when>
102 </conditional>
103 </when>
104 </conditional>
105 <!-- -v -->
106 <param name="invert" argument="-v" type="boolean" truevalue="-v" falsevalue="" checked="false"
107 label="Report only those alignments that **do not** overlap with file(s) B" />
108 <!-- -u -->
109 <param name="once" argument="-u" type="boolean" truevalue="-u" falsevalue="" checked="false"
110 label="Write the original A entry _once_ if _any_ overlaps found in B."
111 help="Just report the fact >=1 hit was found" />
112 <!-- -c -->
113 <param name="count" argument="-c" type="boolean" truevalue="-c" falsevalue="" checked="false"
114 label="For each entry in A, report the number of overlaps with B."
115 help="Reports 0 for A entries that have no overlap with B" />
116 <!-- -bed -->
117 <param argument="-bed" type="boolean" truevalue="-bed" falsevalue="" checked="false"
118 label="When using BAM input, write output as BED instead of BAM." />
119 <!-- -sorted -g -->
120 <expand macro="sorted" />
121 <expand macro="input_conditional_genome_file" optional="true" help="Only applies when used with -sorted option."/>
122 <expand macro="print_header" />
123 </inputs>
124 <outputs>
125 <data name="output" format_source="inputA" metadata_source="inputA">
126 <change_format>
127 <when input="bed" value="-bed" format="bed" />
128 </change_format>
129 </data>
130 </outputs>
131 <tests>
132 <!-- test adapted from the tutorial https://bedtools.readthedocs.io/en/latest/content/tools/intersect.html -->
133 <test>
134 <param name="inputA" value="intersect-A.bed" ftype="bed" />
135 <conditional name="reduce_or_iterate">
136 <param name="reduce_or_iterate_selector" value="iterate" />
137 <param name="inputB" value="intersect-B.bed" ftype="bed" />
138 </conditional>
139 <output name="output" file="intersect-default.bed" ftype="bed" />
140 </test>
141 <test>
142 <param name="inputA" value="intersect-query.bed" ftype="bed" />
143 <conditional name="reduce_or_iterate">
144 <param name="reduce_or_iterate_selector" value="reduce" />
145 <param name="inputB" value="intersect-d1.bed,intersect-d2.bed,intersect-d3.bed" ftype="bed" />
146 </conditional>
147 <output name="output" file="intersect-multiple.bed" ftype="bed" />
148 </test>
149 <test>
150 <param name="inputA" value="intersect-query.bed" ftype="bed" />
151 <conditional name="reduce_or_iterate">
152 <param name="reduce_or_iterate_selector" value="reduce" />
153 <param name="inputB" value="intersect-d1.bed,intersect-d2.bed,intersect-d3.bed" ftype="bed" />
154 </conditional>
155 <param name="overlap_mode" value="-wa,-wb" />
156 <param name="sorted" value="true" />
157 <output name="output" file="intersect-multiple-wa-wb.bed" ftype="bed" />
158 </test>
159 <test>
160 <param name="inputA" value="intersect-query.bed" ftype="bed" />
161 <conditional name="reduce_or_iterate">
162 <param name="reduce_or_iterate_selector" value="reduce" />
163 <param name="inputB" value="intersect-d1.bed,intersect-d2.bed,intersect-d3.bed" ftype="bed" />
164 <param name="names" value="yes" />
165 </conditional>
166 <param name="overlap_mode" value="-wa,-wb" />
167 <param name="sorted" value="true" />
168 <output name="output" file="intersect-multiple-wa-wb-wnames.bed" ftype="bed" />
169 </test>
170 <test>
171 <param name="inputA" value="intersect-query.bed" ftype="bed" />
172 <conditional name="reduce_or_iterate">
173 <param name="reduce_or_iterate_selector" value="reduce" />
174 <param name="inputB" value="intersect-d1.bed,intersect-d2.bed,intersect-d3.bed" ftype="bed" />
175 </conditional>
176 <param name="invert" value="true" />
177 <param name="sorted" value="true" />
178 <output name="output" file="intersect-multiple-invert.bed" ftype="bed" />
179 </test>
180 <test>
181 <param name="inputA" value="intersect-query.bed" ftype="bed" />
182 <conditional name="reduce_or_iterate">
183 <param name="reduce_or_iterate_selector" value="reduce" />
184 <param name="inputB" value="intersect-d1.bed,intersect-d2.bed,intersect-d3.bed" ftype="bed" />
185 </conditional>
186 <param name="overlap_mode" value="-wa,-wb" />
187 <conditional name="fraction_cond">
188 <param name="fraction_select" value="specify"/>
189 <param name="overlap" value="1.0" />
190 </conditional>
191 <param name="sorted" value="true" />
192 <output name="output" file="intersect-multiple-fracA.bed" ftype="bed" />
193 </test>
194 <test>
195 <param name="inputA" value="intersect-A.bed" ftype="bed" />
196 <conditional name="reduce_or_iterate">
197 <param name="reduce_or_iterate_selector" value="iterate" />
198 <param name="inputB" value="intersect-B.bed" ftype="bed" />
199 </conditional>
200 <param name="overlap_mode" value="-wa" />
201 <output name="output" file="intersect-wa.bed" ftype="bed" />
202 </test>
203 <test>
204 <param name="inputA" value="intersect-A.bed" ftype="bed" />
205 <conditional name="reduce_or_iterate">
206 <param name="reduce_or_iterate_selector" value="iterate" />
207 <param name="inputB" value="intersect-B.bed" ftype="bed" />
208 </conditional>
209 <param name="overlap_mode" value="-wb" />
210 <output name="output" file="intersect-wb.bed" ftype="bed" />
211 </test>
212 <test>
213 <param name="inputA" value="intersect-A.bed" ftype="bed" />
214 <conditional name="reduce_or_iterate">
215 <param name="reduce_or_iterate_selector" value="iterate" />
216 <param name="inputB" value="intersect-B.bed" ftype="bed" />
217 </conditional>
218 <param name="overlap_mode" value="-wa,-wb" />
219 <output name="output" file="intersect-wa-wb.bed" ftype="bed" />
220 </test>
221 <test>
222 <param name="inputA" value="intersect-A.bed" ftype="bed" />
223 <conditional name="reduce_or_iterate">
224 <param name="reduce_or_iterate_selector" value="iterate" />
225 <param name="inputB" value="intersect-B.bed" ftype="bed" />
226 </conditional>
227 <param name="overlap_mode" value="-loj" />
228 <output name="output" file="intersect-loj.bed" ftype="bed" />
229 </test>
230 <test>
231 <param name="inputA" value="intersect-A.bed" ftype="bed" />
232 <conditional name="reduce_or_iterate">
233 <param name="reduce_or_iterate_selector" value="iterate" />
234 <param name="inputB" value="intersect-B.bed" ftype="bed" />
235 </conditional>
236 <param name="overlap_mode" value="-wo" />
237 <output name="output" file="intersect-wo.bed" ftype="bed" />
238 </test>
239 <test>
240 <param name="inputA" value="intersect-A.bed" ftype="bed" />
241 <conditional name="reduce_or_iterate">
242 <param name="reduce_or_iterate_selector" value="iterate" />
243 <param name="inputB" value="intersect-B.bed" ftype="bed" />
244 </conditional>
245 <param name="overlap_mode" value="-wao" />
246 <output name="output" file="intersect-wao.bed" ftype="bed" />
247 </test>
248 <test>
249 <param name="inputA" value="intersect-A.bed" ftype="bed" />
250 <conditional name="reduce_or_iterate">
251 <param name="reduce_or_iterate_selector" value="iterate" />
252 <param name="inputB" value="intersect-B.bed" ftype="bed" />
253 </conditional>
254 <param name="once" value="true" />
255 <output name="output" file="intersect-unique.bed" ftype="bed" />
256 </test>
257 <test>
258 <param name="inputA" value="intersect-A.bed" ftype="bed" />
259 <conditional name="reduce_or_iterate">
260 <param name="reduce_or_iterate_selector" value="iterate" />
261 <param name="inputB" value="intersect-B.bed" ftype="bed" />
262 </conditional>
263 <param name="count" value="true"/>
264 <output name="output" file="intersect-count.bed" ftype="bed" />
265 </test>
266 <test>
267 <param name="inputA" value="intersect-A.bed" ftype="bed" />
268 <conditional name="reduce_or_iterate">
269 <param name="reduce_or_iterate_selector" value="iterate" />
270 <param name="inputB" value="intersect-B.bed" ftype="bed" />
271 </conditional>
272 <param name="invert" value="true"/>
273 <output name="output" file="intersect-invert.bed" ftype="bed" />
274 </test>
275 <test>
276 <param name="inputA" value="intersect-A2.bed" ftype="bed" />
277 <conditional name="reduce_or_iterate">
278 <param name="reduce_or_iterate_selector" value="iterate" />
279 <param name="inputB" value="intersect-B2.bed" ftype="bed" />
280 </conditional>
281 <param name="overlap_mode" value="-wa,-wb" />
282 <conditional name="fraction_cond">
283 <param name="fraction_select" value="specify"/>
284 <param name="overlap" value="0.5" />
285 </conditional>
286 <output name="output" file="intersect-fracA.bed" ftype="bed" />
287 </test>
288 <test>
289 <param name="inputA" value="intersect-A2.bed" ftype="bed" />
290 <conditional name="reduce_or_iterate">
291 <param name="reduce_or_iterate_selector" value="iterate" />
292 <param name="inputB" value="intersect-B2.bed" ftype="bed" />
293 </conditional>
294 <param name="overlap_mode" value="-wa,-wb" />
295 <conditional name="fraction_cond">
296 <param name="fraction_select" value="specify"/>
297 <param name="overlap" value="0.5" />
298 <conditional name="reciprocal_cond">
299 <param name="reciprocal" value="-r" />
300 </conditional>
301 </conditional>
302 <output name="output" file="intersect-fracA-rec.bed" ftype="bed" />
303 </test>
304 <test>
305 <param name="inputA" value="intersect-A2.bed" ftype="bed" />
306 <conditional name="reduce_or_iterate">
307 <param name="reduce_or_iterate_selector" value="iterate" />
308 <param name="inputB" value="intersect-B2.bed" ftype="bed" />
309 </conditional>
310 <param name="overlap_mode" value="-wa,-wb" />
311 <conditional name="fraction_cond">
312 <param name="fraction_select" value="specify"/>
313 <param name="overlap" value="0.5" />
314 <conditional name="reciprocal_cond">
315 <param name="overlapB" value="0.5" />
316 </conditional>
317 </conditional>
318 <output name="output" file="intersect-fracA-rec.bed" ftype="bed" />
319 </test>
320 <test>
321 <param name="inputA" value="intersect-A2.bed" ftype="bed" />
322 <conditional name="reduce_or_iterate">
323 <param name="reduce_or_iterate_selector" value="iterate" />
324 <param name="inputB" value="intersect-B2.bed" ftype="bed" />
325 </conditional>
326 <param name="overlap_mode" value="-wa,-wb" />
327 <conditional name="fraction_cond">
328 <param name="fraction_select" value="specify"/>
329 <param name="overlap" value="0.5" />
330 <conditional name="reciprocal_cond">
331 <param name="overlapB" value="0.5" />
332 <param name="disjoint" value="true" />
333 </conditional>
334 </conditional>
335 <output name="output" file="intersect-fracA.bed" ftype="bed" />
336 </test>
337 <!-- old tests -->
338 <test>
339 <param name="inputA" value="intersectBed1.bed" ftype="bed" />
340 <conditional name="reduce_or_iterate">
341 <param name="inputB" value="intersectBed2.bed" ftype="bed" />
342 </conditional>
343 <param name="overlap_mode" value="-wa" />
344 <param name="split" value="False" />
345 <output name="output" file="intersectBed_result1.bed" ftype="bed" />
346 </test>
347 <test>
348 <param name="inputA" value="intersectBed1.bed" ftype="bed" />
349 <conditional name="reduce_or_iterate">
350 <param name="inputB" value="intersectBed2.bed" ftype="bed" />
351 </conditional>
352 <param name="overlap_mode" value="-wa,-wb" />
353 <param name="split" value="False" />
354 <output name="output" file="intersectBed_result2.bed" ftype="bed" />
355 </test>
356 <test>
357 <param name="inputA" value="intersectBed1.bed" ftype="bed" />
358 <conditional name="reduce_or_iterate">
359 <param name="inputB" value="intersectBed2.bed" ftype="bed" />
360 </conditional>
361 <param name="invert" value="True" />
362 <param name="split" value="False" />
363 <output name="output" file="intersectBed_result3.bed" ftype="bed" />
364 </test>
365 </tests>
366 <help><![CDATA[
367**What it does**
368
369By far, the most common question asked of two sets of genomic features is whether or not any of the features in the two sets “overlap” with one another. This is known as feature intersection. bedtools intersect allows one to screen for overlaps between two sets of genomic features. Moreover, it allows one to have fine control as to how the intersections are reported. bedtools intersect works with both @STD_BEDTOOLS_INPUT_LABEL@ and BAM files as input.
370
371.. image:: $PATH_TO_IMAGES/intersect-glyph.png
372
373.. class:: infomark
374
375Note that each BAM alignment is treated individually. Therefore, if one end of a paired-end alignment overlaps an interval in the BED file, yet the other end does not, the output file will only include the overlapping end.
376
377.. class:: infomark
378
379Note that a BAM alignment will be sent to the output file **once** even if it overlaps more than one interval in the BED file.
380
381@REFERENCES@
382 ]]></help>
383 <expand macro="citations" />
384</tool>