Search in sources :

Example 1 with GTR

use of beast.evolution.substitutionmodel.GTR in project beast2 by CompEvol.

the class GTRTest method testGTR.

public void testGTR() throws Exception {
    for (Instance test : all) {
        RealParameter f = new RealParameter(test.getPi());
        Frequencies freqs = new Frequencies();
        freqs.initByName("frequencies", f, "estimate", false);
        GTR gtr = new GTR();
        Double[] rates = test.getRates();
        gtr.initByName("rateAC", new RealParameter(rates[0] + ""), "rateAG", new RealParameter(rates[1] + ""), "rateAT", new RealParameter(rates[2] + ""), "rateCG", new RealParameter(rates[3] + ""), "rateCT", new RealParameter(rates[4] + ""), "rateGT", new RealParameter(rates[5] + ""), "frequencies", freqs);
        double distance = test.getDistance();
        double[] mat = new double[4 * 4];
        gtr.getTransitionProbabilities(null, distance, 0, 1, mat);
        final double[] result = test.getExpectedResult();
        for (int k = 0; k < mat.length; ++k) {
            assertEquals(mat[k], result[k], 1e-10);
            System.out.println(k + " : " + (mat[k] - result[k]));
        }
    }
}
Also used : GTR(beast.evolution.substitutionmodel.GTR) RealParameter(beast.core.parameter.RealParameter) Frequencies(beast.evolution.substitutionmodel.Frequencies)

Example 2 with GTR

use of beast.evolution.substitutionmodel.GTR in project beast2 by CompEvol.

the class TreeLikelihoodTest method testGTRLikelihood.

@Test
public void testGTRLikelihood() throws Exception {
    // Set up GTR model: no gamma categories, no proportion invariant
    Alignment data = BEASTTestCase.getAlignment();
    Tree tree = BEASTTestCase.getTree(data);
    Frequencies freqs = new Frequencies();
    freqs.initByName("data", data);
    GTR gsm = new GTR();
    gsm.initByName("frequencies", freqs);
    SiteModel siteModel = new SiteModel();
    siteModel.initByName("mutationRate", "1.0", "gammaCategoryCount", 1, "substModel", gsm);
    TreeLikelihood likelihood = newTreeLikelihood();
    likelihood.initByName("data", data, "tree", tree, "siteModel", siteModel);
    double logP = 0;
    logP = likelihood.calculateLogP();
    assertEquals(logP, -1969.145839307625, BEASTTestCase.PRECISION);
    likelihood.initByName("useAmbiguities", false, "data", data, "tree", tree, "siteModel", siteModel);
    logP = likelihood.calculateLogP();
    assertEquals(logP, -1969.145839307625, BEASTTestCase.PRECISION);
}
Also used : Alignment(beast.evolution.alignment.Alignment) GTR(beast.evolution.substitutionmodel.GTR) BeagleTreeLikelihood(beast.evolution.likelihood.BeagleTreeLikelihood) TreeLikelihood(beast.evolution.likelihood.TreeLikelihood) Tree(beast.evolution.tree.Tree) SiteModel(beast.evolution.sitemodel.SiteModel) Frequencies(beast.evolution.substitutionmodel.Frequencies) UncertainAlignmentTest(test.beast.evolution.alignment.UncertainAlignmentTest) Test(org.junit.Test)

Aggregations

Frequencies (beast.evolution.substitutionmodel.Frequencies)2 GTR (beast.evolution.substitutionmodel.GTR)2 RealParameter (beast.core.parameter.RealParameter)1 Alignment (beast.evolution.alignment.Alignment)1 BeagleTreeLikelihood (beast.evolution.likelihood.BeagleTreeLikelihood)1 TreeLikelihood (beast.evolution.likelihood.TreeLikelihood)1 SiteModel (beast.evolution.sitemodel.SiteModel)1 Tree (beast.evolution.tree.Tree)1 Test (org.junit.Test)1 UncertainAlignmentTest (test.beast.evolution.alignment.UncertainAlignmentTest)1