| 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 CherryStatistic extends AbstractTreeSummaryStatistic { |
| 38 |
|
| 39 |
private CherryStatistic() { } |
| 40 |
|
| 41 |
public double[] getSummaryStatistic(Tree tree) { |
| 42 |
|
| 43 |
int cherryCount = 0; |
| 44 |
|
| 45 |
int internalNodeCount = tree.getInternalNodeCount(); |
| 46 |
for (int i = 0; i < internalNodeCount; i++) { |
| 47 |
NodeRef node = tree.getInternalNode(i); |
| 48 |
boolean allChildrenExternal = true; |
| 49 |
for (int j = 0; j < tree.getChildCount(node); j++) { |
| 50 |
if (!tree.isExternal(tree.getChild(node, j))) { |
| 51 |
allChildrenExternal = false; |
| 52 |
} |
| 53 |
} |
| 54 |
if (allChildrenExternal) cherryCount += 1; |
| 55 |
} |
| 56 |
return new double[] { (double)cherryCount }; |
| 57 |
} |
| 58 |
|
| 59 |
public String getSummaryStatisticName() { return FACTORY.getSummaryStatisticName(); } |
| 60 |
public String getSummaryStatisticDescription() { return FACTORY.getSummaryStatisticDescription(); } |
| 61 |
public String getSummaryStatisticReference() { return FACTORY.getSummaryStatisticReference(); } |
| 62 |
public boolean allowsPolytomies() { return FACTORY.allowsPolytomies(); } |
| 63 |
public boolean allowsNonultrametricTrees() { return FACTORY.allowsNonultrametricTrees(); } |
| 64 |
public boolean allowsUnrootedTrees() { return FACTORY.allowsUnrootedTrees(); } |
| 65 |
public SummaryStatisticDescription.Category getCategory() { return FACTORY.getCategory(); } |
| 66 |
|
| 67 |
public static final TreeSummaryStatistic.Factory FACTORY = new TreeSummaryStatistic.Factory() { |
| 68 |
|
| 69 |
public TreeSummaryStatistic createStatistic() { |
| 70 |
return new CherryStatistic(); |
| 71 |
} |
| 72 |
|
| 73 |
public String getSummaryStatisticName() { |
| 74 |
return "Cherry count"; |
| 75 |
} |
| 76 |
|
| 77 |
public String getSummaryStatisticDescription() { |
| 78 |
|
| 79 |
return "The number of internal nodes that have only tips as children."; |
| 80 |
} |
| 81 |
|
| 82 |
public String getSummaryStatisticReference() { |
| 83 |
return "Steel and McKenzie (2001)"; |
| 84 |
} |
| 85 |
|
| 86 |
public boolean allowsPolytomies() { return true; } |
| 87 |
|
| 88 |
public boolean allowsNonultrametricTrees() { return true; } |
| 89 |
|
| 90 |
public boolean allowsUnrootedTrees() { return false; } |
| 91 |
|
| 92 |
public SummaryStatisticDescription.Category getCategory() { return SummaryStatisticDescription.Category.TREE_SHAPE; } |
| 93 |
}; |
| 94 |
} |