<?xml version="1.0" standalone="yes"?>
<!--
  ~ testYuleOneSite.xml
  ~
  ~ Copyright (C) 2002-2009 Alexei Drummond and Andrew Rambaut
  ~
  ~ This file is part of BEAST.
  ~ See the NOTICE file distributed with this work for additional
  ~ information regarding copyright ownership and licensing.
  ~
  ~ BEAST is free software; you can redistribute it and/or modify
  ~ it under the terms of the GNU Lesser General Public License as
  ~ published by the Free Software Foundation; either version 2
  ~ of the License, or (at your option) any later version.
  ~
  ~ BEAST is distributed in the hope that it will be useful,
  ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
  ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  ~ GNU Lesser General Public License for more details.
  ~
  ~ You should have received a copy of the GNU Lesser General Public
  ~ License along with BEAST; if not, write to the
  ~ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
  ~ Boston, MA  02110-1301  USA
  -->

<beast>

    <!-- The list of taxa analyse (can also include dates/ages).                 -->
    <!-- ntax=17                                                                 -->
    <taxa id="taxa">
        <taxon id="A"/>
        <taxon id="B"/>
        <taxon id="C"/>
        <taxon id="D"/>
        <taxon id="E"/>
    </taxa>

    <alignment id="alignment" dataType="nucleotide">
        <sequence>
            <taxon idref="A"/>
            A
        </sequence>
        <sequence>
            <taxon idref="B"/>
            A
        </sequence>
        <sequence>
            <taxon idref="C"/>
            A
        </sequence>
        <sequence>
            <taxon idref="D"/>
            A
        </sequence>
        <sequence>
            <taxon idref="E"/>
            A
        </sequence>
    </alignment>

    <!-- The unique patterns for all positions                                   -->
    <!-- npatterns=138                                                           -->
    <patterns id="patterns" from="1">
        <alignment idref="alignment"/>
    </patterns>

    <!-- A prior assumption that the population size has remained constant       -->
    <!-- throughout the time spanned by the genealogy.                           -->
    <constantSize id="constant" units="years">
        <populationSize>
            <parameter id="constant.popSize" value="1.0" lower="0.0" upper="38000.0"/>
        </populationSize>
    </constantSize>

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

    <!-- A prior on the distribution node heights defined given                  -->
    <!-- a Yule speciation process (a pure birth process).                       -->
    <yuleModel id="yule" units="substitutions">
        <birthRate>
            <parameter id="yule.birthRate" value="1.0" lower="0.0" upper="100.0"/>
        </birthRate>
    </yuleModel>


    <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>

    <speciationLikelihood id="speciationLikelihood">
        <model>
            <yuleModel idref="yule"/>
        </model>
        <speciesTree>
            <treeModel idref="treeModel"/>
        </speciesTree>
    </speciationLikelihood>

    <treeLengthStatistic name="TL" id="TL">
        <treeModel idref="treeModel"/>
    </treeLengthStatistic>

    <!-- The strict clock (Uniform rates across branches)                        -->
    <strictClockBranchRates id="branchRates">
        <rate>
            <parameter id="clock.rate" value="1" lower="0.0" upper="100.0"/>
        </rate>
    </strictClockBranchRates>

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

    <!-- site model                                                              -->
    <siteModel id="siteModel">
        <substitutionModel>
            <hkyModel idref="hky"/>
        </substitutionModel>
    </siteModel>

    <treeLikelihood id="treeLikelihood" useAmbiguities="true">
        <patterns idref="patterns"/>
        <treeModel idref="treeModel"/>
        <siteModel idref="siteModel"/>
        <strictClockBranchRates idref="branchRates"/>
    </treeLikelihood>

    <operators id="operators">
        <scaleOperator scaleFactor="0.75" weight="3">
            <parameter idref="treeModel.rootHeight"/>
        </scaleOperator>
        <uniformOperator weight="30">
            <parameter idref="treeModel.internalNodeHeights"/>
        </uniformOperator>
        <subtreeSlide size="1.0" gaussian="true" weight="15">
            <treeModel idref="treeModel"/>
        </subtreeSlide>
        <narrowExchange weight="15">
            <treeModel idref="treeModel"/>
        </narrowExchange>
        <wideExchange weight="3">
            <treeModel idref="treeModel"/>
        </wideExchange>
        <wilsonBalding weight="3">
            <treeModel idref="treeModel"/>
        </wilsonBalding>
    </operators>

    <mcmc id="mcmc" chainLength="1000000" autoOptimize="true">
        <posterior id="posterior">
            <prior id="prior">
                <speciationLikelihood idref="speciationLikelihood"/>
            </prior>
            <likelihood id="likelihood">
                <treeLikelihood idref="treeLikelihood"/>
            </likelihood>
        </posterior>
        <operators idref="operators"/>
        <log id="screenLog" logEvery="10000">
            <column label="Posterior" dp="4" width="12">
                <posterior idref="posterior"/>
            </column>
            <column label="Root Height" sf="6" width="12">
                <parameter idref="treeModel.rootHeight"/>
            </column>
            <column label="L(tree)" dp="4" width="12">
                <treeLikelihood idref="treeLikelihood"/>
            </column>
            <column label="L(coalecent)" dp="4" width="12">
                <speciationLikelihood idref="speciationLikelihood"/>
            </column>
        </log>
        <log id="fileLog" logEvery="500" fileName="testYuleOneSite.log">
            <posterior idref="posterior"/>
            <parameter idref="clock.rate"/>
            <parameter idref="constant.popSize"/>
            <parameter idref="hky.kappa"/>
            <parameter idref="treeModel.rootHeight"/>
            <treeLikelihood idref="treeLikelihood"/>
            <speciationLikelihood idref="speciationLikelihood"/>
        </log>
        <logTree id="treeFileLog" logEvery="500" nexusFormat="true" fileName="testYuleOneSite.trees">
            <treeModel idref="treeModel"/>
            <posterior idref="posterior"/>
        </logTree>
    </mcmc>


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

    <traceAnalysis fileName="testYuleOneSite.log"/>

    <treeTraceAnalysis fileName="testYuleOneSite.trees"/>

    <lineageCountThroughTime treeFile="testYuleOneSite.trees" maxTime="4" skip="200"/>

</beast>
