Debian Codegraph @

src/dr/app/treestat/statistics/InternalBranchLengths.java

raw symbols SCIP
1 /*
2 * InternalBranchLengths.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
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 * @author Alexei Drummond
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 //Arrays.sort(stats);
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 }