Search in sources :

Example 1 with TreeParser

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

the class YuleModelTest method testYule.

@Test
public void testYule() throws Exception {
    YuleModel bdssm = new YuleModel();
    Tree tree1 = new TreeParser("((A:1.0,B:1.0):1.0,C:2.0);", false);
    bdssm.setInputValue("tree", tree1);
    bdssm.setInputValue("birthDiffRate", new RealParameter("10."));
    bdssm.setInputValue("originHeight", new RealParameter("10."));
    bdssm.initAndValidate();
    double logP1 = bdssm.calculateTreeLogLikelihood(tree1);
    Tree tree = new TreeParser("((A:1.0,B:1.0):2.0,C:3.0);", false);
    bdssm.setInputValue("tree", tree);
    bdssm.setInputValue("birthDiffRate", new RealParameter("10."));
    bdssm.setInputValue("originHeight", new RealParameter("10."));
    bdssm.initAndValidate();
    double logP2 = bdssm.calculateTreeLogLikelihood(tree);
    assertEquals(logP1 - logP2, 10.0);
}
Also used : TreeParser(beast.util.TreeParser) Tree(beast.evolution.tree.Tree) RealParameter(beast.core.parameter.RealParameter) YuleModel(beast.evolution.speciation.YuleModel) Test(org.junit.Test)

Example 2 with TreeParser

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

the class Tree method fromXML.

/**
 * reconstruct tree from XML fragment in the form of a DOM node *
 */
@Override
public void fromXML(final org.w3c.dom.Node node) {
    final String newick = node.getTextContent();
    final TreeParser parser = new TreeParser();
    try {
        parser.thresholdInput.setValue(1e-10, parser);
    } catch (Exception e1) {
        e1.printStackTrace();
    }
    try {
        parser.offsetInput.setValue(0, parser);
        setRoot(parser.parseNewick(newick));
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    initArrays();
}
Also used : TreeParser(beast.util.TreeParser)

Example 3 with TreeParser

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

the class StateNodeInitialiserTest method testClusterTree.

@Test
public void testClusterTree() throws Exception {
    Alignment data = BEASTTestCase.getAlignment();
    Tree tree = new Tree();
    tree.initAndValidate();
    assertEquals(true, tree.getNodeCount() == 1);
    TreeParser tree2 = new TreeParser();
    tree2.initByName("initial", tree, "taxa", data, "newick", "((((human:0.024003,(chimp:0.010772,bonobo:0.010772):0.013231):0.012035,gorilla:0.036038):0.033087000000000005,orangutan:0.069125):0.030456999999999998,siamang:0.099582);", "IsLabelledNewick", true);
    assertEquals(true, tree.getNodeCount() > 1);
    assertEquals(11, tree.getNodeCount());
}
Also used : Alignment(beast.evolution.alignment.Alignment) TreeParser(beast.util.TreeParser) Tree(beast.evolution.tree.Tree) ClusterTree(beast.util.ClusterTree) Test(org.junit.Test)

Example 4 with TreeParser

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

the class NodeTest method testBinarySortedNewickTest.

@Test
public void testBinarySortedNewickTest() {
    String newick = "((D:5.0,C:4.0):6.0,(A:1.0,B:2.0):3.0):0.0;";
    TreeParser treeParser = new TreeParser();
    treeParser.initByName("IsLabelledNewick", true, "newick", newick, "adjustTipHeights", false);
    String sortedNewick = treeParser.getRoot().toSortedNewick(new int[1], false);
    String goal = "((1:1.0,2:2.0):3.0,(3:4.0,4:5.0):6.0):0.0";
    assertEquals(goal.split(";")[0], sortedNewick);
}
Also used : TreeParser(beast.util.TreeParser) Test(org.junit.Test)

Example 5 with TreeParser

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

the class UncertainAlignmentTest method getTreeA.

public static Tree getTreeA(Alignment data) throws Exception {
    TreeParser tree = new TreeParser();
    tree.initByName("taxa", data, "newick", "((seq1:1,seq2:1):1,seq3:2);", "IsLabelledNewick", true);
    return tree;
}
Also used : TreeParser(beast.util.TreeParser)

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