| 1 |
package dr.evolution.tree.treemetrics; |
| 2 |
|
| 3 |
import dr.evolution.tree.Tree; |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
public interface TreeMetric { |
| 10 |
|
| 11 |
double getMetric(Tree tree1, Tree tree2); |
| 12 |
|
| 13 |
Type getType(); |
| 14 |
|
| 15 |
enum Type { |
| 16 |
ROBINSON_FOULDS("Robinson-Foulds", "rf"), |
| 17 |
BRANCH_SCORE("branch score", "branchscore"), |
| 18 |
ROOTED_BRANCH_SCORE("rooted branch score", "branch"), |
| 19 |
CLADE_HEIGHT("clade height", "clade"), |
| 20 |
KENDALL_COLIJN("Kendall-Colijn path difference", "kc"), |
| 21 |
STEEL_PENNY("Steel-Penny path difference", "sp"); |
| 22 |
|
| 23 |
Type(String name, String stortName) { |
| 24 |
this.name = name; |
| 25 |
this.stortName = stortName; |
| 26 |
} |
| 27 |
|
| 28 |
public String getName() { |
| 29 |
return name; |
| 30 |
} |
| 31 |
|
| 32 |
public String getShortName() { |
| 33 |
return stortName; |
| 34 |
} |
| 35 |
|
| 36 |
@Override |
| 37 |
public String toString() { |
| 38 |
return getName(); |
| 39 |
} |
| 40 |
|
| 41 |
private final String name; |
| 42 |
private final String stortName; |
| 43 |
} |
| 44 |
|
| 45 |
class Utils { |
| 46 |
static void checkTreeTaxa(Tree tree1, Tree tree2) { |
| 47 |
|
| 48 |
if (tree1.getExternalNodeCount() != tree2.getExternalNodeCount()) { |
| 49 |
throw new RuntimeException("Different number of taxa in both trees."); |
| 50 |
} else { |
| 51 |
for (int i = 0; i < tree1.getExternalNodeCount(); i++) { |
| 52 |
if (!tree1.getNodeTaxon(tree1.getExternalNode(i)).getId().equals(tree2.getNodeTaxon(tree2.getExternalNode(i)).getId())) { |
| 53 |
throw new RuntimeException("Mismatch between taxa in both trees: " + tree1.getNodeTaxon(tree1.getExternalNode(i)).getId() + " vs. " + tree2.getNodeTaxon(tree2.getExternalNode(i)).getId()); |
| 54 |
} |
| 55 |
} |
| 56 |
} |
| 57 |
} |
| 58 |
} |
| 59 |
} |