<tool id="pick_closed_reference_otus" name="Perform closed-reference OTU picking" version="@WRAPPER_VERSION@.0">
    <description></description>
    <macros>
        <import>macros.xml</import>
    </macros>
    <expand macro="requirements"/>
    <version_command>pick_closed_reference_otus.py --version</version_command>
    <command detect_errors="aggressive"><![CDATA[
        pick_closed_reference_otus.py
            --input_fp '$input_fp'
            --output_dir otus
            #if str( $ref_seq.selector ) == 'history'
                #set $ref = $ref_seq.reference_fp
            #else
                #set $ref = $ref_seq.reference_fp.fields.path
            #end if
            --reference_fp '$ref'
            #if str( $taxonomy.selector ) == 'taxonomy_map'
                #if str( $taxonomy.taxo_map.selector ) == 'history'
                    #set $taxonomy = $taxonomy.taxo_map.taxonomy_fp
                #else
                    #set $taxonomy = $taxonomy.taxo_map.taxonomy_fp.fields.path
                #end if
                --taxonomy_fp '$taxonomy'
            #else if str( $taxonomy.selector ) == 'assign_taxonomy'
                --assign_taxonomy
            #else if str( $taxonomy.selector ) == 'suppress_taxonomy_assignment'
                --suppress_taxonomy_assignment
            #end if
            #if $parameter_fp
                --parameter_fp '$parameter_fp'
            #end if
            $parallel
            -O "\${GALAXY_SLOTS:-4}"
    ]]></command>
    <inputs>
        <param argument="--input_fp" type="data" format="fasta" label="Input sequence file"/>
        <conditional name="ref_seq">
            <param name="selector" type="select" label="Reference sequences to query">
                <option value="cached" selected="True">Public databases</option>
                <option value="history">Databases from your history</option>
            </param>
            <when value="cached">
                <param argument="--reference_fp" label="Reference sequences" type="select">
                    <options from_data_table="qiime_rep_set"/>
                </param>            
            </when>
            <when value="history">
                <param argument="--reference_fp" type="data" format="fasta" label="Reference databases"/>
            </when>
        </conditional>
        <conditional name="taxonomy">
            <param name="selector" type="select"  label="Assign taxonomy?">
                <option value="taxonomy_map" selected="True">Assign taxonomy using a taxonomy map</option>
                <option value="assign_taxonomy">Assign taxonomy to each sequence using assign_taxonomy.py</option>
                <option value="suppress_taxonomy_assignment">Skip the taxonomy assignment step</option>
            </param>
            <when value="taxonomy_map">
                <conditional name="taxo_map">
                    <param name="selector" type="select" label="Taxonomy map to use">
                        <option value="cached" selected="True">Public taxonomy map</option>
                        <option value="history">Taxonomy map from your history</option>
                    </param>
                    <when value="cached">
                        <param argument="--taxonomy_fp" label="Taxonomy map" type="select">
                            <options from_data_table="qiime_taxonomy"/>
                        </param>
                    </when>
                    <when value="history">
                        <param argument="--taxonomy_fp" type="data" format="txt" label="Taxonomy map"/>
                    </when>
                </conditional>
            </when>
            <when value="assign_taxonomy"/>
            <when value="suppress_taxonomy_assignment"/>
        </conditional>
        <param argument="--parameter_fp" type="data" format="txt" optional="true" label="Parameter file" help="It specifies changes to the default behavior"/>
        <param argument="--parallel" type="boolean" truevalue="--parallel" falsevalue="" checked="True" label="Run in parallel where available?"/>
    </inputs>
    <outputs>
        <data name="otu_table" format="biom1" from_work_dir="otus/otu_table.biom" label="${tool.name} on ${on_string}: OTU table"/>
    </outputs>
    <tests>
        <test>
            <param name="input_fps" value="pick_closed_reference_otus/seqs.fna"/>
            <conditional name="ref_seq">
                <param name="selector" value="history"/>
                <param name="reference_fp" value="pick_closed_reference_otus/refseqs.fna"/>
            </conditional>
            <conditional name="taxonomy">
                <param name="selector" value="taxonomy_map"/>
                <conditional name="taxo_map">
                    <param name="selector" value="history"/>
                    <param name="taxonomy_fp" value="pick_closed_reference_otus/taxa.txt"/>
                </conditional>
            </conditional>
            <param name="parallel" value=""/>
            <output name="otu_table" file="pick_closed_reference_otus/basic_otu_table.biom" compare="sim_size" />
        </test>
        <test>
            <param name="input_fps" value="pick_closed_reference_otus/seqs.fna"/>
            <conditional name="ref_seq">
                <param name="selector" value="history"/>
                <param name="reference_fp" value="pick_closed_reference_otus/refseqs.fna"/>
            </conditional>
            <conditional name="taxonomy">
                <param name="selector" value="taxonomy_map"/>
                <conditional name="taxo_map">
                    <param name="selector" value="history"/>
                    <param name="taxonomy_fp" value="pick_closed_reference_otus/taxa.txt"/>
                </conditional>
            </conditional>
            <param name="parameter_fp" value="pick_closed_reference_otus/sortmerna_params.txt"/>
            <param name="parallel" value=""/>
            <output name="otu_table" file="pick_closed_reference_otus/sortmerna_otu_table.biom" compare="sim_size" />
        </test>
        <test>
            <param name="input_fps" value="pick_closed_reference_otus/seqs.fna"/>
            <conditional name="ref_seq">
                <param name="selector" value="history"/>
                <param name="reference_fp" value="pick_closed_reference_otus/refseqs.fna"/>
            </conditional>
            <conditional name="taxonomy">
                <param name="selector" value="assign_taxonomy"/>
            </conditional>
            <param name="parallel" value=""/>
            <output name="otu_table" file="pick_closed_reference_otus/assign_taxonomy_otu_table.biom" compare="sim_size" />
        </test>
        <test>
            <param name="input_fps" value="pick_closed_reference_otus/seqs.fna"/>
            <conditional name="ref_seq">
                <param name="selector" value="history"/>
                <param name="reference_fp" value="pick_closed_reference_otus/refseqs.fna"/>
            </conditional>
            <conditional name="taxonomy">
                <param name="selector" value="suppress_taxonomy_assignment"/>
            </conditional>
            <param name="parallel" value=""/>
            <output name="otu_table" file="pick_closed_reference_otus/suppress_taxonomy_assignment_otu_table.biom" compare="sim_size" />
        </test>
    </tests>
    <help><![CDATA[
**What it does**

This script picks OTUs using a closed reference and constructs an OTU table. Taxonomy is assigned using a pre-defined taxonomy map of reference sequence OTU to taxonomy. If full-length genomes are provided as the reference sequences, this script applies the Shotgun UniFrac method.

More information about this tool is available on
`QIIME documentation <http://qiime.org/scripts/pick_closed_reference_otus.html>`_.
]]></help>
    <citations>
        <expand macro="citations"/>
    </citations>
</tool>
