| 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 |
package dr.app.treestat.statistics; |
| 27 |
|
| 28 |
import dr.evolution.tree.NodeRef; |
| 29 |
import dr.evolution.tree.Tree; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
public class ExternalInternalRatio extends AbstractTreeSummaryStatistic { |
| 37 |
|
| 38 |
private ExternalInternalRatio() { } |
| 39 |
|
| 40 |
public double[] getSummaryStatistic(Tree tree) { |
| 41 |
|
| 42 |
double externalLength = 0.0; |
| 43 |
double internalLength = 0.0; |
| 44 |
|
| 45 |
int externalNodeCount = tree.getExternalNodeCount(); |
| 46 |
for (int i = 0; i < externalNodeCount; i++) { |
| 47 |
NodeRef node = tree.getExternalNode(i); |
| 48 |
NodeRef parent = tree.getParent(node); |
| 49 |
externalLength += tree.getNodeHeight(parent) - tree.getNodeHeight(node); |
| 50 |
} |
| 51 |
|
| 52 |
int internalNodeCount = tree.getInternalNodeCount(); |
| 53 |
for (int i = 0; i < internalNodeCount; i++) { |
| 54 |
NodeRef node = tree.getInternalNode(i); |
| 55 |
if (!tree.isRoot(node)) { |
| 56 |
NodeRef parent = tree.getParent(node); |
| 57 |
internalLength += tree.getNodeHeight(parent) - tree.getNodeHeight(node); |
| 58 |
} |
| 59 |
} |
| 60 |
return new double[] { externalLength/internalLength }; |
| 61 |
} |
| 62 |
|
| 63 |
public String getSummaryStatisticName() { |
| 64 |
return FACTORY.getSummaryStatisticName(); |
| 65 |
} |
| 66 |
|
| 67 |
public String getSummaryStatisticDescription() { |
| 68 |
return FACTORY.getSummaryStatisticDescription(); |
| 69 |
} |
| 70 |
|
| 71 |
public String getSummaryStatisticReference() { |
| 72 |
return FACTORY.getSummaryStatisticReference(); |
| 73 |
} |
| 74 |
|
| 75 |
public boolean allowsPolytomies() { return FACTORY.allowsPolytomies(); } |
| 76 |
|
| 77 |
public boolean allowsNonultrametricTrees() { return FACTORY.allowsNonultrametricTrees(); } |
| 78 |
|
| 79 |
public boolean allowsUnrootedTrees() { return FACTORY.allowsUnrootedTrees(); } |
| 80 |
|
| 81 |
public SummaryStatisticDescription.Category getCategory() { return FACTORY.getCategory(); } |
| 82 |
|
| 83 |
|
| 84 |
public static final TreeSummaryStatistic.Factory FACTORY = new TreeSummaryStatistic.Factory() { |
| 85 |
|
| 86 |
public TreeSummaryStatistic createStatistic() { |
| 87 |
return new ExternalInternalRatio(); |
| 88 |
} |
| 89 |
|
| 90 |
public String getSummaryStatisticName() { |
| 91 |
return "External/Internal ratio"; |
| 92 |
} |
| 93 |
|
| 94 |
public String getSummaryStatisticDescription() { |
| 95 |
|
| 96 |
return "The ratio of the total length of external branches to the " + |
| 97 |
"total length of internal branches."; |
| 98 |
} |
| 99 |
|
| 100 |
public String getSummaryStatisticReference() { |
| 101 |
return "-"; |
| 102 |
} |
| 103 |
|
| 104 |
public boolean allowsPolytomies() { return true; } |
| 105 |
|
| 106 |
public boolean allowsNonultrametricTrees() { return true; } |
| 107 |
|
| 108 |
public boolean allowsUnrootedTrees() { return false; } |
| 109 |
|
| 110 |
public SummaryStatisticDescription.Category getCategory() { return SummaryStatisticDescription.Category.POPULATION_GENETIC; } |
| 111 |
|
| 112 |
}; |
| 113 |
} |