| 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.evomodelxml.coalescent; |
| 27 |
|
| 28 |
import dr.evolution.tree.Tree; |
| 29 |
|
| 30 |
import dr.evomodel.coalescent.GaussianProcessMultilocusSkytrackLikelihood; |
| 31 |
import dr.evomodel.coalescent.GaussianProcessSkytrackLikelihood; |
| 32 |
import dr.evomodel.tree.TreeModel; |
| 33 |
|
| 34 |
import dr.inference.model.Parameter; |
| 35 |
import dr.xml.*; |
| 36 |
|
| 37 |
import java.util.ArrayList; |
| 38 |
import java.util.List; |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
public class GaussianProcessSkytrackLikelihoodParser extends AbstractXMLObjectParser { |
| 45 |
|
| 46 |
|
| 47 |
public static final String SKYTRACK_LIKELIHOOD = "gpSkytrackLikelihood"; |
| 48 |
|
| 49 |
public static final String LAMBDA_BOUND_PARAMETER = "lambdaBoundParameter"; |
| 50 |
public static final String POPULATION_PARAMETER = "populationSizes"; |
| 51 |
public static final String NUMBER_POINTS="pointsParameter"; |
| 52 |
public static final String GPTYPE="GPtype"; |
| 53 |
public static final String GPCOUNTS="GPcounts"; |
| 54 |
public static final String COALFACTOR="coalfactor"; |
| 55 |
public static final String CHANGE_POINTS="changePoints"; |
| 56 |
public static final String COALCOUNT="CoalCounts"; |
| 57 |
public static final String TMRCA="timeMRCA"; |
| 58 |
|
| 59 |
public static final String PRECISION_PARAMETER = "precisionParameter"; |
| 60 |
public static final String POPULATION_TREE = "populationTree"; |
| 61 |
public static final String LAMBDA_PARAMETER = "lambdaParameter"; |
| 62 |
public static final String BETA_PARAMETER = "betaParameter"; |
| 63 |
public static final String ALPHA_PARAMETER = "alphaParameter"; |
| 64 |
|
| 65 |
public static final String RANDOMIZE_TREE = "randomizeTree"; |
| 66 |
|
| 67 |
|
| 68 |
public static final String RESCALE_BY_ROOT_ISSUE = "rescaleByRootHeight"; |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
public String getParserName() { |
| 79 |
return SKYTRACK_LIKELIHOOD; |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 85 |
|
| 86 |
|
| 87 |
XMLObject cxo = xo.getChild(POPULATION_PARAMETER); |
| 88 |
Parameter popParameter = (Parameter) cxo.getChild(Parameter.class); |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
cxo = xo.getChild(PRECISION_PARAMETER); |
| 94 |
Parameter precParameter = (Parameter) cxo.getChild(Parameter.class); |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
cxo = xo.getChild(POPULATION_TREE); |
| 104 |
|
| 105 |
List<Tree> treeList = new ArrayList<Tree>(); |
| 106 |
for (int i = 0; i < cxo.getChildCount(); i++) { |
| 107 |
Object testObject = cxo.getChild(i); |
| 108 |
if (testObject instanceof Tree) { |
| 109 |
treeList.add((TreeModel) testObject); |
| 110 |
} |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
Parameter lambda_parameter; |
| 125 |
if (xo.getChild(LAMBDA_PARAMETER) != null) { |
| 126 |
cxo = xo.getChild(LAMBDA_PARAMETER); |
| 127 |
lambda_parameter = (Parameter) cxo.getChild(Parameter.class); |
| 128 |
} else { |
| 129 |
lambda_parameter = new Parameter.Default(1.0); |
| 130 |
|
| 131 |
} |
| 132 |
|
| 133 |
Parameter GPtype; |
| 134 |
if (xo.getChild(GPTYPE) != null) { |
| 135 |
cxo = xo.getChild(GPTYPE); |
| 136 |
GPtype = (Parameter) cxo.getChild(Parameter.class); |
| 137 |
} else { |
| 138 |
GPtype = new Parameter.Default(1.0); |
| 139 |
|
| 140 |
} |
| 141 |
|
| 142 |
Parameter Tmrca; |
| 143 |
if (xo.getChild(TMRCA) != null) { |
| 144 |
cxo = xo.getChild(TMRCA); |
| 145 |
Tmrca = (Parameter) cxo.getChild(Parameter.class); |
| 146 |
} else { |
| 147 |
Tmrca = new Parameter.Default(1.0); |
| 148 |
|
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
Parameter numPoints; |
| 153 |
if (xo.getChild(NUMBER_POINTS) != null) { |
| 154 |
cxo = xo.getChild(NUMBER_POINTS); |
| 155 |
numPoints = (Parameter) cxo.getChild(Parameter.class); |
| 156 |
} else { |
| 157 |
numPoints = new Parameter.Default(1.0); |
| 158 |
|
| 159 |
} |
| 160 |
|
| 161 |
Parameter CoalCounts; |
| 162 |
if (xo.getChild(COALCOUNT) != null) { |
| 163 |
cxo = xo.getChild(COALCOUNT); |
| 164 |
CoalCounts = (Parameter) cxo.getChild(Parameter.class); |
| 165 |
} else { |
| 166 |
CoalCounts = new Parameter.Default(1.0); |
| 167 |
|
| 168 |
} |
| 169 |
|
| 170 |
Parameter GPcounts; |
| 171 |
if (xo.getChild(GPCOUNTS) != null) { |
| 172 |
cxo = xo.getChild(GPCOUNTS); |
| 173 |
GPcounts = (Parameter) cxo.getChild(Parameter.class); |
| 174 |
} else { |
| 175 |
GPcounts = new Parameter.Default(1.0); |
| 176 |
|
| 177 |
} |
| 178 |
|
| 179 |
|
| 180 |
Parameter coalfactor; |
| 181 |
if (xo.getChild(COALFACTOR) != null) { |
| 182 |
cxo = xo.getChild(COALFACTOR); |
| 183 |
coalfactor = (Parameter) cxo.getChild(Parameter.class); |
| 184 |
} else { |
| 185 |
coalfactor = new Parameter.Default(1.0); |
| 186 |
|
| 187 |
} |
| 188 |
|
| 189 |
Parameter lambda_bound; |
| 190 |
if (xo.getChild(LAMBDA_BOUND_PARAMETER) != null) { |
| 191 |
cxo = xo.getChild(LAMBDA_BOUND_PARAMETER); |
| 192 |
lambda_bound = (Parameter) cxo.getChild(Parameter.class); |
| 193 |
} else { |
| 194 |
lambda_bound = new Parameter.Default(1.0); |
| 195 |
} |
| 196 |
|
| 197 |
Parameter alpha_parameter; |
| 198 |
if (xo.getChild(ALPHA_PARAMETER) != null) { |
| 199 |
cxo = xo.getChild(ALPHA_PARAMETER); |
| 200 |
alpha_parameter = (Parameter) cxo.getChild(Parameter.class); |
| 201 |
} else { |
| 202 |
alpha_parameter = new Parameter.Default(0.001); |
| 203 |
} |
| 204 |
|
| 205 |
Parameter beta_parameter; |
| 206 |
if (xo.getChild(BETA_PARAMETER) != null) { |
| 207 |
cxo = xo.getChild(BETA_PARAMETER); |
| 208 |
beta_parameter = (Parameter) cxo.getChild(Parameter.class); |
| 209 |
} else { |
| 210 |
beta_parameter = new Parameter.Default(0.001); |
| 211 |
} |
| 212 |
|
| 213 |
Parameter change_points; |
| 214 |
if (xo.getChild(CHANGE_POINTS) != null) { |
| 215 |
cxo = xo.getChild(CHANGE_POINTS); |
| 216 |
change_points = (Parameter) cxo.getChild(Parameter.class); |
| 217 |
} else { |
| 218 |
change_points = new Parameter.Default(0,1); |
| 219 |
} |
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
if (xo.getAttribute(RANDOMIZE_TREE, false)) { |
| 279 |
for (Tree tree : treeList) { |
| 280 |
if (tree instanceof TreeModel) { |
| 281 |
GaussianProcessSkytrackLikelihood.checkTree((TreeModel) tree); |
| 282 |
} else { |
| 283 |
throw new XMLParseException("Can not randomize a fixed tree"); |
| 284 |
} |
| 285 |
} |
| 286 |
} |
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
boolean rescaleByRootHeight = xo.getAttribute(RESCALE_BY_ROOT_ISSUE, true); |
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
if (treeList.size()==1) { |
| 299 |
return new GaussianProcessSkytrackLikelihood(treeList, precParameter, |
| 300 |
rescaleByRootHeight, lambda_bound, lambda_parameter, popParameter,alpha_parameter,beta_parameter, change_points, |
| 301 |
GPtype, GPcounts, coalfactor, CoalCounts, numPoints,Tmrca); |
| 302 |
} else { |
| 303 |
return new GaussianProcessMultilocusSkytrackLikelihood(treeList, precParameter, rescaleByRootHeight, lambda_bound, |
| 304 |
lambda_parameter, popParameter, alpha_parameter, beta_parameter, change_points, GPtype,GPcounts,coalfactor, CoalCounts, numPoints,Tmrca); |
| 305 |
} |
| 306 |
} |
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
public String getParserDescription() { |
| 313 |
return "This element represents the likelihood of the tree given the population size vector."; |
| 314 |
} |
| 315 |
|
| 316 |
public Class getReturnType() { |
| 317 |
return GaussianProcessSkytrackLikelihood.class; |
| 318 |
} |
| 319 |
|
| 320 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 321 |
return rules; |
| 322 |
} |
| 323 |
|
| 324 |
private final XMLSyntaxRule[] rules = { |
| 325 |
new ElementRule(POPULATION_PARAMETER, new XMLSyntaxRule[]{ |
| 326 |
new ElementRule(Parameter.class) |
| 327 |
}), |
| 328 |
new ElementRule(CHANGE_POINTS, new XMLSyntaxRule[]{ |
| 329 |
new ElementRule(Parameter.class) |
| 330 |
}), |
| 331 |
new ElementRule(PRECISION_PARAMETER, new XMLSyntaxRule[]{ |
| 332 |
new ElementRule(Parameter.class) |
| 333 |
}), |
| 334 |
|
| 335 |
new ElementRule(LAMBDA_BOUND_PARAMETER, new XMLSyntaxRule[]{ |
| 336 |
new ElementRule(Parameter.class) |
| 337 |
}), |
| 338 |
new ElementRule(LAMBDA_PARAMETER, new XMLSyntaxRule[]{ |
| 339 |
new ElementRule(Parameter.class) |
| 340 |
}), |
| 341 |
new ElementRule(ALPHA_PARAMETER, new XMLSyntaxRule[]{ |
| 342 |
new ElementRule(Parameter.class) |
| 343 |
}), |
| 344 |
new ElementRule(BETA_PARAMETER, new XMLSyntaxRule[]{ |
| 345 |
new ElementRule(Parameter.class) |
| 346 |
}), |
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
new ElementRule(POPULATION_TREE, new XMLSyntaxRule[]{ |
| 351 |
new ElementRule(TreeModel.class, 1, Integer.MAX_VALUE) |
| 352 |
}), |
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
AttributeRule.newBooleanRule(RESCALE_BY_ROOT_ISSUE, true), |
| 359 |
AttributeRule.newBooleanRule(RANDOMIZE_TREE, true), |
| 360 |
|
| 361 |
|
| 362 |
}; |
| 363 |
|
| 364 |
} |