<?xml version="1.0"?>
<macros>
    <token name="@DESEQ2_ASV_PREPROCESS_CMD_LINE@">
    deseq2_preprocess.py
        --analysis-type 'ASV'
        --phyloseq-rdata '$phyloseq_rdata'
        #if $multiple.correction == 'true'
            --var-exp '$var_exp${multiple.model_type}${multiple.conf_factor}'
        #else
            --var-exp '$var_exp'
        #end if
        --output-deseq-rdata '$ASV_deseq_rdata'
    </token>

    <xml name="deseq2_asv_preprocess_inputs">
        <!-- Files -->
        <param argument="--phyloseq-rdata" type="data" format="rdata" label="Phyloseq object (.Rdata)" help="Rdata file generated by the FROGS Stat 'Phyloseq Import data' tool."/>
        <!-- Parameters -->        
        <param argument="--var-exp" type="text" label="Experimental variable" help="Sample metadata variable expected to influence ASV abundances (e.g., Treatment, Environment, Site, etc.).">
            <expand macro="restricted_sanitizer_validator"/>
        </param>
        <conditional name="multiple">
            <param name="correction" type="select" label="Correct for a confounding factor?" help="If yes, specify an additional sample metadata variable that could affect ASV abundances.">
                <option value="true">True</option>
                <option value="false" selected="true">False</option>
            </param>
            <when value="false"/>
            <when value="true">
                <param name="conf_factor" type="text" label="Confounding factor" help="Secondary sample metadata variable to account for (e.g., Gender, Batch, Sampling date, etc.).">
                    <expand macro="restricted_sanitizer_validator"/>
                </param>
                <param name="model_type" type="select" multiple="false" label="Model type" help="Choose an additive model (+) if the effects of the two variables are independent, or an interaction model (*) if their effects are expected to depend on each other.">
                    <option value="+" selected="true">Linear (+)</option>
                    <option value="*">Interaction (*)</option>
                </param>
            </when>
        </conditional>
    </xml>

    <!-- Test -->
    <xml name="deseq2_asv_preprocess_test_input">
        <param name="phyloseq_rdata" value="references/16-phylo_import.Rdata" />
        <param name="var_exp" value="EnvType" />
    </xml>

    <xml name="deseq2_asv_preprocess_test_output">
        <output name="ASV_deseq_rdata" count="1" file="references/23-deseq2_preprocess_asv.Rdata" compare="sim_size" delta="100"/>
    </xml>

    <token name="@DESEQ2_FUN_PREPROCESS_CMD_LINE@">
    deseq2_preprocess.py
        --analysis-type 'FUNCTION'
        --input-functions-abund '$input_functions_abund'
        --sample-metadata-tsv '$sample_metadata_tsv'
        
        #if $multiple.correction == 'true'
            --var-exp '$var_exp${multiple.model_type}${multiple.conf_factor}'
        #else
            --var-exp '$var_exp'
        #end if
        
        --output-phyloseq-rdata '$FUN_phyloseq_rdata'
        --output-deseq-rdata '$FUN_deseq_rdata'



    </token>

    <xml name="deseq2_fun_preprocess_inputs">
        <!-- Files -->
        <param argument="--input-functions-abund" type="data" format="tsv,tabular" label="Function abundances file (.tsv) " help="Input file containing predicted function abundances (e.g., 'picrust2_functions: EC_unstrat_abundance.tsv' generated by the FROGS Func 'picrust2_function' tool)."/>
        <param argument="--sample-metadata-tsv" type="data" format="tabular,tsv" label="Sample metadata file (.tsv)" help="Tabular file containing metadata describing each sample (e.g., Treatment, Site, Host type, etc.)."/>
        <!-- Parameters -->        
        <param argument="--var-exp" type="text" label="Experimental variable" help="Sample metadata variable expected to influence functional abundances (e.g., Treatment, Environment, Site, etc.).">
            <expand macro="restricted_sanitizer_validator"/>
        </param>
        <conditional name="multiple">
            <param name="correction" type="select" label="Correct for a confounding factor?" help="If yes, specify an additional sample metadata variable to account for (e.g., Batch, Gender, etc.).">
                <option value="true">True</option>
                <option value="false" selected="true">False</option>
            </param>
            <when value="false"/>
            <when value="true">
                <param name="conf_factor" type="text" label="Confounding factor" help="Secondary sample metadata variable to control for (e.g., Gender, Batch, Sampling date, etc.).">
                    <expand macro="restricted_sanitizer_validator"/>
                </param>
                <param name="model_type" type="select" multiple="false" label="Model type" help="Choose an additive model (+) if the effects of both variables are independent, or an interaction model (*) if their effects depend on each other.">
                    <option value="+" selected="true">Linear (+)</option>
                    <option value="*">Interaction (*)</option>
                </param>
            </when>
        </conditional>
    </xml>

    <!-- Test -->
    <xml name="deseq2_fun_preprocess_test_input">
        <param name="sample_metadata_tsv" value="input/sample_metadata.tsv"/>
        <param name="input_functions_abund" value="input/frogsfunc_functions_unstrat_EC.tsv" />
        <param name="var_exp" value="EnvType" />
    </xml>

    <xml name="deseq2_fun_preprocess_test_output">
		<!-- Deseq2 is influenced by other intermediate libraries or packages and results are hard to compare -->
        <!-- <output name="FUN_deseq_rdata" count="1" file="references/23-deseq2_preprocess_func.Rdata" compare="sim_size" delta="4000"/> -->
        <output name="FUN_phyloseq_rdata" count="1" file="references/23-phyloseq_functions.Rdata" compare="sim_size" delta="10"/>
    </xml>
</macros>
