Debian Codegraph @

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

raw symbols SCIP
1 /*
2 * InternalNodeAttribute.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 InternalNodeAttribute implements TreeSummaryStatistic {
36
37 String attributeName;
38
39 private InternalNodeAttribute() {
40 this.attributeName = "";
41 }
42
43 public void setString(String value) {
44 this.attributeName = value;
45 }
46
47 public int getStatisticDimensions(Tree tree) {
48 return tree.getInternalNodeCount() - 1;
49 }
50
51 public String getStatisticLabel(Tree tree, int i) {
52 return attributeName + " " + Integer.toString(i + 1);
53 }
54
55 public double[] getSummaryStatistic(Tree tree) {
56
57 int internalNodeCount = tree.getInternalNodeCount();
58 double[] stats = new double[internalNodeCount - 1];
59 int count = 0;
60 for (int i = 0; i < internalNodeCount; i++) {
61 NodeRef node = tree.getInternalNode(i);
62 if (!tree.isRoot(node)) {
63 stats[count++] = (Double) tree.getNodeAttribute(node, attributeName);
64 }
65 }
66 //Arrays.sort(stats);
67
68 return stats;
69 }
70
71 public void setTaxonList(TaxonList taxonList) {
72 throw new UnsupportedOperationException("not implemented in this statistic");
73 }
74
75 public void setInteger(int value) {
76 throw new UnsupportedOperationException("not implemented in this statistic");
77 }
78
79 public void setDouble(double value) {
80 throw new UnsupportedOperationException("not implemented in this statistic");
81 }
82
83 public String getSummaryStatisticName() {
84 return FACTORY.getSummaryStatisticName();
85 }
86
87 public String getSummaryStatisticDescription() {
88 return FACTORY.getSummaryStatisticDescription();
89 }
90
91 public String getSummaryStatisticReference() {
92 return FACTORY.getSummaryStatisticReference();
93 }
94
95 public boolean allowsPolytomies() {
96 return FACTORY.allowsPolytomies();
97 }
98
99 public boolean allowsNonultrametricTrees() {
100 return FACTORY.allowsNonultrametricTrees();
101 }
102
103 public boolean allowsUnrootedTrees() {
104 return FACTORY.allowsUnrootedTrees();
105 }
106
107 public Category getCategory() {
108 return FACTORY.getCategory();
109 }
110
111 public static final Factory FACTORY = new Factory() {
112
113 public TreeSummaryStatistic createStatistic() {
114 return new InternalNodeAttribute();
115 }
116
117 public String getSummaryStatisticName() {
118 return "Internal Node Attribute";
119 }
120
121 public String getSummaryStatisticDescription() {
122
123 return "A named attribute of the internal nodes of the tree.";
124 }
125
126 public String getSummaryStatisticReference() {
127
128 return "-";
129 }
130
131 public String getValueName() {
132 return "The attribute name:";
133 }
134
135 public boolean allowsPolytomies() {
136 return true;
137 }
138
139 public boolean allowsNonultrametricTrees() {
140 return true;
141 }
142
143 public boolean allowsUnrootedTrees() {
144 return false;
145 }
146
147 public Category getCategory() {
148 return Category.GENERAL;
149 }
150
151 public boolean allowsWholeTree() {
152 return true;
153 }
154
155 public boolean allowsTaxonList() {
156 return true;
157 }
158
159 public boolean allowsString() {
160 return true;
161 }
162 };
163 }