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();
}
}
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);
}
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);
}
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);
}
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;
}
Aggregations