<?xml version="1.0" standalone="yes"?>
<!-- $Id:  $ -->
<!-- Tests the sequence simulator -->

<beast>

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

    <tree id="treeML" units="years" usingDates="false">
        <node height="0.099582">
            <node height="0.069125">
                <node height="0.036038">
                    <node height="0.024003">
                        <node height="0.000000">
                            <taxon idref="human"/>
                        </node>
                        <node height="0.010772">
                            <node height="0.000000">
                                <taxon idref="chimp"/>
                            </node>
                            <node height="0.000000">
                                <taxon idref="bonobo"/>
                            </node>
                        </node>
                    </node>
                    <node height="0.000000">
                        <taxon idref="gorilla"/>
                    </node>
                </node>
                <node height="0.000000">
                    <taxon idref="orangutan"/>
                </node>
            </node>
            <node height="0.000000">
                <taxon idref="siamang"/>
            </node>
        </node>
    </tree>

    <!-- JC -->

    <hkyModel id="simHKYModel">
        <frequencies>
            <frequencyModel dataType="nucleotide">
                <frequencies>
                    <parameter dimension="4" value="0.25 0.25 0.25 0.25"/>
                </frequencies>
            </frequencyModel>
        </frequencies>
        <kappa>
            <parameter id="simjc69.kappa" value="2.0" lower="0.0" upper="100.0"/>
        </kappa>
    </hkyModel>

    <siteModel id="simSiteModel">
        <substitutionModel>
            <hkyModel idref="simHKYModel"/>
        </substitutionModel>
        <mutationRate>
            <parameter id="simSiteModel.mu" value="1.0" lower="0.0"/>
        </mutationRate>
        <gammaShape gammaCategories="4">
            <parameter id="simAlpha" value="0.5" lower="0.0" upper="100.0"/>
        </gammaShape>
    </siteModel>

    <report>
        <completeHistorySimulator id="myAlignment" replications='10000'>
            <tree idref="treeML"/>
            <siteModel idref="simSiteModel"/>
            <branchSpecificSpecification>
            	<variableParameter>
            		<parameter idref="simjc69.kappa"/>
            	</variableParameter>
            	<valuesParameter>
            		<parameter id="replacementValues" dimension="11">
            			<randomize>
            				<gammaDistributionModel>
            					<shape> 1 </shape>
            					<scale> 2 </scale>
            				</gammaDistributionModel>            			
            			</randomize>            		
            		</parameter>
            	</valuesParameter>
            </branchSpecificSpecification>            
        </completeHistorySimulator>
    </report>


    <patterns id="myPatterns">
        <sequenceSimulator idref="myAlignment"/>
    </patterns>
    
    
    <hkyModel id="fitHKYModel">
        <frequencies>
            <frequencyModel dataType="nucleotide">
                <frequencies>
                    <parameter dimension="4" value="0.25 0.25 0.25 0.25"/>
                </frequencies>
            </frequencyModel>
        </frequencies>
        <kappa>
            <parameter id="fitKappa" value="1.0" lower="0.0" upper="100.0"/>
        </kappa>
    </hkyModel>

    <siteModel id="fitSiteModel">
        <substitutionModel>
            <hkyModel idref="fitHKYModel"/>
        </substitutionModel>
        <mutationRate>
            <parameter id="fitMu" value="2.0" lower="0.0"/>
        </mutationRate>
        <gammaShape gammaCategories="4">
            <parameter id="fitAlpha" value="1.0" lower="0.0" upper="100.0"/>
        </gammaShape>
    </siteModel>

    <treeModel id="treeModel1">
        <tree idref="treeML"/>
        <rootHeight>
            <parameter id="treeModel1.rootHeight"/>
        </rootHeight>
        <nodeHeights internalNodes="true">
            <parameter id="treeModel1.internalNodeHeights"/>
        </nodeHeights>
        <nodeHeights internalNodes="true" rootNode="true">
            <parameter id="treeModel1.allInternalNodeHeights"/>
        </nodeHeights>
    </treeModel>
 

    <treeLikelihood id="treeLikelihood1">
        <patterns idref="myPatterns"/>
        <treeModel idref="treeModel1"/>
        <siteModel idref="fitSiteModel"/>
    </treeLikelihood>


    <operators id="operators">
        <scaleOperator scaleFactor="0.5" weight="1">
            <parameter idref="fitKappa"/>
        </scaleOperator>
        <scaleOperator scaleFactor="0.5" weight="1">
            <parameter idref="fitMu"/>
        </scaleOperator>
        <scaleOperator scaleFactor="0.5" weight="1">
            <parameter idref="fitAlpha"/>
        </scaleOperator>
    </operators>
    
 	<mcmc id="mcmc" chainLength="500000" autoOptimize="true">
        <posterior>
            <likelihood id="likelihood">
                <treeLikelihood idref="treeLikelihood1"/>
            </likelihood>            
        </posterior>
        <operators idref="operators"/>
        <log logEvery="50000">
            <column label="Likelihood" dp="4" width="12">
                <likelihood idref="likelihood"/>
            </column>
            <column label="Kappa" sf="6" width="12">
                <parameter idref="fitKappa"/>
            </column>
            <column label="Mu" sf="6" width="12">
                <parameter idref="fitMu"/>
            </column>
            <column label="Alpha" sf="6" width="12">
                <parameter idref="fitAlpha"/>
            </column>            
        </log>
        <log logEvery="1000" fileName="testSimulation.log">
            <likelihood idref="likelihood"/>
            <parameter idref="fitKappa"/>
            <parameter idref="fitMu"/>
            <parameter idref="fitAlpha"/>
        </log>
    </mcmc>

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

    <traceAnalysis fileName="testSimulation.log"/>

</beast>
	