| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 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 |
|
| 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 |
} |