Search in sources :

Example 66 with Tree

use of beast.evolution.tree.Tree in project beast2 by CompEvol.

the class TreeLikelihoodTest method testJC69Likelihood.

@Test
public void testJC69Likelihood() throws Exception {
    // Set up JC69 model: uniform freqs, kappa = 1, 0 gamma categories
    Alignment data = BEASTTestCase.getAlignment();
    Tree tree = BEASTTestCase.getTree(data);
    JukesCantor JC = new JukesCantor();
    JC.initAndValidate();
    SiteModel siteModel = new SiteModel();
    siteModel.initByName("mutationRate", "1.0", "gammaCategoryCount", 1, "substModel", JC);
    TreeLikelihood likelihood = newTreeLikelihood();
    likelihood.initByName("data", data, "tree", tree, "siteModel", siteModel);
    double logP = 0;
    logP = likelihood.calculateLogP();
    assertEquals(logP, -1992.2056440317247, BEASTTestCase.PRECISION);
    likelihood.initByName("useAmbiguities", true, "data", data, "tree", tree, "siteModel", siteModel);
    logP = likelihood.calculateLogP();
    assertEquals(logP, -1992.2056440317247, BEASTTestCase.PRECISION);
}
Also used : Alignment(beast.evolution.alignment.Alignment) BeagleTreeLikelihood(beast.evolution.likelihood.BeagleTreeLikelihood) TreeLikelihood(beast.evolution.likelihood.TreeLikelihood) Tree(beast.evolution.tree.Tree) SiteModel(beast.evolution.sitemodel.SiteModel) JukesCantor(beast.evolution.substitutionmodel.JukesCantor) UncertainAlignmentTest(test.beast.evolution.alignment.UncertainAlignmentTest) Test(org.junit.Test)

Example 67 with Tree

use of beast.evolution.tree.Tree 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)

Example 68 with Tree

use of beast.evolution.tree.Tree in project beast2 by CompEvol.

the class TreeLikelihoodTest method testBinaryCovarionLikelihood.

@Test
public void testBinaryCovarionLikelihood() throws Exception {
    Alignment data = BEASTTestCase.getCovarionAlignment();
    Tree tree = BEASTTestCase.getTree(data, "((English_ST:0.22743347188019544,(German_ST:0.10557648379843088,Dutch_List:0.10557648379843088):0.12185698808176457):1.5793160946109988,(Spanish:0.11078392189606047,(Italian:0.10119772534558173,French:0.10119772534558173):0.009586196550478737):1.6959656445951337)");
    RealParameter alpha = new RealParameter("0.284");
    RealParameter switchRate = new RealParameter("0.829");
    RealParameter frequencies = new RealParameter("0.683 0.317");
    RealParameter hfrequencies = new RealParameter("0.5 0.5");
    BinaryCovarion covarion = new BinaryCovarion();
    covarion.initByName("alpha", alpha, "switchRate", switchRate, "vfrequencies", frequencies, "hfrequencies", hfrequencies);
    SiteModel siteModel = new SiteModel();
    siteModel.initByName("mutationRate", "1.0", "gammaCategoryCount", 1, "substModel", covarion);
    TreeLikelihood likelihood = newTreeLikelihood();
    likelihood.initByName("data", data, "tree", tree, "siteModel", siteModel);
    double logP = 0;
    likelihood.initByName("useAmbiguities", true, "data", data, "tree", tree, "siteModel", siteModel);
    logP = likelihood.calculateLogP();
    // beast1 xml gives -1730.5363
    assertEquals(logP, -1730.53631739, BEASTTestCase.PRECISION);
}
Also used : BinaryCovarion(beast.evolution.substitutionmodel.BinaryCovarion) Alignment(beast.evolution.alignment.Alignment) BeagleTreeLikelihood(beast.evolution.likelihood.BeagleTreeLikelihood) TreeLikelihood(beast.evolution.likelihood.TreeLikelihood) Tree(beast.evolution.tree.Tree) RealParameter(beast.core.parameter.RealParameter) SiteModel(beast.evolution.sitemodel.SiteModel) UncertainAlignmentTest(test.beast.evolution.alignment.UncertainAlignmentTest) Test(org.junit.Test)

Example 69 with Tree

use of beast.evolution.tree.Tree in project beast2 by CompEvol.

the class TreeAnnotatorTest method testTreeScoreAndCladeSystemSA.

@Test
public void testTreeScoreAndCladeSystemSA() throws Exception {
    for (Tree tree : treesSA) {
        cladeSystemSA.add(tree, false);
    }
    Assert.assertEquals(cladesSA.length, cladeSystemSA.getCladeMap().size());
    cladeSystemSA.calculateCladeCredibilities(treesSA.length);
    int i = 0;
    for (Map.Entry<BitSet, CladeSystem.Clade> entry : cladeSystemSA.getCladeMap().entrySet()) {
        // System.out.println(entry.getKey() + " = " + entry.getValue().getCount());
        int index = -1;
        // find the clade in the clades array
        for (int j = 0; j < cladesSA.length; j++) {
            if (cladesSA[j].equals(entry.getKey().toString())) {
                index = j;
                break;
            }
        }
        // if the clade is not found then index = -1
        Assert.assertFalse(i == -1);
        Assert.assertEquals(cladesCountSA[index], entry.getValue().getCount());
        i++;
    }
    int maxScoreIndex = -1;
    int maxScoreLogIndex = -1;
    double maxScore = Double.NEGATIVE_INFINITY;
    double maxScoreLog = Double.NEGATIVE_INFINITY;
    i = 0;
    for (Tree tree : treesSA) {
        double score = treeAnnotatorSA.scoreTree(tree, cladeSystemSA, true);
        double scoreLog = treeAnnotatorSA.scoreTree(tree, cladeSystemSA, false);
        // Assert.assertEquals(logTreeScoresSA[i], scoreLog, 1e-6);
        System.out.println(i + " => " + score + ", log " + scoreLog);
        if (maxScore < score) {
            maxScore = score;
            maxScoreIndex = i;
        }
        if (maxScoreLog < scoreLog) {
            maxScoreLog = scoreLog;
            maxScoreLogIndex = i;
        }
        i++;
    }
    // System.out.println(maxScoreIndex + " => " + maxScore + ", log " + maxScoreLog);
    Assert.assertEquals(1, maxScoreIndex);
    Assert.assertEquals(1, maxScoreLogIndex);
}
Also used : BitSet(java.util.BitSet) Tree(beast.evolution.tree.Tree) Map(java.util.Map) Test(org.junit.Test)

Example 70 with Tree

use of beast.evolution.tree.Tree in project beast2 by CompEvol.

the class BayesianSkylineTest method testSkyline.

@Test
public void testSkyline() throws Exception {
    // RealParameter popSize = new RealParameter("1.0", 0.0, 10.0, 2);
    // IntegerParameter groupSize = new IntegerParameter("2", 1, 4, 2);
    // popSize.setValue(1, 2.0);
    Tree tree = new Tree("(((1:1,2:1):2.5,(3:1.5,4:1.5):2):2,5:5.5);");
    TreeIntervals intervals = new TreeIntervals(tree);
    BayesianSkyline skyline = new BayesianSkyline();
    // skyline.init(popSize, groupSize, intervals);
    skyline.initByName("popSizes", "1.0 2.0", "groupSizes", "2 2", "treeIntervals", intervals);
    assertEquals(skyline.getPopSize(0.01), 1.0);
    assertEquals(skyline.getPopSize(1.49), 1.0);
    assertEquals(skyline.getPopSize(1.51), 2.0);
    assertEquals(skyline.getPopSize(5.51), 2.0);
}
Also used : BayesianSkyline(beast.evolution.tree.coalescent.BayesianSkyline) Tree(beast.evolution.tree.Tree) TreeIntervals(beast.evolution.tree.coalescent.TreeIntervals) Test(org.junit.Test)

Aggregations

Tree (beast.evolution.tree.Tree)70 Alignment (beast.evolution.alignment.Alignment)29 Test (org.junit.Test)26 TreeLikelihood (beast.evolution.likelihood.TreeLikelihood)22 SiteModel (beast.evolution.sitemodel.SiteModel)21 BeagleTreeLikelihood (beast.evolution.likelihood.BeagleTreeLikelihood)19 RealParameter (beast.core.parameter.RealParameter)17 UncertainAlignmentTest (test.beast.evolution.alignment.UncertainAlignmentTest)17 Node (beast.evolution.tree.Node)14 Frequencies (beast.evolution.substitutionmodel.Frequencies)13 ArrayList (java.util.ArrayList)10 TaxonSet (beast.evolution.alignment.TaxonSet)9 RandomTree (beast.evolution.tree.RandomTree)7 ClusterTree (beast.util.ClusterTree)7 ParametricDistribution (beast.math.distributions.ParametricDistribution)6 BEASTInterface (beast.core.BEASTInterface)5 CompoundDistribution (beast.core.util.CompoundDistribution)5 Sequence (beast.evolution.alignment.Sequence)5 Taxon (beast.evolution.alignment.Taxon)5 HKY (beast.evolution.substitutionmodel.HKY)5