view intersectBed.xml @ 43:07e8b80f278c draft

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bedtools commit db0b91a784ca0c216345bc488d7d488babf1b53f"
author iuc
date Fri, 01 Apr 2022 19:02:51 +0000
parents 7ab85ac5f64b
children
line wrap: on
line source

<tool id="bedtools_intersectbed" name="bedtools Intersect intervals" version="@TOOL_VERSION@+galaxy1" profile="@PROFILE@">
    <description>find overlapping intervals in various ways</description>
    <macros>
        <import>macros.xml</import>
    </macros>
    <expand macro="bio_tools" />
    <expand macro="requirements">
        <requirement type="package" version="@SAMTOOLS_VERSION@">samtools</requirement>
    </expand>
    <expand macro="stdio" />
    <command><![CDATA[
#import re
#set modes = ' '.join(str($overlap_mode).split(','))

#if $modes == "None":
    #set modes = ''
#end if

bedtools intersect
-a '${inputA}'

#if str($reduce_or_iterate.reduce_or_iterate_selector) == 'iterate':
    -b '$reduce_or_iterate.inputB'
#else:
    -b
    #for $file in $reduce_or_iterate.inputB
        '$file'
    #end for

    #if $reduce_or_iterate.names:
        #set namesB = "' '".join([re.sub('[^\s\w\-]', '_', str($file.element_identifier)) for $file in $reduce_or_iterate.inputB])
        -names '$namesB'
    #end if
#end if
$split
$strand
#if $fraction_cond.fraction_select == "specify":
    #if str($fraction_cond.overlap)
        -f $fraction_cond.overlap
    #end if
    $fraction_cond.reciprocal_cond.reciprocal
    #if str($fraction_cond.reciprocal_cond.reciprocal) == '':
        #if str($fraction_cond.reciprocal_cond.overlapB):
            -F $fraction_cond.reciprocal_cond.overlapB
        #end if
        $fraction_cond.reciprocal_cond.disjoint
    #end if
#end if
$invert
$once
$header
$modes
@SORTED@
@GENOME_FILE@
$bed
$count
> '${output}'
    ]]></command>
    <inputs>
        <param name="inputA" type="data" format="bam,@STD_BEDTOOLS_INPUTS@" label="File A to intersect with B" help="BAM/@STD_BEDTOOLS_INPUT_LABEL@ format" />
        <conditional name="reduce_or_iterate">
            <param name="reduce_or_iterate_selector" type="select" label="Combined or separate output files">
                <option value="iterate" selected="true">One output file per 'input B' file</option>
                <option value="reduce">Single output containing intersections of any 'input B' lines with A</option>
            </param>
            <when value="iterate">
                <param name="inputB" argument="-b" type="data" format="bam,@STD_BEDTOOLS_INPUTS@"
                       label="File B to intersect with A" help="BAM/@STD_BEDTOOLS_INPUT_LABEL@ format"/>
            </when>
            <when value="reduce">
                <param name="inputB" argument="-b" type="data" format="bam,@STD_BEDTOOLS_INPUTS@" multiple="true"
                       label="File(s) B to intersect with A" help="BAM/@STD_BEDTOOLS_INPUT_LABEL@ format"/>
                <param argument="-names" type="boolean" truevalue="yes" falsevalue="no" label="Add data set names instead of indices" />
            </when>
        </conditional>
        <expand macro="strand2" />
        <param name="overlap_mode" type="select" multiple="true" label="What should be written to the output file?">
            <option value="-wa">Write the original entry in A for each overlap (-wa)</option>
            <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>
            <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>
            <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>
            <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>
        </param>

        <expand macro="split" />
        <conditional name="fraction_cond">
            <param name="fraction_select" type="select" label="Required overlap">
                <option value="default" selected="true">Default: 1bp</option>
                <option value="specify">Specify minimum overlap(s)</option>
            </param>
            <when value="default"/>
            <when value="specify">
                <expand macro="overlap" />
                <conditional name="reciprocal_cond">
                    <expand macro="reciprocal" />
                <when value="-r"/>
                <when value="">
                    <expand macro="overlap" name="overlapB" argument="-F" fracof="B"/>
                    <param name="disjoint" argument="-e" type="boolean" truevalue="-e"  falsevalue="" checked="false"
                        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."/>
                </when>
            </conditional>
            </when>
        </conditional>
        <!-- -v -->
        <param name="invert" argument="-v" type="boolean" truevalue="-v" falsevalue="" checked="false"
            label="Report only those alignments that **do not** overlap with file(s) B" />
        <!-- -u -->
        <param name="once" argument="-u" type="boolean" truevalue="-u" falsevalue="" checked="false"
            label="Write the original A entry _once_ if _any_ overlaps found in B."
            help="Just report the fact >=1 hit was found" />
        <!-- -c -->
        <param name="count" argument="-c" type="boolean" truevalue="-c" falsevalue="" checked="false"
            label="For each entry in A, report the number of overlaps with B."
            help="Reports 0 for A entries that have no overlap with B" />
        <!-- -bed -->
        <param argument="-bed" type="boolean" truevalue="-bed" falsevalue="" checked="false"
            label="When using BAM input, write output as BED instead of BAM." />
        <!-- -sorted -g  -->
        <expand macro="sorted" />
        <expand macro="input_conditional_genome_file" optional="true" help="Only applies when used with -sorted option."/>
        <expand macro="print_header" />
    </inputs>
    <outputs>
        <data name="output" format_source="inputA" metadata_source="inputA">
            <change_format>
                <when input="bed" value="-bed" format="bed" />
            </change_format>
        </data>
    </outputs>
    <tests>
        <!-- test adapted from the tutorial https://bedtools.readthedocs.io/en/latest/content/tools/intersect.html -->
        <test>
            <param name="inputA" value="intersect-A.bed" ftype="bed" />
            <conditional name="reduce_or_iterate">
                <param name="reduce_or_iterate_selector" value="iterate" />
                <param name="inputB" value="intersect-B.bed" ftype="bed" />
            </conditional>
            <output name="output" file="intersect-default.bed" ftype="bed" />
        </test>
        <test>
            <param name="inputA" value="intersect-query.bed" ftype="bed" />
            <conditional name="reduce_or_iterate">
                <param name="reduce_or_iterate_selector" value="reduce" />
                <param name="inputB" value="intersect-d1.bed,intersect-d2.bed,intersect-d3.bed" ftype="bed" />
            </conditional>
            <output name="output" file="intersect-multiple.bed" ftype="bed" />
        </test>
        <test>
            <param name="inputA" value="intersect-query.bed" ftype="bed" />
            <conditional name="reduce_or_iterate">
                <param name="reduce_or_iterate_selector" value="reduce" />
                <param name="inputB" value="intersect-d1.bed,intersect-d2.bed,intersect-d3.bed" ftype="bed" />
            </conditional>
            <param name="overlap_mode" value="-wa,-wb" />
            <param name="sorted" value="true" />
            <output name="output" file="intersect-multiple-wa-wb.bed" ftype="bed" />
        </test>
        <test>
            <param name="inputB" value="intersect-d1.bed,intersect-d2.bed,intersect-d3.bed" ftype="bed" />
            <param name="inputA" value="intersect-query.bed" ftype="bed" />
            <conditional name="reduce_or_iterate">
                <param name="reduce_or_iterate_selector" value="reduce" />
                <param name="inputB" value="intersect-d1.bed,intersect-d2.bed,intersect-d3.bed" ftype="bed" />
                <param name="names" value="yes" />
            </conditional>
            <param name="overlap_mode" value="-wa,-wb" />
            <param name="sorted" value="true" />
            <output name="output" file="intersect-multiple-wa-wb-wnames.bed" ftype="bed" />
        </test>
        <test>
            <param name="inputA" value="intersect-query.bed" ftype="bed" />
            <conditional name="reduce_or_iterate">
                <param name="reduce_or_iterate_selector" value="reduce" />
                <param name="inputB" value="intersect-d1.bed,intersect-d2.bed,intersect-d3.bed" ftype="bed" />
            </conditional>
            <param name="invert" value="-v" />
            <param name="sorted" value="true" />
            <output name="output" file="intersect-multiple-invert.bed" ftype="bed" />
        </test>
        <test>
            <param name="inputA" value="intersect-query.bed" ftype="bed" />
            <conditional name="reduce_or_iterate">
                <param name="reduce_or_iterate_selector" value="reduce" />
                <param name="inputB" value="intersect-d1.bed,intersect-d2.bed,intersect-d3.bed" ftype="bed" />
            </conditional>
            <param name="overlap_mode" value="-wa,-wb" />
            <conditional name="fraction_cond">
                <param name="fraction_select" value="specify"/>
                <param name="overlap" value="1.0" />
            </conditional>
            <param name="sorted" value="true" />
            <output name="output" file="intersect-multiple-fracA.bed" ftype="bed" />
        </test>
        <test>
            <param name="inputA" value="intersect-A.bed" ftype="bed" />
            <conditional name="reduce_or_iterate">
                <param name="reduce_or_iterate_selector" value="iterate" />
                <param name="inputB" value="intersect-B.bed" ftype="bed" />
            </conditional>
            <param name="overlap_mode" value="-wa" />
            <output name="output" file="intersect-wa.bed" ftype="bed" />
        </test>
        <test>
            <param name="inputA" value="intersect-A.bed" ftype="bed" />
            <conditional name="reduce_or_iterate">
                <param name="reduce_or_iterate_selector" value="iterate" />
                <param name="inputB" value="intersect-B.bed" ftype="bed" />
            </conditional>
            <param name="overlap_mode" value="-wb" />
            <output name="output" file="intersect-wb.bed" ftype="bed" />
        </test>
        <test>
            <param name="inputA" value="intersect-A.bed" ftype="bed" />
            <conditional name="reduce_or_iterate">
                <param name="reduce_or_iterate_selector" value="iterate" />
                <param name="inputB" value="intersect-B.bed" ftype="bed" />
            </conditional>
            <param name="overlap_mode" value="-wa,-wb" />
            <output name="output" file="intersect-wa-wb.bed" ftype="bed" />
        </test>
        <test>
            <param name="inputA" value="intersect-A.bed" ftype="bed" />
            <conditional name="reduce_or_iterate">
                <param name="reduce_or_iterate_selector" value="iterate" />
                <param name="inputB" value="intersect-B.bed" ftype="bed" />
            </conditional>
            <param name="overlap_mode" value="-loj" />
            <output name="output" file="intersect-loj.bed" ftype="bed" />
        </test>
        <test>
            <param name="inputA" value="intersect-A.bed" ftype="bed" />
            <conditional name="reduce_or_iterate">
                <param name="reduce_or_iterate_selector" value="iterate" />
                <param name="inputB" value="intersect-B.bed" ftype="bed" />
            </conditional>
            <param name="overlap_mode" value="-wo" />
            <output name="output" file="intersect-wo.bed" ftype="bed" />
        </test>
        <test>
            <param name="inputA" value="intersect-A.bed" ftype="bed" />
            <conditional name="reduce_or_iterate">
                <param name="reduce_or_iterate_selector" value="iterate" />
                <param name="inputB" value="intersect-B.bed" ftype="bed" />
            </conditional>
            <param name="overlap_mode" value="-wao" />
            <output name="output" file="intersect-wao.bed" ftype="bed" />
        </test>
        <test>
            <param name="inputA" value="intersect-A.bed" ftype="bed" />
            <conditional name="reduce_or_iterate">
                <param name="reduce_or_iterate_selector" value="iterate" />
                <param name="inputB" value="intersect-B.bed" ftype="bed" />
            </conditional>
            <param name="once" value="-u" />
            <output name="output" file="intersect-unique.bed" ftype="bed" />
        </test>
        <test>
            <param name="inputA" value="intersect-A.bed" ftype="bed" />
            <conditional name="reduce_or_iterate">
                <param name="reduce_or_iterate_selector" value="iterate" />
                <param name="inputB" value="intersect-B.bed" ftype="bed" />
            </conditional>
            <param name="count" value="-c"/>
            <output name="output" file="intersect-count.bed" ftype="bed" />
        </test>
        <test>
            <param name="inputA" value="intersect-A.bed" ftype="bed" />
            <conditional name="reduce_or_iterate">
                <param name="reduce_or_iterate_selector" value="iterate" />
                <param name="inputB" value="intersect-B.bed" ftype="bed" />
            </conditional>
            <param name="invert" value="-v"/>
            <output name="output" file="intersect-invert.bed" ftype="bed" />
        </test>
        <test>
            <param name="inputA" value="intersect-A2.bed" ftype="bed" />
            <conditional name="reduce_or_iterate">
                <param name="reduce_or_iterate_selector" value="iterate" />
                <param name="inputB" value="intersect-B2.bed" ftype="bed" />
            </conditional>
            <param name="overlap_mode" value="-wa,-wb" />
            <conditional name="fraction_cond">
                <param name="fraction_select" value="specify"/>
                <param name="overlap" value="0.5" />
            </conditional>
            <output name="output" file="intersect-fracA.bed" ftype="bed" />
        </test>
        <test>
            <param name="inputA" value="intersect-A2.bed" ftype="bed" />
            <conditional name="reduce_or_iterate">
                <param name="reduce_or_iterate_selector" value="iterate" />
                <param name="inputB" value="intersect-B2.bed" ftype="bed" />
            </conditional>
            <param name="overlap_mode" value="-wa,-wb" />
            <conditional name="fraction_cond">
                <param name="fraction_select" value="specify"/>
                <param name="overlap" value="0.5" />
                <conditional name="reciprocal_cond">
                    <param name="reciprocal" value="-r" />
                </conditional>
            </conditional>
            <output name="output" file="intersect-fracA-rec.bed" ftype="bed" />
        </test>
        <test>
            <param name="inputA" value="intersect-A2.bed" ftype="bed" />
            <conditional name="reduce_or_iterate">
                <param name="reduce_or_iterate_selector" value="iterate" />
                <param name="inputB" value="intersect-B2.bed" ftype="bed" />
            </conditional>
            <param name="overlap_mode" value="-wa,-wb" />
            <conditional name="fraction_cond">
                <param name="fraction_select" value="specify"/>
                <param name="overlap" value="0.5" />
                <conditional name="reciprocal_cond">
                    <param name="overlapB" value="0.5" />
                </conditional>
            </conditional>
            <output name="output" file="intersect-fracA-rec.bed" ftype="bed" />
        </test>
        <test>
            <param name="inputA" value="intersect-A2.bed" ftype="bed" />
            <conditional name="reduce_or_iterate">
                <param name="reduce_or_iterate_selector" value="iterate" />
                <param name="inputB" value="intersect-B2.bed" ftype="bed" />
            </conditional>
            <param name="overlap_mode" value="-wa,-wb" />
            <conditional name="fraction_cond">
                <param name="fraction_select" value="specify"/>
                <param name="overlap" value="0.5" />
                <conditional name="reciprocal_cond">
                    <param name="overlapB" value="0.5" />
                    <param name="disjoint" value="-e" />
                </conditional>
            </conditional>
            <output name="output" file="intersect-fracA.bed" ftype="bed" />
        </test>
        <!-- old tests -->
        <test>
            <param name="inputA" value="intersectBed1.bed" ftype="bed" />
            <param name="inputB" value="intersectBed2.bed" ftype="bed" />
            <param name="overlap_mode" value="-wa" />
            <param name="split" value="False" />
            <output name="output" file="intersectBed_result1.bed" ftype="bed" />
        </test>
        <test>
            <param name="inputA" value="intersectBed1.bed" ftype="bed" />
            <param name="inputB" value="intersectBed2.bed" ftype="bed" />
            <param name="overlap_mode" value="-wa,-wb" />
            <param name="split" value="False" />
            <output name="output" file="intersectBed_result2.bed" ftype="bed" />
        </test>
        <test>
            <param name="inputA" value="intersectBed1.bed" ftype="bed" />
            <param name="inputB" value="intersectBed2.bed" ftype="bed" />
            <param name="invert" value="True" />
            <param name="split" value="False" />
            <output name="output" file="intersectBed_result3.bed" ftype="bed" />
        </test>
    </tests>
    <help><![CDATA[
**What it does**

By 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.

.. image:: $PATH_TO_IMAGES/intersect-glyph.png

.. class:: infomark

Note 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.

.. class:: infomark

Note that a BAM alignment will be sent to the output file **once** even if it overlaps more than one interval in the BED file.

@REFERENCES@
    ]]></help>
    <expand macro="citations" />
</tool>