| 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 |
|
| 37 |
public class TreenessStatistic extends AbstractTreeSummaryStatistic { |
| 38 |
|
| 39 |
private TreenessStatistic() { } |
| 40 |
|
| 41 |
public double[] getSummaryStatistic(Tree tree) { |
| 42 |
|
| 43 |
double externalLength = 0.0; |
| 44 |
double internalLength = 0.0; |
| 45 |
|
| 46 |
int externalNodeCount = tree.getExternalNodeCount(); |
| 47 |
for (int i = 0; i < externalNodeCount; i++) { |
| 48 |
NodeRef node = tree.getExternalNode(i); |
| 49 |
NodeRef parent = tree.getParent(node); |
| 50 |
externalLength += tree.getNodeHeight(parent) - tree.getNodeHeight(node); |
| 51 |
} |
| 52 |
|
| 53 |
int internalNodeCount = tree.getInternalNodeCount(); |
| 54 |
for (int i = 0; i < internalNodeCount; i++) { |
| 55 |
NodeRef node = tree.getInternalNode(i); |
| 56 |
if (!tree.isRoot(node)) { |
| 57 |
NodeRef parent = tree.getParent(node); |
| 58 |
internalLength += tree.getNodeHeight(parent) - tree.getNodeHeight(node); |
| 59 |
} |
| 60 |
} |
| 61 |
return new double[] { internalLength/(internalLength+externalLength) }; |
| 62 |
} |
| 63 |
|
| 64 |
public String getSummaryStatisticName() { return FACTORY.getSummaryStatisticName(); } |
| 65 |
public String getSummaryStatisticDescription() { return FACTORY.getSummaryStatisticDescription(); } |
| 66 |
public String getSummaryStatisticReference() { return FACTORY.getSummaryStatisticReference(); } |
| 67 |
public boolean allowsPolytomies() { return FACTORY.allowsPolytomies(); } |
| 68 |
public boolean allowsNonultrametricTrees() { return FACTORY.allowsNonultrametricTrees(); } |
| 69 |
public boolean allowsUnrootedTrees() { return FACTORY.allowsUnrootedTrees(); } |
| 70 |
public SummaryStatisticDescription.Category getCategory() { return FACTORY.getCategory(); } |
| 71 |
|
| 72 |
public static final TreeSummaryStatistic.Factory FACTORY = new TreeSummaryStatistic.Factory() { |
| 73 |
|
| 74 |
public TreeSummaryStatistic createStatistic() { |
| 75 |
return new TreenessStatistic(); |
| 76 |
} |
| 77 |
|
| 78 |
public String getSummaryStatisticName() { |
| 79 |
return "Treeness"; |
| 80 |
} |
| 81 |
|
| 82 |
public String getSummaryStatisticDescription() { |
| 83 |
|
| 84 |
return "The proportion of the total length of the tree that is taken up by internal branches. " + |
| 85 |
"Interpreted as a signal/(signal+noise) measure for phylogenetic reconstruction."; |
| 86 |
} |
| 87 |
|
| 88 |
public String getSummaryStatisticReference() { |
| 89 |
|
| 90 |
return "see Phillips & Penny (2001)"; |
| 91 |
} |
| 92 |
|
| 93 |
public boolean allowsPolytomies() { return true; } |
| 94 |
|
| 95 |
public boolean allowsNonultrametricTrees() { return true; } |
| 96 |
|
| 97 |
public boolean allowsUnrootedTrees() { return true; } |
| 98 |
|
| 99 |
public SummaryStatisticDescription.Category getCategory() { return SummaryStatisticDescription.Category.PHYLOGENETIC; } |
| 100 |
}; |
| 101 |
} |