Search in sources :

Example 26 with TreeParser

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

the class NodeTest method setUp.

@Override
public void setUp() throws Exception {
    for (int i = 0; i < trees.length; i++) {
        TreeParser newickTree = new TreeParser(trees[i], false, false, true, 1);
        roots[i] = newickTree.getRoot();
    }
}
Also used : TreeParser(beast.util.TreeParser)

Example 27 with TreeParser

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

the class NodeTest method testNonBinarySortedNewickTest.

@Test
public void testNonBinarySortedNewickTest() {
    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;";
    TreeParser treeParser = new TreeParser();
    treeParser.initByName("IsLabelledNewick", true, "newick", newick, "adjustTipHeights", false, "binarizeMultifurcations", false);
    String sortedNewick = treeParser.getRoot().toSortedNewick(new int[1], false);
    String goal = "((1:1.0,2:1.0,3:1.0):1.0,(4:1.0,5:1.0,6:1.0,7:1.0):1.0):0.0";
    assertEquals(goal.split(";")[0], sortedNewick);
}
Also used : TreeParser(beast.util.TreeParser) Test(org.junit.Test)

Example 28 with TreeParser

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

the class TreeTest method testTreeScaling.

@Test
public void testTreeScaling() {
    String newick = "((0:1.0,1:1.0)4:1.0,(2:1.0,3:1.0)5:0.5)6:0.0;";
    TreeParser treeParser = new TreeParser(newick, false, false, false, 0);
    Node[] node = treeParser.getNodesAsArray();
    assertEquals(0.0, node[0].getHeight(), EPSILON);
    assertEquals(0.0, node[1].getHeight(), EPSILON);
    // leaf node, not scaled
    assertEquals(0.5, node[2].getHeight(), EPSILON);
    assertEquals(0.5, node[3].getHeight(), EPSILON);
    // internal nodes, all scaled
    assertEquals(1.0, node[4].getHeight(), EPSILON);
    assertEquals(1.5, node[5].getHeight(), EPSILON);
    assertEquals(2.0, node[6].getHeight(), EPSILON);
    treeParser.scale(2.0);
    // leaf node
    node = treeParser.getNodesAsArray();
    assertEquals(0.0, node[0].getHeight(), EPSILON);
    assertEquals(0.0, node[1].getHeight(), EPSILON);
    // leaf node, not scaled
    assertEquals(0.5, node[2].getHeight(), EPSILON);
    assertEquals(0.5, node[3].getHeight(), EPSILON);
    // internal nodes, all scaled
    assertEquals(2.0, node[4].getHeight(), EPSILON);
    assertEquals(3.0, node[5].getHeight(), EPSILON);
    assertEquals(4.0, node[6].getHeight(), EPSILON);
}
Also used : TreeParser(beast.util.TreeParser) Node(beast.evolution.tree.Node) Test(org.junit.Test)

Example 29 with TreeParser

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

the class Utils method main.

public static void main(String[] args) {
    try {
        Sequence a = new Sequence("A", "A");
        Sequence b = new Sequence("B", "A");
        Sequence c = new Sequence("C", "A");
        Sequence d = new Sequence("D", "A");
        Alignment data = new Alignment();
        data.initByName("sequence", a, "sequence", b, "sequence", c, "sequence", d, "dataType", "nucleotide");
        TreeParser tree = new TreeParser();
        tree.initByName("taxa", data, "newick", "(((A:1,B:1):1,C:2):1,D:3)", "IsLabelledNewick", true);
        JukesCantor JC = new JukesCantor();
        JC.initAndValidate();
        SiteModel siteModel = new SiteModel();
        siteModel.initByName("mutationRate", "1.0", "gammaCategoryCount", 1, "substModel", JC);
        BeagleTreeLikelihood likelihood = new BeagleTreeLikelihood();
        likelihood.initByName("data", data, "tree", tree, "siteModel", siteModel);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    System.out.println("Success");
    // if we got this far, exit with status 0
    System.exit(0);
}
Also used : BeagleTreeLikelihood(beast.evolution.likelihood.BeagleTreeLikelihood) Alignment(beast.evolution.alignment.Alignment) TreeParser(beast.util.TreeParser) SiteModel(beast.evolution.sitemodel.SiteModel) Sequence(beast.evolution.alignment.Sequence) JukesCantor(beast.evolution.substitutionmodel.JukesCantor) UnsupportedLookAndFeelException(javax.swing.UnsupportedLookAndFeelException) IOException(java.io.IOException)

Example 30 with TreeParser

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

the class BEASTTestCase method getAminoAcidTree.

public static Tree getAminoAcidTree(Alignment data) throws Exception {
    TreeParser tree = new TreeParser();
    tree.initByName("taxa", data, "newick", "(Struthio_camelus:0.09413496891819266,(Rhea_americana:0.03667415617018579,Pterocnemia_pennata:0.03667415617018579):0.05746081274800687);", "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