<tool id="qiime_alpha_rarefaction" name="Perform alpha rarefaction" version="@WRAPPER_VERSION@.0" profile="@PROFILE@">
    <description>(alpha_rarefaction)</description>
    <macros>
        <import>macros.xml</import>
    </macros>
    <expand macro="requirements"/>
    <version_command>alpha_rarefaction.py --version</version_command>
    <command detect_errors="aggressive"><![CDATA[
@MPLBACKEND@
alpha_rarefaction.py
    --otu_table_fp '$otu_table_fp'
    --mapping_fp '$mapping_fp'
    -o alpha_rarefaction
    #if $parameter_fp
        --parameter_fp '$parameter_fp'
    #end if
    --num_steps '$num_steps'
    $parallel
    -O "\${GALAXY_SLOTS:-4}"
    #if $tree_fp
        --tree_fp '$tree_fp'
    #end if
    --min_rare_depth '$min_rare_depth'
    #if $max_rare_depth
        --max_rare_depth '$max_rare_depth'
    #end if
    $retain_intermediate_files

&& mkdir -p $alpha_rarefaction_plots.files_path
&& cp alpha_rarefaction/alpha_rarefaction_plots/rarefaction_plots.html $alpha_rarefaction_plots
&& cp -r alpha_rarefaction/alpha_rarefaction_plots/average_plots $alpha_rarefaction_plots.files_path
    ]]></command>
    <inputs>
        <param argument="--otu_table_fp" type="data" format="tabular,txt,tsv,biom" label="OTU table"/>
        <param argument="--mapping_fp" type="data" format="tabular,txt,tsv" label="Mapping file"/>
        <param argument="--parameter_fp" type="data" format="txt" optional="true" label="Parameter file" help="It specifies changes to the default behavior"/>
        <param argument="--num_steps" type="integer" value="10" label="Number of steps (or rarefied OTU table sizes) to make between min and max counts"/>
        <param argument="--parallel" type="boolean" truevalue="--parallel" falsevalue="" checked="true" label="Run in parallel where available?"/>
        <param argument="--tree_fp" type="data" format="tabular,txt,tsv" optional="true" label="Tree file (optional)" help="Required for phylogenetic measures"/>
        <param argument="--min_rare_depth" type="integer" value="10" label="Lower limit of rarefaction depths"/>
        <param argument="--max_rare_depth" type="integer" label="Upper limit of rarefaction depths" help="By default, median sequence/sample count is used" optional="True"/>
        <param argument="--retain_intermediate_files" type="boolean" truevalue="--retain_intermediate_files" falsevalue="" checked="true" label="Retain intermediate files?"/>
    </inputs>
    <outputs>
        <data name="alpha_rarefaction_plots" format="html" label="${tool.name} on ${on_string}: Alpha rarefaction plots"/>
        <collection name="alpha_diversity" type="list" label="${tool.name} on ${on_string}: Alpha diversity information">
            <discover_datasets pattern="(?P&lt;designation&gt;.+)\.txt" directory="alpha_rarefaction/alpha_div_collated/"/>
        </collection>
        <collection name="rarefaction" type="list" label="${tool.name} on ${on_string}: Rarefied OTU tables">
            <discover_datasets pattern="rarefaction_(?P&lt;designation&gt;.+)\.biom" directory="alpha_rarefaction/rarefaction/"/>
            <filter>retain_intermediate_files!=''</filter>
        </collection>
        <collection name="alpha_div" type="list" label="${tool.name} on ${on_string}: Alpha diversity results">
            <discover_datasets pattern="alpha_rarefaction_(?P&lt;designation&gt;.+)\.txt" directory="alpha_rarefaction/alpha_div/"/>
            <filter>retain_intermediate_files!=''</filter>
        </collection>
    </outputs>
    <tests>
        <test>
            <param name="otu_table_fp" value="alpha_rarefaction/otu_table.biom"/>
            <param name="mapping_fp" value="alpha_rarefaction/mapping_file.txt"/>
            <param name="num_steps" value="2"/>
            <param name="parallel" value=""/>
            <param name="tree_fp" value="alpha_rarefaction/rep_set.tre"/>
            <param name="min_rare_depth" value="10"/>
            <param name="max_rare_depth" value="50"/>
            <param name="retain_intermediate_files" value="--retain_intermediate_files"/>
            <output name="alpha_rarefaction_plots">
                <assert_contents>
                    <has_text text="Control_mouse_I.D._354" />
                </assert_contents>
            </output>
            <output_collection name="alpha_diversity" type="list" count="3">
                <element name="chao1">
                    <assert_contents>
                        <has_text text="alpha_rarefaction_10_0" />
                        <has_text text="alpha_rarefaction_30_5" />
                        <has_text text="alpha_rarefaction_50_9" />
                    </assert_contents>
                </element>
                <element name="observed_otus">
                    <assert_contents>
                        <has_text text="alpha_rarefaction_10_0" />
                        <has_text text="alpha_rarefaction_30_5" />
                        <has_text text="alpha_rarefaction_50_9" />
                    </assert_contents>
                </element>
                <element name="PD_whole_tree">
                    <assert_contents>
                        <has_text text="alpha_rarefaction_10_0" />
                        <has_text text="alpha_rarefaction_30_5" />
                        <has_text text="alpha_rarefaction_50_9" />
                    </assert_contents>
                </element>
            </output_collection>
            <output_collection name="rarefaction" type="list" count="30">
                <element name="10_0">
                    <assert_contents>
                        <has_text text="PC.636" />
                        <has_text text="PC.354" />
                        <has_text text="PC.634" />
                    </assert_contents>
                </element>
                <element name="30_6">
                    <assert_contents>
                        <has_text text="PC.636" />
                        <has_text text="PC.354" />
                        <has_text text="PC.634" />
                    </assert_contents>
                </element>
                <element name="50_9">
                    <assert_contents>
                        <has_text text="PC.636" />
                        <has_text text="PC.354" />
                        <has_text text="PC.634" />
                    </assert_contents>
                </element>
            </output_collection>
            <output_collection name="alpha_div" type="list" count="30">
                <element name="10_0">
                    <assert_contents>
                        <has_text text="PC.636" />
                        <has_text text="PC.354" />
                        <has_text text="PC.634" />
                    </assert_contents>
                </element>
                <element name="30_6">
                    <assert_contents>
                        <has_text text="PC.636" />
                        <has_text text="PC.354" />
                        <has_text text="PC.634" />
                    </assert_contents>
                </element>
                <element name="50_9">
                    <assert_contents>
                        <has_text text="PC.636" />
                        <has_text text="PC.354" />
                        <has_text text="PC.634" />
                    </assert_contents>
                </element>
            </output_collection>
        </test>
    </tests>
    <help><![CDATA[
**What it does**

This script performs alpha rarefaction in several steps:

    - Generation of rarefied OTU tables
    - Computation of alpha diversity metrics for each rarefied OTU table
    - Concatenation of alpha diversity results
    - Generation of alpha rarefaction plots

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