Search in sources :

Example 11 with TreeParser

use of beast.util.TreeParser in project beast2 by CompEvol.

the class MRCAPriorTest method testMRCATimePrior.

@Test
public void testMRCATimePrior() throws Exception {
    Alignment data = BEASTTestCase.getAlignment();
    TreeParser tree = new TreeParser();
    tree.initByName("taxa", data, "newick", "((human:0.024003,(chimp:0.010772,bonobo:0.010772):0.013231):0.012035," + "(gorilla:0.024003,(orangutan:0.010772,siamang:0.010772):0.013231):0.012035);", "IsLabelledNewick", true);
    Taxon human = new Taxon();
    human.setID("human");
    Taxon bonobo = new Taxon();
    bonobo.setID("bonobo");
    Taxon chimp = new Taxon();
    chimp.setID("chimp");
    Taxon gorilla = new Taxon();
    gorilla.setID("gorilla");
    Taxon orangutan = new Taxon();
    orangutan.setID("orangutan");
    Taxon siamang = new Taxon();
    siamang.setID("siamang");
    MRCAPrior prior = new MRCAPrior();
    TaxonSet set = new TaxonSet();
    set.initByName("taxon", human, "taxon", bonobo, "taxon", chimp);
    Exponential exp = new Exponential();
    /* get distribution for set (human, bonobo, chimp) */
    prior.initByName("tree", tree, "taxonset", set, "monophyletic", true, "distr", exp);
    double logP = prior.calculateLogP();
    assertEquals(-0.024003, logP, BEASTTestCase.PRECISION);
    /* get distribution for set (human, chimp), do not require the set to by monophyletic */
    set = new TaxonSet();
    set.initByName("taxon", human, "taxon", chimp);
    prior.initByName("tree", tree, "taxonset", set, "monophyletic", false);
    logP = prior.calculateLogP();
    assertEquals(-0.024003, logP, BEASTTestCase.PRECISION);
    /* get distribution for set (human, chimp), DO require the set to by monophyletic */
    prior.initByName("tree", tree, "taxonset", set, "monophyletic", true);
    logP = prior.calculateLogP();
    assertEquals(Double.NEGATIVE_INFINITY, logP, 0);
    /* get distribution for set (human, gorilla) = root, not monophyletic */
    set = new TaxonSet();
    set.initByName("taxon", human, "taxon", gorilla);
    prior.initByName("tree", tree, "taxonset", set, "monophyletic", false);
    logP = prior.calculateLogP();
    assertEquals(-0.024003 - 0.012035, logP, BEASTTestCase.PRECISION);
}
Also used : Alignment(beast.evolution.alignment.Alignment) TreeParser(beast.util.TreeParser) Taxon(beast.evolution.alignment.Taxon) MRCAPrior(beast.math.distributions.MRCAPrior) Exponential(beast.math.distributions.Exponential) TaxonSet(beast.evolution.alignment.TaxonSet) Test(org.junit.Test)

Example 12 with TreeParser

use of beast.util.TreeParser in project beast2 by CompEvol.

the class MRCAPriorTest method testSingleMonophyleticConstraint.

@Test
public void testSingleMonophyleticConstraint() throws Exception {
    Alignment data = BEASTTestCase.getAlignment();
    TreeParser tree = new TreeParser();
    tree.initByName("taxa", data, "newick", "((human:0.024003,(chimp:0.010772,bonobo:0.010772):0.013231):0.012035," + "(gorilla:0.024003,(orangutan:0.010772,siamang:0.010772):0.013231):0.012035);", "IsLabelledNewick", true);
    Taxon human = new Taxon();
    human.setID("human");
    Taxon bonobo = new Taxon();
    bonobo.setID("bonobo");
    Taxon chimp = new Taxon();
    chimp.setID("chimp");
    Taxon gorilla = new Taxon();
    gorilla.setID("gorilla");
    Taxon orangutan = new Taxon();
    orangutan.setID("orangutan");
    Taxon siamang = new Taxon();
    siamang.setID("siamang");
    MRCAPrior prior = new MRCAPrior();
    /* check (human, bonobo, chimp) is monophyletic **/
    TaxonSet set = new TaxonSet();
    set.initByName("taxon", human, "taxon", bonobo, "taxon", chimp);
    prior.initByName("tree", tree, "taxonset", set, "monophyletic", true);
    double logP = prior.calculateLogP();
    assertEquals(logP, 0, 0);
    /* check (gorilla, siamang) is NOT monophyletic **/
    set = new TaxonSet();
    set.initByName("taxon", gorilla, "taxon", siamang);
    prior.initByName("tree", tree, "taxonset", set, "monophyletic", true);
    logP = prior.calculateLogP();
    assertEquals(logP, Double.NEGATIVE_INFINITY, 0);
    /* check (gorilla, orangutan, siamang) is monophyletic **/
    set = new TaxonSet();
    set.initByName("taxon", gorilla, "taxon", orangutan, "taxon", siamang);
    prior.initByName("tree", tree, "taxonset", set, "monophyletic", true);
    logP = prior.calculateLogP();
    assertEquals(logP, 0, 0);
    /* check (human, gorilla) is NOT monophyletic **/
    set = new TaxonSet();
    set.initByName("taxon", human, "taxon", gorilla);
    prior.initByName("tree", tree, "taxonset", set, "monophyletic", true);
    logP = prior.calculateLogP();
    assertEquals(logP, Double.NEGATIVE_INFINITY, 0);
    set.setID("test");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(baos);
    prior.init(ps);
    String log = new String(baos.toByteArray(), StandardCharsets.UTF_8);
    assertEquals(log, "mrcatime(test)\t");
    baos = new ByteArrayOutputStream();
    ps = new PrintStream(baos);
    prior.initByName("tree", tree, "taxonset", set, "monophyletic", true, "useOriginate", true);
    prior.init(ps);
    log = new String(baos.toByteArray(), StandardCharsets.UTF_8);
    assertEquals(log, "mrcatime(test.originate)\t");
}
Also used : PrintStream(java.io.PrintStream) Alignment(beast.evolution.alignment.Alignment) TreeParser(beast.util.TreeParser) Taxon(beast.evolution.alignment.Taxon) MRCAPrior(beast.math.distributions.MRCAPrior) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TaxonSet(beast.evolution.alignment.TaxonSet) Test(org.junit.Test)

Example 13 with TreeParser

use of beast.util.TreeParser in project beast2 by CompEvol.

the class TreeParserTest method testBinarization.

@Test
public void testBinarization() throws Exception {
    String newick = "((A:1.0,B:1.0,C:1.0):1.0,(D:1.0,E:1.0,F:1.0,G:1.0):1.0):0.0;";
    String binaryNewick = "((A:1.0,(B:1.0,C:1.0):0.0):1.0,(D:1.0,(E:1.0,(F:1.0,G:1.0):0.0):0.0):1.0):0.0;";
    boolean isLabeled = true;
    TreeParser treeParser = new TreeParser(newick, false, false, isLabeled, 1);
    Assert.assertEquals(binaryNewick.split(";")[0], treeParser.getRoot().toNewick());
}
Also used : TreeParser(beast.util.TreeParser) Test(org.junit.Test)

Example 14 with TreeParser

use of beast.util.TreeParser in project beast2 by CompEvol.

the class TreeParserTest method testSomeInternalNodesLabelled.

@Test
public void testSomeInternalNodesLabelled() {
    String newick = "((A:1.0,B:1.0)E:1.0,(C:1.0,D:1.0):1.0):0.0;";
    try {
        boolean isLabeled = true;
        TreeParser treeParser = new TreeParser(newick, false, false, isLabeled, 1);
        Assert.assertEquals(newick.split(";")[0], treeParser.getRoot().toNewick());
    } catch (Exception e) {
        // To change body of catch statement use File | Settings | File Templates.  \
        e.printStackTrace();
        Assert.assertTrue("Exception!", false);
    }
}
Also used : TreeParser(beast.util.TreeParser) Test(org.junit.Test)

Example 15 with TreeParser

use of beast.util.TreeParser in project beast2 by CompEvol.

the class TreeParserTest method testOnlyLeafLabels.

@Test
public void testOnlyLeafLabels() throws Exception {
    String newick = "((A:1.0,B:1.0):1.0,(C:1.0,D:1.0):1.0):0.0;";
    boolean isLabeled = true;
    TreeParser treeParser = new TreeParser(newick, false, false, isLabeled, 1);
    System.out.println("adfgad");
    Assert.assertEquals(newick.split(";")[0], treeParser.getRoot().toNewick());
}
Also used : TreeParser(beast.util.TreeParser) Test(org.junit.Test)

Aggregations

TreeParser (beast.util.TreeParser)37 Test (org.junit.Test)23 Alignment (beast.evolution.alignment.Alignment)6 Sequence (beast.evolution.alignment.Sequence)3 Node (beast.evolution.tree.Node)3 Taxon (beast.evolution.alignment.Taxon)2 TaxonSet (beast.evolution.alignment.TaxonSet)2 Tree (beast.evolution.tree.Tree)2 MRCAPrior (beast.math.distributions.MRCAPrior)2 PrintStream (java.io.PrintStream)2 ArrayList (java.util.ArrayList)2 CladeSystem (beast.app.treeannotator.CladeSystem)1 TreeAnnotator (beast.app.treeannotator.TreeAnnotator)1 State (beast.core.State)1 StateNode (beast.core.StateNode)1 RealParameter (beast.core.parameter.RealParameter)1 BeagleTreeLikelihood (beast.evolution.likelihood.BeagleTreeLikelihood)1 Exchange (beast.evolution.operators.Exchange)1 ScaleOperator (beast.evolution.operators.ScaleOperator)1 SiteModel (beast.evolution.sitemodel.SiteModel)1