Debian Codegraph @

src/test/dr/evolution/TreeMetricsTest.java

raw symbols SCIP
1 package test.dr.evolution;
2
3 import dr.evolution.io.Importer;
4 import dr.evolution.io.NewickImporter;
5 import dr.evolution.tree.*;
6 import dr.evolution.tree.treemetrics.BranchScoreMetric;
7 import dr.evolution.tree.treemetrics.SteelPennyPathDifferenceMetric;
8 import dr.evolution.tree.treemetrics.RobinsonFouldsMetric;
9 import junit.framework.TestCase;
10
11 import java.io.*;
12
13 /**
14 * @author Luiz Carvalho
15 */
16 public class TreeMetricsTest extends TestCase {
17
18 public static void main(String[] args) {
19
20 try {
21
22 NewickImporter importer = new NewickImporter("((A:0.1,B:0.1):0.1,(C:0.1,D:0.1):0.1)");
23 Tree treeOne = importer.importNextTree();
24 System.out.println("tree 1: " + treeOne);
25
26 importer = new NewickImporter("(((A:0.1,B:0.1):0.5,C:0.1):0.1,D:0.1)");
27 Tree treeTwo = importer.importNextTree();
28 System.out.println("tree 2: " + treeTwo + "\n");
29
30 /* Billera et al., 2001 */
31
32 // double billera = (new BilleraMetric().getMetric(TreeUtils.asJeblTree(treeOne),
33 // TreeUtils.asJeblTree(treeTwo)));
34 //
35 // System.out.println("Billera distance = " + billera);
36 // assertEquals(billera, 0.2236068);
37
38 /* Robinson & Foulds, 1981*/
39 double RF = (new RobinsonFouldsMetric().getMetric(treeOne, treeTwo)*2.0);
40 System.out.println("Robinson-Foulds = " + RF);
41 assertEquals(RF, 2.0, 0.0000001);
42
43 /* Penny and Hendy, 1993*/
44 double path = (new SteelPennyPathDifferenceMetric().getMetric(treeOne, treeTwo));
45 System.out.println("path difference = " + path);
46 assertEquals(path, 0.7141428, 0.0000001);
47
48 /* Branch Score*/
49 double bl = (new BranchScoreMetric().getMetric(treeOne, treeTwo));
50 System.out.println("bl score = " + bl);
51 assertEquals(bl, Math.sqrt(Math.pow(0.5-0.1, 2) + Math.pow(.1, 2) + Math.pow(.1, 2)), 0.0000001);
52
53
54 } catch(Importer.ImportException ie) {
55 System.err.println(ie);
56 } catch(IOException ioe) {
57 System.err.println(ioe);
58 }
59
60 }
61
62 }
63