<macros>

    <token name="@PROFILE@">23.1</token>

    <xml name="discosnp_requirements">
        <requirements>
            <requirement type="package" version="@TOOL_VERSION@">discosnp</requirement>
        </requirements>
    </xml>

    <token name="@discosnp_single_for@"><![CDATA[
        #for $input in $input_type_options.list_reads:
    ]]></token>

    <token name="@discosnp_single_end_for@"><![CDATA[
            echo '${filename}' >> input.lst &&
        #end for
    ]]></token>

    <token name="@single_reads@"><![CDATA[
        #import re
        #set $base_filename = re.sub('[^\w_]', '_', $input.element_identifier)
        #if $input.ext.startswith('fasta'):
            #set filename = $base_filename + ".fasta"
        #else:
            #set filename = $base_filename + ".fastq"
        #end if
        #if $input.ext.endswith('.gz'):
            gunzip -c '${input}' > '${filename}' &&
        #else:
            ln -sf '${input}' '${filename}' &&
        #end if
    ]]></token>

    <token name="@discosnp_paired_for@"><![CDATA[
        #for $i, $paired in enumerate($input_type_options.list_paired_reads):
    ]]></token>

    <token name="@discosnp_paired_end_for@"><![CDATA[
            echo '${forward}' > "paired_${i}.lst" &&
            echo '${reverse}' >> "paired_${i}.lst" &&
            echo "paired_${i}.lst" >> input.lst &&
        #end for
    ]]></token>

    <token name="@paired_reads@"><![CDATA[
        #set $base_forward = re.sub('[^\w_]', '_', $paired.forward.element_identifier)
        #if $paired.forward.ext.startswith('fasta'):
            #set forward = $base_forward + ".fasta"
        #else:
            #set forward = $base_forward + ".fastq"
        #end if
        #if $paired.forward.ext.endswith('.gz'):
            gunzip -c '$paired.forward' > '$forward' &&
        #else:
            ln -sf '${paired.forward}' '$forward' &&
        #end if

        #set $base_reverse = re.sub('[^\w_]', '_', $paired.reverse.element_identifier)
        #if $paired.reverse.ext.startswith('fasta'):
            #set reverse = $base_reverse + ".fasta"
        #else:
            #set reverse = $base_reverse + ".fastq"
        #end if
        #if $paired.reverse.ext.endswith('.gz'):
            gunzip -c '$paired.reverse' > '$reverse' &&
        #else:
            ln -sf '${paired.reverse}' '$reverse' &&
        #end if
    ]]></token>

    <xml name="discosnp_inputs">
        <conditional name="input_type_options">
            <param name="input_type" type="select" label="Input options">
                <option value="single">Single end reads</option>
                <option value="paired">Paired end reads</option>
                <option value="mix">Both single and paired reads</option>
            </param>
            <when value="single">
                <param name='list_reads' argument="-r" format="fasta,fasta.gz,fastq,fastq.gz" type="data" multiple="true" label="Single read files" />
            </when>
            <when value="paired">
                <param name='list_paired_reads' argument="-r" format="fasta,fasta.gz,fastq,fastq.gz" type="data_collection" collection_type="list:paired" multiple='true' label="List of paired read files" />
            </when>
            <when value="mix">
                <param name='list_reads' argument="-r" format="fasta,fasta.gz,fastq,fastq.gz" type="data" multiple="true" label="Single read files" />
                <param name='list_paired_reads' argument="-r" format="fasta,fasta.gz,fastq,fastq.gz" type="data_collection" collection_type="list:paired" multiple='true' label="List of paired read files"/>
            </when>
        </conditional>
    </xml>

    <xml name="discosnp_options">
        <param argument="-D" type="integer" label="Deletion size" value="0" help="If different of 0, discoSnp will search for deletions of size from 1 to D included"/>
        <param argument="-P" type="integer" label="Maximum SNPs per bubble" value="1" help="discoSnp will search up to P SNPs in a unique bubble"/>
        <param name="low_complexity" type="boolean" checked="false" truevalue="-l" falsevalue="" label="Remove low complexity bubbles" />
        <param argument="-k" type="integer" label="Size of kmers" value="31" />

        <conditional name="coverage_options_type" >
            <param name="coverage_options" type="select" label="Coverage option">
                <option value="auto"></option>
                <option value="custom"></option>
            </param>
            <when value="auto" />
            <when value="custom">
                <param argument="-c" type="text" label="Minimal coverage per read set" value="3" help="e.g. 3 / 3,5,17 / 3,auto,auto"/>
            </when>
        </conditional>

        <param argument="-C" type="integer" label="Maximal coverage per read set" value="2147483647" help="default value = 2^31-1" />
        <param argument="-d" type="integer" label="Max number of errors per read" value="1" help="Max number of errors per read" />

    </xml>

    <token name="@discosnp_inputs@"><![CDATA[
        -r input.lst
        -D ${D}
        -P ${P}
        ${low_complexity}
        -k ${k}

        #if str($coverage_options_type.coverage_options) == 'auto'
            -c auto
        #else
            -c '${coverage_options_type.c}'
        #end if
        -C ${C}
        -d ${d}
    ]]></token>

    <token name="@lordec_inputs@"><![CDATA[
        -2 "${ ",".join(['%s' % file for file in $program_type_choice.inputs]) }"
        -i '${program_type_choice.i}'
        -k ${program_type_choice.k}
        -s ${program_type_choice.s}
    ]]></token>

    <xml name="lordec_inputs">
        <param name="inputs" argument="-2" type="data" format="fasta,fastq.gz,fastq,fastq.gz" multiple="true" label="Short read FASTA/Q files" />
        <param argument="-i" type="data" format="fasta,fastq.gz,fastq,fastq.gz" label="Long read FASTA/Q file" help="PacBio reads files" />
        <param argument="-k" type="integer" label="Size of kmers" value="31" help="Only uneven number"/>
        <param argument="-s" type="integer" label="Solidity abundance threshold for k-mers" value="4" />
    </xml>

    <token name="@discosnp_help@"><![CDATA[
-------

.. class:: warningmark

**Input parameters**

-Sequences files in fasta or fastq each allele will be counted in each file individually

-Use collections: data list and/or data list paired

-Fasta sequence of a genome if case of you are willing to map the sequence extension on a reference in order to get a compliant VCF

-------

.. class:: warningmark

**Ouput parameters**

-VCF file with coordinates on the higher branch sequences or on a reference genome if provided

-Fasta file with sequence extensions around the SNP.


-------

**Web site**

https://colibread.inria.fr/software/discosnp/

    ]]></token>

    <xml name="citations">
        <citations>
            <yield/>
            <citation type="doi">10.1186/s13742-015-0105-2</citation>
        </citations>
    </xml>

    <xml name="discosnp_citation">
        <citation type="doi">10.1101/209965</citation>
    </xml>

</macros>
