Debian Codegraph @

src/dr/evolution/tree/treemetrics/RootedBranchScoreMetric.java

raw symbols SCIP
1 /*
2 * RootedBranchScoreMetric.java
3 *
4 * Copyright (c) 2002-2018 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
24 */
25
26 /**
27 *
28 */
29 package dr.evolution.tree.treemetrics;
30
31 import dr.evolution.tree.Clade;
32 import dr.evolution.tree.NodeRef;
33 import dr.evolution.tree.Tree;
34 import dr.util.Author;
35 import dr.util.Citable;
36 import dr.util.Citation;
37
38 import java.util.Collections;
39 import java.util.List;
40
41 /**
42 * @author Guy Baele
43 *
44 */
45 public class RootedBranchScoreMetric extends BranchScoreMetric implements Citable {
46
47 public static Type TYPE = Type.ROOTED_BRANCH_SCORE;
48
49 public RootedBranchScoreMetric() {
50 }
51
52 @Override
53 public double getMetric(Tree tree1, Tree tree2) {
54
55 TreeMetric.Utils.checkTreeTaxa(tree1, tree2);
56
57 List<Clade> clades1 = Clade.getCladeList(tree1);
58 List<Clade> clades2 = Clade.getCladeList(tree2);
59
60 return Math.sqrt(Math.pow(getDistance(clades1, clades2), 2) + getExternalDistance(tree1, tree2));
61 }
62
63 private double getExternalDistance(Tree tree1, Tree tree2) {
64
65 double distance = 0.0;
66
67 for (int i = 0; i < tree1.getExternalNodeCount(); i++) {
68 NodeRef node1 = tree1.getExternalNode(i);
69 NodeRef node2 = tree2.getExternalNode(i);
70 NodeRef parent1 = tree1.getParent(node1);
71 NodeRef parent2 = tree2.getParent(node2);
72 distance += Math.pow(
73 (tree1.getNodeHeight(parent1) - tree1.getNodeHeight(node1))-
74 (tree2.getNodeHeight(parent2) - tree2.getNodeHeight(node2)), 2);
75 }
76
77 return distance;
78
79 }
80
81 @Override
82 public Type getType() {
83 return TYPE;
84 }
85
86 @Override
87 public String toString() {
88 return getType().getShortName();
89 }
90
91 @Override
92 public Citation.Category getCategory() {
93 return Citation.Category.TREE_METRICS;
94 }
95
96 @Override
97 public String getDescription() {
98 return "Normalized Rooted Branch Score";
99 }
100
101 @Override
102 public List<Citation> getCitations() {
103 return Collections.singletonList(CITATION);
104 }
105
106 public static Citation CITATION = new Citation(
107 new Author[]{
108 new Author("J", "Heled"),
109 new Author("AJ", "Drummond")
110 },
111 "Bayesian inference of species trees from multilocus data",
112 2010,
113 "Mol. Biol. Evol.",
114 27,
115 570, 580,
116 Citation.Status.PUBLISHED
117 );
118
119 }