<?xml version="1.0" standalone="yes"?>
<!-- $Id: testMCMC.xml,v 1.2 2005/07/11 23:22:40 rambaut Exp $ -->
<!-- Tests the MCMC engine -->

<beast>

    <!-- The list of taxa analyse (can also include dates/ages).                 -->
    <!-- ntax=6                                                                  -->
    <taxa id="taxa">
        <taxon id="human"/>
        <taxon id="chimp"/>
        <taxon id="bonobo"/>
        <taxon id="gorilla"/>
        <taxon id="orangutan"/>
        <taxon id="siamang"/>
    </taxa>

    <!-- The sequence alignment (each sequence refers to a taxon above).         -->
    <!-- ntax=6 nchar=768                                                        -->
    <alignment id="alignment" dataType="nucleotide">
        <sequence>
            <taxon idref="human"/>
            ACGTATGTTGACAATGTTGACAATGTTGACAATGTTGACAATGTTGACATTTTT
        </sequence>
        <sequence>
            <taxon idref="chimp"/>
            ACGTATGTTGCTAATGTTGCTAATGTTGCTAATGTTGCTAATGTTGCTATTTTT
        </sequence>
        <sequence>
            <taxon idref="bonobo"/>
            ACGTATGTCCCTTATGTCCCTTATGTCCCTTATGTCCCTTATGTCCCTTTTTTT
        </sequence>
        <sequence>
            <taxon idref="gorilla"/>
            ACGTATGTCCCTTATGTCCCTTATGTCCCTTATGTCCCTTATGTCCCTTTTTTT
        </sequence>
        <sequence>
            <taxon idref="orangutan"/>
            ACGTTCGTCCCTTTCGTCCCTTTCGTCCCTTTCGTCCCTTTCGTCCCTTTTTTT
        </sequence>
        <sequence>
            <taxon idref="siamang"/>
            ACGTTTATCCCTTTTATCCCTTTTATCCCTTTTATCCCTTTTATCCCTTCAGCA
        </sequence>
    </alignment>

    <!-- The unique patterns for all positions                                   -->
    -->
    <ascertainedPatterns id="patterns" from="5">
        <alignment idref="alignment"/>
        <!-- all constant sites (1 through 4) are excluded from the dataset -->
        <excludePatterns from="1" to="1"/>
    </ascertainedPatterns>

    <!-- This is a simple constant population size coalescent model              -->
    <!-- that is used to generate an initial tree for the chain.                 -->
    <constantSize id="initialDemo" units="substitutions">
        <populationSize>
            <parameter id="initialDemo.popSize" value="0.0001"/>
        </populationSize>
    </constantSize>

    <!-- Generate a random starting tree under the coalescent process            -->
    <coalescentTree id="startingTree">
        <taxa idref="taxa"/>
        <constantSize idref="initialDemo"/>
    </coalescentTree>

    <treeModel id="treeModel">
        <coalescentTree idref="startingTree"/>
        <rootHeight>
            <parameter id="treeModel.rootHeight"/>
        </rootHeight>
        <nodeHeights internalNodes="true">
            <parameter id="treeModel.internalNodeHeights"/>
        </nodeHeights>
        <nodeHeights internalNodes="true" rootNode="true">
            <parameter id="treeModel.allInternalNodeHeights"/>
        </nodeHeights>
    </treeModel>

    <!-- The HKY substitution model (Hasegawa, Kishino & Yano, 1985)             -->
    <hkyModel id="hky">
        <frequencies>
            <frequencyModel dataType="nucleotide">
                <alignment idref="alignment"/>
                <frequencies>
                    <parameter id="hky.frequencies" dimension="4"/>
                </frequencies>
            </frequencyModel>
        </frequencies>
        <kappa>
            <parameter id="hky.kappa" value="1.0" lower="0.0"/>
        </kappa>
    </hkyModel>

    <!-- site model                                                              -->
    <siteModel id="siteModel">
        <substitutionModel>
            <hkyModel idref="hky"/>
        </substitutionModel>
        <mutationRate>
            <parameter id="siteModel.mu" value="1.0" lower="0.0"/>
        </mutationRate>
    </siteModel>

    <treeLikelihood id="treeLikelihood">
        <patterns idref="patterns"/>
        <treeModel idref="treeModel"/>
        <siteModel idref="siteModel"/>
    </treeLikelihood>

    <operators id="operators">
        <scaleOperator scaleFactor="0.5" weight="1">
            <parameter idref="hky.kappa"/>
        </scaleOperator>
        <scaleOperator scaleFactor="0.5" weight="1">
            <parameter idref="treeModel.rootHeight"/>
        </scaleOperator>
        <uniformOperator weight="10">
            <parameter idref="treeModel.internalNodeHeights"/>
        </uniformOperator>
        <subtreeSlide weight="5" gaussian="true" size="1.0">
            <treeModel idref="treeModel"/>
        </subtreeSlide>
        <narrowExchange weight="1">
            <treeModel idref="treeModel"/>
        </narrowExchange>
        <wideExchange weight="1">
            <treeModel idref="treeModel"/>
        </wideExchange>
        <wilsonBalding weight="1">
            <treeModel idref="treeModel"/>
        </wilsonBalding>
    </operators>

    <mcmc id="mcmc" chainLength="10000000" autoOptimize="true">
        <compoundLikelihood id="likelihood">
            <treeLikelihood idref="treeLikelihood"/>
            <gammaPrior id="MRCAprior" scale="1" shape="0.0001" offset="0">
                <parameter idref="treeModel.rootHeight"/>
            </gammaPrior>
        </compoundLikelihood>
        <operators idref="operators"/>
        <log logEvery="10000">
            <column label="Likelihood" dp="4" width="12">
                <compoundLikelihood idref="likelihood"/>
            </column>
            <column label="Root Height" sf="6" width="12">
                <parameter idref="treeModel.rootHeight"/>
            </column>
            <column label="Kappa" sf="6" width="12">
                <parameter idref="hky.kappa"/>
            </column>
        </log>
        <log logEvery="1000" fileName="testMCMC.log">
            <compoundLikelihood idref="likelihood"/>
            <parameter idref="treeModel.rootHeight"/>
            <parameter idref="hky.kappa"/>
        </log>
        <logTree logEvery="1000" nexusFormat="true" fileName="testMCMC.trees">
            <treeModel idref="treeModel"/>
        </logTree>
    </mcmc>

    <report>
        <property name="timer">
            <object idref="mcmc"/>
        </property>
    </report>

    <treeTraceAnalysis fileName="testMCMC.trees"/>

</beast>
