<tool id="qiime_multiple_join_paired_ends" name="Run join_paired_ends on multiple files" version="@WRAPPER_VERSION@.0" profile="@PROFILE@">
    <description>(multiple_join_paired_ends)</description>
    <macros>
        <import>macros.xml</import>
    </macros>
    <expand macro="requirements">
        <requirement type="package" version="1.3.1">fastq-join</requirement>
    </expand>
    <version_command>multiple_join_paired_ends.py -v</version_command>
    <command detect_errors="aggressive"><![CDATA[
@MPLBACKEND@
mkdir input
&&
#set $match_barcodes = "no"
#for $i, $s in enumerate( $input_files )
    cp '$s.r1_file' input/forward_${i}.fastq
    &&
    cp '$s.r2_file' input/reverse_${i}.fastq
    &&
    #if str($s.barcode['match_barcodes']) == 'yes'
        #set $match_barcodes = "yes"
        cp '${s.barcode.barcode_seq}' input/barcode_${i}.fastq
        &&
    #end if
#end for
multiple_join_paired_ends.py
    --input_dir 'input'
    --output_dir 'output'
    #if $parameter_fp
        --parameter_fp '$parameter_fp'
    #end if
    --read1_indicator 'forward_'
    --read2_indicator 'reverse_'
    #if str($match_barcodes) == 'yes'
        --match_barcodes
        --barcode_indicator 'barcode_'
    #end if
    --leading_text '$leading_text'
    --trailing_text '$trailing_text'
#for $i, $s in enumerate( $input_files )
    &&
    cp output/forward_${i}/fastqjoin.join.fastq output/${i}_join.fastq
    &&
    cp output/forward_${i}/fastqjoin.un1.fastq output/${i}_un1.fastq
    &&
    cp output/forward_${i}/fastqjoin.un2.fastq output/${i}_un2.fastq
    #if str($s.barcode['match_barcodes']) == 'yes'
        &&
        cp output/forward_${i}/fastqjoin.join_barcodes.fastq output/${i}_barcodes.fastq
    #end if
#end for
    ]]></command>
    <inputs>
        <repeat name="input_files" title="Input files">
            <param name="r1_file" type="data" format="fastq,fastqsanger,fastq.gz,fastqsanger.gz,fastq.bz2,fastqsanger.bz2" label="Forward reads"/>
            <param name="r2_file" type="data" format="fastq,fastqsanger,fastq.gz,fastqsanger.gz,fastq.bz2,fastqsanger.bz2" label="Reverse reads"/>
            <conditional name="barcode">
                <param argument="--match_barcodes" type="select" label="Enable searching for matching barcodes?">
                    <option value="yes">Yes</option>
                    <option value="no" selected="True">No</option>
                </param>
                <when value="yes">
                    <param name="barcode_seq" type="data" format="fastq,fastqsanger,fastq.gz,fastqsanger.gz,fastq.bz2,fastqsanger.bz2" label="Barcode sequences"/>
                </when>
                <when value="no"/>
            </conditional>
        </repeat>
        <param argument="--parameter_fp" type="data" format="txt" label="Parameter file" help="It specifies changes to the default behavior of join_paired_ends.py" optional="true"/>
        <param argument="--leading_text" type="text" value="" label="Leading text to add to each join_paired_ends command"/>
        <param argument="--trailing_text" type="text" value="" label="Trailing text to add to each join_paired_ends command"/>
    </inputs>
    <outputs>
        <collection name="joined_seq" type="list:list" label="${tool.name} on ${on_string}: Joined sequences">
            <discover_datasets pattern="(?P&lt;identifier_0&gt;.+)_(?P&lt;identifier_1&gt;.+).fastq" ext="fastq" directory="output/"/>
        </collection>
        <data name="log" format="txt" from_work_dir="output/log_*" label="${tool.name} on ${on_string}: Log"/>
    </outputs>
    <tests>
        <test>
            <repeat name="input_files">
                <param name="r1_file" value="multiple_join_paired_ends/without_barcode/forward_1.fastq"/>
                <param name="r2_file" value="multiple_join_paired_ends/without_barcode/reverse_1.fastq"/>
                <conditional name="barcode">
                    <param name="match_barcodes" value="no"/>
                </conditional>
            </repeat>
            <repeat name="input_files">
                <param name="r1_file" value="multiple_join_paired_ends/without_barcode/forward_2.fastq"/>
                <param name="r2_file" value="multiple_join_paired_ends/without_barcode/reverse_2.fastq"/>
                <conditional name="barcode">
                    <param name="match_barcodes" value="no"/>
                </conditional>
            </repeat>
            <param name="barcode_indicator" value="_I1_"/>
            <param name="leading_text" value=""/>
            <param name="trailing_text" value=""/>
            <output_collection name="joined_seq" type="list:list">
                <element name="0">
                    <element name="join" file="multiple_join_paired_ends/output_without_barcode/forward_1/fastqjoin.join.fastq"/>
                    <element name="un1" file="multiple_join_paired_ends/output_without_barcode/forward_1/fastqjoin.un1.fastq"/>
                    <element name="un2" file="multiple_join_paired_ends/output_without_barcode/forward_1/fastqjoin.un2.fastq"/>
                </element>
                <element name="1">
                    <element name="join" file="multiple_join_paired_ends/output_without_barcode/forward_2/fastqjoin.join.fastq"/>
                    <element name="un1" file="multiple_join_paired_ends/output_without_barcode/forward_2/fastqjoin.un1.fastq"/>
                    <element name="un2" file="multiple_join_paired_ends/output_without_barcode/forward_2/fastqjoin.un2.fastq"/>
                </element>
            </output_collection>
        </test>
        <test>
            <repeat name="input_files">
                <param name="r1_file" value="multiple_join_paired_ends/with_barcode/forward_1.fastq"/>
                <param name="r2_file" value="multiple_join_paired_ends/with_barcode/reverse_1.fastq"/>
                <conditional name="barcode">
                    <param name="match_barcodes" value="yes"/>
                    <param name="barcode_seq" value="multiple_join_paired_ends/with_barcode/barcode_1.fastq"/>
                </conditional>
            </repeat>
            <repeat name="input_files">
                <param name="r1_file" value="multiple_join_paired_ends/with_barcode/forward_2.fastq"/>
                <param name="r2_file" value="multiple_join_paired_ends/with_barcode/reverse_2.fastq"/>
                <conditional name="barcode">
                    <param name="match_barcodes" value="yes"/>
                    <param name="barcode_seq" value="multiple_join_paired_ends/with_barcode/barcode_2.fastq"/>
                </conditional>
            </repeat>
            <param name="leading_text" value=""/>
            <param name="trailing_text" value=""/>
            <output_collection name="joined_seq" type="list:list">
                <element name="0">
                    <element name="join" file="multiple_join_paired_ends/output_with_barcode/forward_1/fastqjoin.join.fastq"/>
                    <element name="un1" file="multiple_join_paired_ends/output_with_barcode/forward_1/fastqjoin.un1.fastq"/>
                    <element name="un2" file="multiple_join_paired_ends/output_with_barcode/forward_1/fastqjoin.un2.fastq"/>
                </element>
                <element name="1">
                    <element name="join" file="multiple_join_paired_ends/output_with_barcode/forward_2/fastqjoin.join.fastq"/>
                    <element name="un1" file="multiple_join_paired_ends/output_with_barcode/forward_2/fastqjoin.un1.fastq"/>
                    <element name="un2" file="multiple_join_paired_ends/output_with_barcode/forward_2/fastqjoin.un2.fastq"/>
                </element>
            </output_collection>
        </test>
    </tests>
    <help><![CDATA[
**What it does**

In addition to using PCoA, it can be useful to cluster samples using UPGMA (Unweighted Pair Group Method with Arithmetic mean, also known as average linkage). As with PCoA, the input to this step is a distance matrix (i.e. resulting file from beta_diversity.py).
The output is a newick formatted tree compatible with most standard tree viewing programs. Batch processing is also available, allowing the analysis of an entire directory of distance matrices.
    ]]></help>
    <citations>
        <expand macro="citations"/>
    </citations>
</tool>
