| 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 |
import dr.evolution.util.TaxonList; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
public class InternalBranchLengths implements TreeSummaryStatistic { |
| 36 |
|
| 37 |
private InternalBranchLengths() { |
| 38 |
} |
| 39 |
|
| 40 |
public int getStatisticDimensions(Tree tree) { |
| 41 |
return tree.getInternalNodeCount() - 1; |
| 42 |
} |
| 43 |
|
| 44 |
public String getStatisticLabel(Tree tree, int i) { |
| 45 |
return "Branch " + Integer.toString(i + 1); |
| 46 |
} |
| 47 |
|
| 48 |
public double[] getSummaryStatistic(Tree tree) { |
| 49 |
|
| 50 |
int internalNodeCount = tree.getInternalNodeCount(); |
| 51 |
double[] stats = new double[internalNodeCount - 1]; |
| 52 |
int count = 0; |
| 53 |
for (int i = 0; i < internalNodeCount; i++) { |
| 54 |
NodeRef node = tree.getInternalNode(i); |
| 55 |
if (!tree.isRoot(node)) { |
| 56 |
stats[count++] = |
| 57 |
tree.getNodeHeight(tree.getParent(node)) - tree.getNodeHeight(node); |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
return stats; |
| 63 |
} |
| 64 |
|
| 65 |
public void setTaxonList(TaxonList taxonList) { |
| 66 |
throw new UnsupportedOperationException("not implemented in this statistic"); |
| 67 |
} |
| 68 |
|
| 69 |
public void setInteger(int value) { |
| 70 |
throw new UnsupportedOperationException("not implemented in this statistic"); |
| 71 |
} |
| 72 |
|
| 73 |
public void setDouble(double value) { |
| 74 |
throw new UnsupportedOperationException("not implemented in this statistic"); |
| 75 |
} |
| 76 |
|
| 77 |
public void setString(String value) { |
| 78 |
throw new UnsupportedOperationException("not implemented in this statistic"); |
| 79 |
} |
| 80 |
|
| 81 |
public String getSummaryStatisticName() { |
| 82 |
return FACTORY.getSummaryStatisticName(); |
| 83 |
} |
| 84 |
|
| 85 |
public String getSummaryStatisticDescription() { |
| 86 |
return FACTORY.getSummaryStatisticDescription(); |
| 87 |
} |
| 88 |
|
| 89 |
public String getSummaryStatisticReference() { |
| 90 |
return FACTORY.getSummaryStatisticReference(); |
| 91 |
} |
| 92 |
|
| 93 |
public boolean allowsPolytomies() { |
| 94 |
return FACTORY.allowsPolytomies(); |
| 95 |
} |
| 96 |
|
| 97 |
public boolean allowsNonultrametricTrees() { |
| 98 |
return FACTORY.allowsNonultrametricTrees(); |
| 99 |
} |
| 100 |
|
| 101 |
public boolean allowsUnrootedTrees() { |
| 102 |
return FACTORY.allowsUnrootedTrees(); |
| 103 |
} |
| 104 |
|
| 105 |
public Category getCategory() { |
| 106 |
return FACTORY.getCategory(); |
| 107 |
} |
| 108 |
|
| 109 |
public static final Factory FACTORY = new Factory() { |
| 110 |
|
| 111 |
public TreeSummaryStatistic createStatistic() { |
| 112 |
return new InternalBranchLengths(); |
| 113 |
} |
| 114 |
|
| 115 |
public String getSummaryStatisticName() { |
| 116 |
return "Internal Branch Lengths"; |
| 117 |
} |
| 118 |
|
| 119 |
public String getSummaryStatisticDescription() { |
| 120 |
|
| 121 |
return "The branch lengths of the internal edges in the tree."; |
| 122 |
} |
| 123 |
|
| 124 |
public String getSummaryStatisticReference() { |
| 125 |
|
| 126 |
return "-"; |
| 127 |
} |
| 128 |
|
| 129 |
public boolean allowsPolytomies() { |
| 130 |
return true; |
| 131 |
} |
| 132 |
|
| 133 |
public boolean allowsNonultrametricTrees() { |
| 134 |
return true; |
| 135 |
} |
| 136 |
|
| 137 |
public boolean allowsUnrootedTrees() { |
| 138 |
return false; |
| 139 |
} |
| 140 |
|
| 141 |
public Category getCategory() { |
| 142 |
return Category.GENERAL; |
| 143 |
} |
| 144 |
}; |
| 145 |
} |