<tool id="hyphy_slac" name="HyPhy-SLAC" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="@PROFILE@">
    <description>Single Likelihood Ancestor Counting</description>
    <macros>
        <import>macros.xml</import>
    </macros>
    <expand macro="bio_tools"/>
    <expand macro="requirements"/>
    <command detect_errors="exit_code"><![CDATA[
        @SYMLINK_FILES@
        @HYPHYMP@ slac
            --alignment ./$input_file
            @INPUT_TREE@
            --code '$gencodeid'
            @branch_options@
            --samples '$number_of_samples'
            --pvalue '$p_value'
            --output '$slac_output'
            --kill-zero-lengths $kill_zero_lengths > slac_stdout.md
        @ERRORS@
    ]]></command>
    <inputs>
        <expand macro="inputs"/>
        <expand macro="gencode"/>
        <expand macro="branches"/>
        <param argument="--pvalue" name="p_value" type="float" value=".1" min="0" max="1" label="P-value"  />
        <param argument="--samples" name="number_of_samples" type="integer" value="0" min="0" max="10000" label="Number of samples used to assess ancestral reconstruction uncertainty"/>
        <expand macro="kill_zero_lengths_param"/>
    </inputs>
    <outputs>
        <data name="slac_md_report" format="markdown" from_work_dir="slac_stdout.md" label="SLAC Report (Markdown) for ${tool.name} on ${on_string}" />
        <data name="slac_output" format="hyphy_results.json" />
    </outputs>
    <tests>
        <test>
            <param name="input_file" ftype="fasta" value="absrel-in1.fa"/>
            <param name="input_nhx" ftype="nhx" value="absrel-in1.nhx"/>
            <param name="number_of_samples" value="100"/>
            <output name="slac_output">
                <assert_contents>
                    <has_text text="sample-2.5"/>
                    <has_text text="sample-97.5"/>
                    <has_text text="Global MG94xREV"/>
                </assert_contents>
            </output>
            <output name="slac_md_report">
                <assert_contents>
                    <has_text text="Performing joint maximum likelihood ancestral state reconstruction"/>
                    <has_text text="Selected 5 branches to include in SLAC calculations: `Pig, Cow, Node2, Baboon, Rat`"/>
                </assert_contents>
            </output>
        </test>
    </tests>
    <help><![CDATA[
SLAC : Single Likelihood Ancestor Counting
==========================================

What question does this method answer?
--------------------------------------

SLAC (Single Likelihood Ancestor Counting) is designed to identify individual sites within a gene that are subject to pervasive diversifying selection, meaning selection that acts consistently across the entire evolutionary phylogeny. It helps answer: Which specific sites in a gene show evidence of positive selection that has been maintained throughout the evolutionary history of the analyzed sequences?

Recommended Applications
------------------------

The phenomenon of pervasive selection is generally most prevalent in pathogen evolution and any biological system influenced by evolutionary arms race dynamics
(or balancing selection), including adaptive immune escape by viruses. As such, SLAC is ideally suited to identify sites under positive selection which
represent candidate sites subject to strong selective pressures across the entire phylogeny.
SLAC provides legacy functionality as a counting-based method adapted for phylogenetic applications.
In general, this method will be the least statistically robust (compared to FEL or FUBAR), but it is the most directly interpretable.

Brief description
-----------------

SLAC (Single Likelihood Ancestor Counting) is a counting-based method designed to detect pervasive positive or negative selection at individual sites within a gene. It operates by first inferring ancestral sequences at each node of the provided phylogenetic tree using a maximum likelihood approach. This reconstruction allows for the estimation of synonymous (dS) and non-synonymous (dN) substitution rates at each site across the entire phylogeny. Finally, a binomial test is applied to determine if the observed number of non-synonymous substitutions significantly deviates from the expected number under neutrality (dN = dS). The method aggregates information across all branches of the phylogeny, making it suitable for detecting pervasive diversifying selection (dN > dS) or purifying selection (dN < dS) that acts consistently throughout the evolutionary history of the analyzed sequences. While generally less statistically robust than likelihood-based methods like FEL or FUBAR, SLAC offers direct interpretability of its results.

How it works
------------

1.  Ancestral Sequence Reconstruction: SLAC begins by reconstructing the most likely ancestral sequences at each internal node of the provided phylogenetic tree.
2.  Counting Substitutions: Once ancestral sequences are inferred, the method counts the number of synonymous (dS) and non-synonymous (dN) substitutions that have occurred along each branch of the phylogeny.
3.  Binomial Test: For each site, SLAC applies a binomial test. The null hypothesis is that non-synonymous and synonymous mutations occur at equal rates (i.e., no selection).
4.  Pervasive Selection: By aggregating evidence across all branches of the tree, SLAC identifies sites that have been under consistent selective pressure throughout the evolutionary history of the gene.

Input
-----

1. A coding multiple sequence alignment.
2. A phylogenetic tree in the *Newick* format

Note: the names of sequences in the alignment must match the names of the sequences in the tree.


Output
------

A JSON file with analysis results (http://hyphy.org/resources/json-fields.pdf). This JSON output can be visualized using the HyPhy Vision platform at http://vision.hyphy.org/SLAC/.

Further reading
---------------

http://hyphy.org/methods/selection-methods/#SLAC


Tool options
------------
::

    --alignment         [required] An in-frame codon alignment in one of the formats supported by HyPhy.
    --tree              [conditionally required] A phylogenetic tree (optionally annotated with {}).

    --code              Which genetic code to use (see tool form for available options).

    --branches          Which branches should be tested for selection?
                            All [default] : test all branches
                            Internal : test only internal branches (suitable for intra-host pathogen evolution for example, where terminal branches may contain polymorphism data)
                            Leaves: test only terminal (leaf) branches
                            Unlabeled: if the Newick string is labeled using the {} notation, test only branches without explicit labels (see http://hyphy.org/tutorials/phylotree/)
                            Custom : Enter a branch label.

    --pvalue            The significance level used to determine significance (default: 0.1, range: 0 to 1).
    --samples           Draw this many alternative ancestral state reconstructions to evaluate uncertainty (default: 100, range: 0 to 10000).

    --kill-zero-lengths Automatically delete internal zero-length branches for computational efficiency.
                            Yes [default] : Automatically delete internal zero-length branches for computational efficiency (will not affect results otherwise).
                            Constrain : Keep zero-length branches, but constrain their values to 0.
                            No : Keep all branches.

  ]]>
  </help>
    <expand macro="citations">
        <citation type="doi">10.1093/molbev/msi105</citation>
    </expand>
</tool>
