Debian Codegraph @

src/dr/evomodel/arg/ARGReassortmentTimingStatistic.java

raw symbols SCIP
1 /*
2 * ARGReassortmentTimingStatistic.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.evomodel.arg;
27
28 import java.util.ArrayList;
29 import java.util.Collections;
30 import java.util.logging.Logger;
31
32 import dr.evomodel.arg.ARGModel.Node;
33 import dr.evomodel.arg.operators.ARGPartitioningOperator.PartitionChangedEvent;
34
35 import dr.inference.model.Parameter;
36 import dr.inference.model.Statistic;
37 import dr.math.MathUtils;
38 import dr.xml.AbstractXMLObjectParser;
39 import dr.xml.AttributeRule;
40 import dr.xml.ElementRule;
41 import dr.xml.XMLObject;
42 import dr.xml.XMLObjectParser;
43 import dr.xml.XMLParseException;
44 import dr.xml.XMLSyntaxRule;
45
46 public class ARGReassortmentTimingStatistic extends Statistic.Abstract{
47
48 private int dimension;
49 private ARGModel arg;
50
51 public static final String ARG_TIMING_STATISTIC = "argTimingStatistic";
52 public static final String NUMBER_OF_REASSORTMENTS = "reassortments"; //TODO This is probably somewhere else in BEAST.
53
54 public ARGReassortmentTimingStatistic(String name, ARGModel arg){
55 super(name);
56
57
58 this.dimension = arg.getExternalNodeCount() + 1;
59 this.arg = arg;
60 }
61
62 public int getDimension() {
63 return dimension;
64 }
65
66 public String getDimensionName(int dim){
67 if(dim == 0){
68 return "Root";
69 }else if(dim == 1){
70 return "RootChild";
71 }else if(dim == 2){
72 return "ENParent";
73 }else if(dim == 3){
74 return "DNParent";
75 }else if(dim == 4){
76 return "DCParent";
77 }else if(dim == 5){
78 return "CCParent";
79 }else if(dim == 6){
80 return "FNParent";
81 }else if(dim == 7){
82 return "ReassortHeight";
83 }else if(dim == 8){
84 return "CNParent";
85 }else if(dim == 9){
86 return "CCParentParent";
87 }
88
89 return "";
90 }
91
92 public double getStatisticValue(int dim) {
93 String max = "((((((<(FC,FN)>,CN),CC),<(FC,FN)>),DC),((EC,EN),DN)),AN);";
94
95
96 if(!arg.toExtendedNewick().equals(max)){
97 return Double.NaN;
98 }
99
100 if(dim == 0){
101 return arg.getRootHeightParameter().getParameterValue(0);
102 }else if(dim == 1){
103 Node a = (Node)arg.getRoot();
104
105 Node aLeft = a.leftChild;
106 Node aRight = a.rightChild;
107
108 return Math.max(aLeft.heightParameter.getParameterValue(0), aRight.heightParameter.getParameterValue(0));
109 }else if(dim == 2){
110 int value = 0;
111 Node a = (Node)arg.getExternalNode(0);
112
113 while(!a.taxon.toString().equals("EN")){
114 value++;
115 a = (Node)arg.getExternalNode(value);
116 }
117 return a.leftParent.heightParameter.getParameterValue(0);
118 }else if(dim == 3){
119 int value = 0;
120 Node a = (Node)arg.getExternalNode(0);
121
122 while(!a.taxon.toString().equals("DN")){
123 value++;
124 a = (Node)arg.getExternalNode(value);
125 }
126 return a.leftParent.heightParameter.getParameterValue(0);
127 }else if(dim == 4){
128 int value = 0;
129 Node a = (Node)arg.getExternalNode(0);
130
131 while(!a.taxon.toString().equals("DC")){
132 value++;
133 a = (Node)arg.getExternalNode(value);
134 }
135 return a.leftParent.heightParameter.getParameterValue(0);
136 }else if(dim == 5){
137 int value = 0;
138 Node a = (Node)arg.getExternalNode(0);
139
140 while(!a.taxon.toString().equals("CC")){
141 value++;
142 a = (Node)arg.getExternalNode(value);
143 }
144 return a.leftParent.heightParameter.getParameterValue(0);
145 }else if(dim == 6){
146 int value = 0;
147 Node a = (Node)arg.getExternalNode(0);
148
149 while(!a.taxon.toString().equals("FN")){
150 value++;
151 a = (Node)arg.getExternalNode(value);
152 }
153 return a.leftParent.heightParameter.getParameterValue(0);
154 }else if(dim == 7){
155 int value = 0;
156 Node a = (Node)arg.getExternalNode(0);
157
158 while(!a.taxon.toString().equals("FN")){
159 value++;
160 a = (Node)arg.getExternalNode(value);
161 }
162 return a.leftParent.leftParent.heightParameter.getParameterValue(0);
163 }else if(dim == 8){
164 int value = 0;
165 Node a = (Node)arg.getExternalNode(0);
166
167 while(!a.taxon.toString().equals("CN")){
168 value++;
169 a = (Node)arg.getExternalNode(value);
170 }
171 return a.leftParent.heightParameter.getParameterValue(0);
172 }
173
174 int value = 0;
175 Node a = (Node)arg.getExternalNode(0);
176
177 while(!a.taxon.toString().equals("CC")){
178 value++;
179 a = (Node)arg.getExternalNode(value);
180 }
181 return a.leftParent.leftParent.heightParameter.getParameterValue(0);
182
183
184
185
186 }
187
188
189
190
191
192 public static XMLObjectParser PARSER = new AbstractXMLObjectParser(){
193
194 public String getParserDescription() {
195
196 return "";
197 }
198
199 public Class getReturnType() {
200
201 return ARGReassortmentTimingStatistic.class;
202 }
203
204
205 public XMLSyntaxRule[] getSyntaxRules() {
206 return new XMLSyntaxRule[]{
207 new ElementRule(ARGModel.class,false),
208 AttributeRule.newStringRule(NAME,true),
209 };
210 }
211
212
213 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
214 String name = xo.getId();
215 // int dim = xo.getIntegerAttribute(DIMENSION);
216 ARGModel arg = (ARGModel)xo.getChild(ARGModel.class);
217
218 Logger.getLogger("dr.evomodel").info("Creating timing statistic");
219
220 return new ARGReassortmentTimingStatistic(name,arg);
221 }
222
223 public String getParserName() {
224 return ARG_TIMING_STATISTIC;
225 }
226
227 };
228
229
230
231 }
232