<tool id="deeptools_multi_bigwig_summary" name="multiBigwigSummary" version="@TOOL_VERSION@+galaxy0" profile="@GALAXY_VERSION@">
    <description>calculates average scores for a list of two or more bigwig files</description>
    <macros>
        <token name="@BINARY@">multiBigwigSummary</token>
        <import>deepTools_macros.xml</import>
    </macros>
    <expand macro="requirements" />
    <command>
<![CDATA[
        #set files=[]
        #set labels=[]

        @multiple_input_bigwigs@
        @BINARY@
            $mode.modeOpt

            @THREADS@

            --outFileName $outFile

            --bwfiles #echo ' '.join($files)#
            
            #if $custom_sample_labels_conditional.custom_labels_select == 'Yes'
                --labels #echo ' '.join($custom_sample_labels_conditional.labels)#
            #end if
            #if $outRawCounts:
                --outRawCounts '$outFileRawCounts'
            #end if

            #if $mode.modeOpt == "bins":
                --binSize '$mode.binSize'
                --distanceBetweenBins '$mode.distanceBetweenBins'
            #else:
                --BED $mode.region_file
            #end if

            #if str($region.value) != '':
                --region '$region'
            #end if

            #if $advancedOpt.showAdvancedOpt == "yes":
                @ADVANCED_OPTS_GTF@
                @blacklist@
            #end if
]]>
    </command>
    <inputs>
        <expand macro="multiple_input_bigwigs" MIN="2" LABEL="Bigwig files" TITLE="BigWig files"/>
        <expand macro="custom_sample_labels" />

        <conditional name="mode">
            <param name="modeOpt" type="select" label="Choose computation mode"
                help="In the bins mode, the correlation is computed using equally sized bins.
                In the BED file mode, a list of genomic regions in BED format has to be given.
                For each region in the BED file, the number of overlapping reads is counted in
                each of the BigWig files. Then the correlation is computed.">
                <option value="bins" selected="true">Bins</option>
                <option value="BED-file">Limit correlation to certain regions (BED file)</option>
            </param>
            <when value="bins">
                <param name="binSize" type="integer" value="10000" min="1"
                    label="Bin size in bp"
                    help="Length in bases for a window used to sample the genome. (--binSize)"/>

                <expand macro="distanceBetweenBins" />
            </when>
            <when value="BED-file">
                <param name="region_file" type="data" format="bed,gtf"
                    label="Region file in BED format"
                    help="Correlation is computed for the number of reads that overlap such regions."/>
            </when>
        </conditional>
        <expand macro="region_limit_operation" />
        <param argument="--outRawCounts" type="boolean" label="Save raw counts (scores) to file" help=""/>

        <expand macro="advancedOpt_scaffold">
            <expand macro="gtf_options" />
            <expand macro="blacklist" />
        </expand>

    </inputs>
    <outputs>
        <data format="deeptools_coverage_matrix" name="outFile" label="${tool.name} on ${on_string}: correlation matrix" />
        <data format="tabular" name="outFileRawCounts" label="${tool.name} on ${on_string}: bin counts">
            <filter>outRawCounts is True</filter>
        </data>
    </outputs>
    <tests>
        <test>
            <param name="bigwigfiles" value="test.bw,test.bw" ftype="bigwig" />
            <param name="modeOpt" value="bins" />
            <param name="binSize" value="10" />
            <output name="outFile" file="multiBigwigSummary_result1.npz" ftype="deeptools_coverage_matrix" compare="sim_size" />
        </test>
        <test>
            <param name="bigwigfiles" value="test.bw,test.bw" ftype="bigwig" />
            <param name="modeOpt" value="bins" />
            <param name="binSize" value="10" />
            <param name="outRawCounts" value="True" />
            <conditional name="custom_sample_labels_conditional">
                <param name="custom_labels_select" value="Yes"/>
                <param name="labels" value="sample1 sample2"/>
            </conditional>
            <output name="outFileRawCounts" file="multiBigwigSummary_result2.tabular" ftype="tabular" />
            <output name="outFile" file="multiBigwigSummary_result2.npz" ftype="deeptools_coverage_matrix" compare="sim_size" />
        </test>
    </tests>
    <help>
<![CDATA[

What it does
--------------

This tool computes the average scores for every genomic region for every bigWig file that is provided. In principle, it does the same as ``multiBamSummary``, but for bigWig files.

The analysis is performed for the entire genome by running the program in 'bins' mode, or for certain user selected regions (e.g., genes) in 'BED-file' mode.

Typically the output of ``multiBigwigSummary`` is used by other tools, such as ``plotCorrelation`` or ``plotPCA``, for visualization and diagnostic purposes.


Output
--------

The default output is a **compressed file** that can only be used with ``plotPCA`` or ``plotCorrelation``.

To analyze the average scores yourself, you can get the **uncompressed score matrix** where every row corresponds to a genomic region (or bin) and each column corresponds to a sample (BAM file). (To obtain this output file, select "Save raw counts (coverages) to file" )

.. image:: $PATH_TO_IMAGES/multiBigwigSummary_output.png
   :width: 600
   :height: 358

-----

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