| 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.beauti.generator; |
| 27 |
|
| 28 |
import dr.app.beauti.components.ComponentFactory; |
| 29 |
import dr.app.beauti.options.*; |
| 30 |
import dr.app.beauti.types.StartingTreeType; |
| 31 |
import dr.app.beauti.types.TreePriorParameterizationType; |
| 32 |
import dr.app.beauti.types.TreePriorType; |
| 33 |
import dr.app.beauti.util.XMLWriter; |
| 34 |
import dr.evolution.util.Taxa; |
| 35 |
import dr.evolution.util.Units; |
| 36 |
import dr.evomodel.tree.TreeModel; |
| 37 |
import dr.evomodelxml.CSVExporterParser; |
| 38 |
import dr.evomodelxml.coalescent.*; |
| 39 |
import dr.evomodelxml.speciation.*; |
| 40 |
import dr.evoxml.TaxaParser; |
| 41 |
import dr.inference.distribution.ExponentialDistributionModel; |
| 42 |
import dr.inference.distribution.ExponentialMarkovModel; |
| 43 |
import dr.inference.model.ParameterParser; |
| 44 |
import dr.inferencexml.distribution.DistributionModelParser; |
| 45 |
import dr.inferencexml.distribution.ExponentialMarkovModelParser; |
| 46 |
import dr.inferencexml.distribution.MixedDistributionLikelihoodParser; |
| 47 |
import dr.inferencexml.model.SumStatisticParser; |
| 48 |
import dr.util.Attribute; |
| 49 |
import dr.xml.XMLParser; |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
public class TreePriorGenerator extends Generator { |
| 56 |
|
| 57 |
public TreePriorGenerator(BeautiOptions options, ComponentFactory[] components) { |
| 58 |
super(options, components); |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
void writeTreePriorModel(PartitionTreePrior prior, XMLWriter writer) { |
| 74 |
|
| 75 |
String prefix = prior.getPrefix(); |
| 76 |
|
| 77 |
String initialPopSize = null; |
| 78 |
|
| 79 |
TreePriorType nodeHeightPrior = prior.getNodeHeightPrior(); |
| 80 |
Units.Type units = options.units; |
| 81 |
TreePriorParameterizationType parameterization = prior.getParameterization(); |
| 82 |
|
| 83 |
switch (nodeHeightPrior) { |
| 84 |
case CONSTANT: |
| 85 |
writer.writeComment("A prior assumption that the population size has remained constant", |
| 86 |
"throughout the time spanned by the genealogy."); |
| 87 |
writer.writeOpenTag( |
| 88 |
ConstantPopulationModelParser.CONSTANT_POPULATION_MODEL, |
| 89 |
new Attribute[]{ |
| 90 |
new Attribute.Default<String>(XMLParser.ID, prefix + "constant"), |
| 91 |
new Attribute.Default<String>("units", Units.Utils.getDefaultUnitName(options.units)) |
| 92 |
} |
| 93 |
); |
| 94 |
|
| 95 |
writer.writeOpenTag(ConstantPopulationModelParser.POPULATION_SIZE); |
| 96 |
writeParameter("constant.popSize", prior, writer); |
| 97 |
writer.writeCloseTag(ConstantPopulationModelParser.POPULATION_SIZE); |
| 98 |
writer.writeCloseTag(ConstantPopulationModelParser.CONSTANT_POPULATION_MODEL); |
| 99 |
|
| 100 |
break; |
| 101 |
|
| 102 |
case EXPONENTIAL: |
| 103 |
|
| 104 |
|
| 105 |
writer.writeComment("A prior assumption that the population size has grown exponentially", |
| 106 |
"throughout the time spanned by the genealogy."); |
| 107 |
writer.writeOpenTag( |
| 108 |
ExponentialGrowthModelParser.EXPONENTIAL_GROWTH_MODEL, |
| 109 |
new Attribute[]{ |
| 110 |
new Attribute.Default<String>(XMLParser.ID, prefix + "exponential"), |
| 111 |
new Attribute.Default<String>("units", Units.Utils.getDefaultUnitName(options.units)) |
| 112 |
} |
| 113 |
); |
| 114 |
|
| 115 |
|
| 116 |
writer.writeOpenTag(ExponentialGrowthModelParser.POPULATION_SIZE); |
| 117 |
writeParameter("exponential.popSize", prior, writer); |
| 118 |
writer.writeCloseTag(ExponentialGrowthModelParser.POPULATION_SIZE); |
| 119 |
|
| 120 |
if (parameterization == TreePriorParameterizationType.GROWTH_RATE) { |
| 121 |
|
| 122 |
writer.writeOpenTag(ExponentialGrowthModelParser.GROWTH_RATE); |
| 123 |
writeParameter("exponential.growthRate", prior, writer); |
| 124 |
writer.writeCloseTag(ExponentialGrowthModelParser.GROWTH_RATE); |
| 125 |
} else { |
| 126 |
|
| 127 |
writer.writeOpenTag(ExponentialGrowthModelParser.DOUBLING_TIME); |
| 128 |
writeParameter("exponential.doublingTime", prior, writer); |
| 129 |
writer.writeCloseTag(ExponentialGrowthModelParser.DOUBLING_TIME); |
| 130 |
} |
| 131 |
|
| 132 |
writer.writeCloseTag(ExponentialGrowthModelParser.EXPONENTIAL_GROWTH_MODEL); |
| 133 |
|
| 134 |
break; |
| 135 |
|
| 136 |
case LOGISTIC: |
| 137 |
|
| 138 |
writer.writeComment("A prior assumption that the population size has grown logistically", |
| 139 |
"throughout the time spanned by the genealogy."); |
| 140 |
writer.writeOpenTag( |
| 141 |
LogisticGrowthModelParser.LOGISTIC_GROWTH_MODEL, |
| 142 |
new Attribute[]{ |
| 143 |
new Attribute.Default<String>(XMLParser.ID, prefix + "logistic"), |
| 144 |
new Attribute.Default<String>("units", Units.Utils.getDefaultUnitName(options.units)) |
| 145 |
} |
| 146 |
); |
| 147 |
|
| 148 |
|
| 149 |
writer.writeOpenTag(LogisticGrowthModelParser.POPULATION_SIZE); |
| 150 |
writeParameter("logistic.popSize", prior, writer); |
| 151 |
writer.writeCloseTag(LogisticGrowthModelParser.POPULATION_SIZE); |
| 152 |
|
| 153 |
if (parameterization == TreePriorParameterizationType.GROWTH_RATE) { |
| 154 |
|
| 155 |
writer.writeOpenTag(LogisticGrowthModelParser.GROWTH_RATE); |
| 156 |
writeParameter("logistic.growthRate", prior, writer); |
| 157 |
writer.writeCloseTag(LogisticGrowthModelParser.GROWTH_RATE); |
| 158 |
} else { |
| 159 |
|
| 160 |
writer.writeOpenTag(LogisticGrowthModelParser.DOUBLING_TIME); |
| 161 |
writeParameter("logistic.doublingTime", prior, writer); |
| 162 |
writer.writeCloseTag(LogisticGrowthModelParser.DOUBLING_TIME); |
| 163 |
} |
| 164 |
|
| 165 |
|
| 166 |
writer.writeOpenTag(LogisticGrowthModelParser.TIME_50); |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
writeParameter("logistic.t50", prior, writer); |
| 197 |
writer.writeCloseTag(LogisticGrowthModelParser.TIME_50); |
| 198 |
|
| 199 |
writer.writeCloseTag(LogisticGrowthModelParser.LOGISTIC_GROWTH_MODEL); |
| 200 |
|
| 201 |
initialPopSize = "logistic.popSize"; |
| 202 |
|
| 203 |
break; |
| 204 |
|
| 205 |
case EXPANSION: |
| 206 |
|
| 207 |
writer.writeComment("A prior assumption that the population size has grown exponentially", |
| 208 |
"from some ancestral population size in the past."); |
| 209 |
writer.writeOpenTag( |
| 210 |
ExpansionModelParser.EXPANSION_MODEL, |
| 211 |
new Attribute[]{ |
| 212 |
new Attribute.Default<String>(XMLParser.ID, prefix + "expansion"), |
| 213 |
new Attribute.Default<String>("units", Units.Utils.getDefaultUnitName(options.units)) |
| 214 |
} |
| 215 |
); |
| 216 |
|
| 217 |
|
| 218 |
writeParameter(ExpansionModelParser.POPULATION_SIZE, "expansion.popSize", prior, writer); |
| 219 |
|
| 220 |
if (parameterization == TreePriorParameterizationType.GROWTH_RATE) { |
| 221 |
|
| 222 |
writeParameter(ExpansionModelParser.GROWTH_RATE, "expansion.growthRate", prior, writer); |
| 223 |
} else { |
| 224 |
|
| 225 |
writeParameter(ExpansionModelParser.DOUBLING_TIME, "expansion.doublingTime", prior, writer); |
| 226 |
} |
| 227 |
|
| 228 |
|
| 229 |
writeParameter(ExpansionModelParser.ANCESTRAL_POPULATION_PROPORTION, "expansion.ancestralProportion", prior, writer); |
| 230 |
|
| 231 |
writer.writeCloseTag(ExpansionModelParser.EXPANSION_MODEL); |
| 232 |
|
| 233 |
initialPopSize = "expansion.popSize"; |
| 234 |
|
| 235 |
break; |
| 236 |
|
| 237 |
case YULE: |
| 238 |
case YULE_CALIBRATION: |
| 239 |
if (nodeHeightPrior == TreePriorType.YULE_CALIBRATION) { |
| 240 |
writer.writeComment("Calibrated Yule: Heled J, Drummond AJ (2011), Syst Biol, doi: " + |
| 241 |
"10.1093/sysbio/syr087"); |
| 242 |
} else { |
| 243 |
writer.writeComment("A prior on the distribution node heights defined given", |
| 244 |
"a Yule speciation process (a pure birth process)."); |
| 245 |
} |
| 246 |
writer.writeOpenTag( |
| 247 |
YuleModelParser.YULE_MODEL, |
| 248 |
new Attribute[]{ |
| 249 |
new Attribute.Default<String>(XMLParser.ID, prefix + YuleModelParser.YULE), |
| 250 |
new Attribute.Default<String>("units", Units.Utils.getDefaultUnitName(units)) |
| 251 |
} |
| 252 |
); |
| 253 |
|
| 254 |
writeParameter(YuleModelParser.BIRTH_RATE, "yule.birthRate", prior, writer); |
| 255 |
writer.writeCloseTag(YuleModelParser.YULE_MODEL); |
| 256 |
|
| 257 |
break; |
| 258 |
|
| 259 |
case BIRTH_DEATH: |
| 260 |
case BIRTH_DEATH_INCOMPLETE_SAMPLING: |
| 261 |
writer.writeComment("A prior on the distribution node heights defined given"); |
| 262 |
writer.writeComment(nodeHeightPrior == TreePriorType.BIRTH_DEATH_INCOMPLETE_SAMPLING ? |
| 263 |
BirthDeathModelParser.getCitationRHO() : BirthDeathModelParser.getCitation()); |
| 264 |
writer.writeOpenTag( |
| 265 |
BirthDeathModelParser.BIRTH_DEATH_MODEL, |
| 266 |
new Attribute[]{ |
| 267 |
new Attribute.Default<String>(XMLParser.ID, prefix + BirthDeathModelParser.BIRTH_DEATH), |
| 268 |
new Attribute.Default<String>("units", Units.Utils.getDefaultUnitName(units)) |
| 269 |
} |
| 270 |
); |
| 271 |
|
| 272 |
writeParameter(BirthDeathModelParser.BIRTHDIFF_RATE, BirthDeathModelParser.MEAN_GROWTH_RATE_PARAM_NAME, prior, writer); |
| 273 |
writeParameter(BirthDeathModelParser.RELATIVE_DEATH_RATE, BirthDeathModelParser.RELATIVE_DEATH_RATE_PARAM_NAME, prior, writer); |
| 274 |
|
| 275 |
if (nodeHeightPrior == TreePriorType.BIRTH_DEATH_INCOMPLETE_SAMPLING) { |
| 276 |
writeParameter(BirthDeathModelParser.SAMPLE_PROB, |
| 277 |
BirthDeathModelParser.BIRTH_DEATH + "." + BirthDeathModelParser.SAMPLE_PROB, prior, writer); |
| 278 |
} |
| 279 |
|
| 280 |
writer.writeCloseTag(BirthDeathModelParser.BIRTH_DEATH_MODEL); |
| 281 |
|
| 282 |
break; |
| 283 |
|
| 284 |
case BIRTH_DEATH_SERIAL_SAMPLING: |
| 285 |
writer.writeComment(BirthDeathSerialSamplingModelParser.getCitationPsiOrg()); |
| 286 |
|
| 287 |
writer.writeOpenTag( |
| 288 |
BirthDeathSerialSamplingModelParser.BIRTH_DEATH_SERIAL_MODEL, |
| 289 |
new Attribute[]{ |
| 290 |
new Attribute.Default<String>(XMLParser.ID, prefix + BirthDeathSerialSamplingModelParser.BDSS), |
| 291 |
new Attribute.Default<String>("units", Units.Utils.getDefaultUnitName(units)), |
| 292 |
new Attribute.Default<Boolean>(BirthDeathSerialSamplingModelParser.HAS_FINAL_SAMPLE, false) |
| 293 |
} |
| 294 |
); |
| 295 |
|
| 296 |
writeParameter(BirthDeathSerialSamplingModelParser.LAMBDA, |
| 297 |
BirthDeathSerialSamplingModelParser.BDSS + "." + BirthDeathSerialSamplingModelParser.LAMBDA, prior, writer); |
| 298 |
writeParameter(BirthDeathSerialSamplingModelParser.RELATIVE_MU, |
| 299 |
BirthDeathSerialSamplingModelParser.BDSS + "." + BirthDeathSerialSamplingModelParser.RELATIVE_MU, prior, writer); |
| 300 |
|
| 301 |
|
| 302 |
writeParameter(BirthDeathSerialSamplingModelParser.PSI, |
| 303 |
BirthDeathSerialSamplingModelParser.BDSS + "." + BirthDeathSerialSamplingModelParser.PSI, prior, writer); |
| 304 |
writeParameter(BirthDeathSerialSamplingModelParser.ORIGIN, |
| 305 |
BirthDeathSerialSamplingModelParser.BDSS + "." + BirthDeathSerialSamplingModelParser.ORIGIN, prior, writer); |
| 306 |
|
| 307 |
writer.writeCloseTag(BirthDeathSerialSamplingModelParser.BIRTH_DEATH_SERIAL_MODEL); |
| 308 |
|
| 309 |
break; |
| 310 |
|
| 311 |
case BIRTH_DEATH_BASIC_REPRODUCTIVE_NUMBER: |
| 312 |
writer.writeComment(BirthDeathSerialSamplingModelParser.getCitationRT()); |
| 313 |
|
| 314 |
writer.writeOpenTag( |
| 315 |
BirthDeathEpidemiologyModelParser.BIRTH_DEATH_EPIDEMIOLOGY, |
| 316 |
new Attribute[]{ |
| 317 |
new Attribute.Default<String>(XMLParser.ID, prefix + BirthDeathEpidemiologyModelParser.BIRTH_DEATH_EPIDEMIOLOGY), |
| 318 |
new Attribute.Default<String>("units", Units.Utils.getDefaultUnitName(units)) |
| 319 |
} |
| 320 |
); |
| 321 |
|
| 322 |
writeParameter(BirthDeathEpidemiologyModelParser.R0, |
| 323 |
BirthDeathEpidemiologyModelParser.R0, prior, writer); |
| 324 |
writeParameter(BirthDeathEpidemiologyModelParser.RECOVERY_RATE, |
| 325 |
BirthDeathEpidemiologyModelParser.RECOVERY_RATE, prior, writer); |
| 326 |
writeParameter(BirthDeathEpidemiologyModelParser.SAMPLING_PROBABILITY, |
| 327 |
BirthDeathEpidemiologyModelParser.SAMPLING_PROBABILITY, prior, writer); |
| 328 |
writeParameter(BirthDeathEpidemiologyModelParser.ORIGIN, |
| 329 |
BirthDeathEpidemiologyModelParser.ORIGIN, prior, writer); |
| 330 |
|
| 331 |
writer.writeCloseTag(BirthDeathEpidemiologyModelParser.BIRTH_DEATH_EPIDEMIOLOGY); |
| 332 |
|
| 333 |
break; |
| 334 |
} |
| 335 |
|
| 336 |
if (nodeHeightPrior != TreePriorType.CONSTANT && nodeHeightPrior != TreePriorType.EXPONENTIAL) { |
| 337 |
|
| 338 |
|
| 339 |
writer.writeComment("This is a simple constant population size coalescent model", |
| 340 |
"that is used to generate an initial tree for the chain."); |
| 341 |
writer.writeOpenTag( |
| 342 |
ConstantPopulationModelParser.CONSTANT_POPULATION_MODEL, |
| 343 |
new Attribute[]{ |
| 344 |
new Attribute.Default<String>(XMLParser.ID, prefix + "initialDemo"), |
| 345 |
new Attribute.Default<String>("units", Units.Utils.getDefaultUnitName(units)) |
| 346 |
} |
| 347 |
); |
| 348 |
|
| 349 |
writer.writeOpenTag(ConstantPopulationModelParser.POPULATION_SIZE); |
| 350 |
if (initialPopSize != null) { |
| 351 |
writer.writeIDref(ParameterParser.PARAMETER, prefix + initialPopSize); |
| 352 |
} else { |
| 353 |
writeParameter(prefix + "initialDemo.popSize", 1, 100.0, Double.NaN, Double.NaN, writer); |
| 354 |
} |
| 355 |
writer.writeCloseTag(ConstantPopulationModelParser.POPULATION_SIZE); |
| 356 |
writer.writeCloseTag(ConstantPopulationModelParser.CONSTANT_POPULATION_MODEL); |
| 357 |
} |
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
} |
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
void writePriorLikelihood(PartitionTreeModel model, XMLWriter writer) { |
| 412 |
|
| 413 |
|
| 414 |
String prefix = model.getPrefix(); |
| 415 |
|
| 416 |
PartitionTreePrior prior = model.getPartitionTreePrior(); |
| 417 |
TreePriorType treePrior = prior.getNodeHeightPrior(); |
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
switch (treePrior) { |
| 422 |
case YULE: |
| 423 |
case BIRTH_DEATH: |
| 424 |
case BIRTH_DEATH_INCOMPLETE_SAMPLING: |
| 425 |
case BIRTH_DEATH_SERIAL_SAMPLING: |
| 426 |
case BIRTH_DEATH_BASIC_REPRODUCTIVE_NUMBER: |
| 427 |
case YULE_CALIBRATION: |
| 428 |
|
| 429 |
writer.writeComment("Generate a speciation likelihood for Yule or Birth Death"); |
| 430 |
writer.writeOpenTag( |
| 431 |
SpeciationLikelihoodParser.SPECIATION_LIKELIHOOD, |
| 432 |
new Attribute[]{ |
| 433 |
new Attribute.Default<String>(XMLParser.ID, prefix + "speciation") |
| 434 |
} |
| 435 |
); |
| 436 |
|
| 437 |
|
| 438 |
writer.writeOpenTag(SpeciationLikelihoodParser.MODEL); |
| 439 |
writeNodeHeightPriorModelRef(prior, writer); |
| 440 |
writer.writeCloseTag(SpeciationLikelihoodParser.MODEL); |
| 441 |
writer.writeOpenTag(SpeciationLikelihoodParser.TREE); |
| 442 |
writer.writeIDref(TreeModel.TREE_MODEL, prefix + TreeModel.TREE_MODEL); |
| 443 |
writer.writeCloseTag(SpeciationLikelihoodParser.TREE); |
| 444 |
|
| 445 |
if (treePrior == TreePriorType.YULE_CALIBRATION) { |
| 446 |
|
| 447 |
if (options.treeModelOptions.isNodeCalibrated(model) == 0) { |
| 448 |
writer.writeOpenTag(SpeciationLikelihoodParser.CALIBRATION, |
| 449 |
new Attribute[]{ |
| 450 |
new Attribute.Default<String>(SpeciationLikelihoodParser.CORRECTION, prior.getCalibCorrectionType().toString()) |
| 451 |
}); |
| 452 |
writer.writeOpenTag(SpeciationLikelihoodParser.POINT); |
| 453 |
|
| 454 |
String taxaId; |
| 455 |
if (options.hasIdenticalTaxa()) { |
| 456 |
taxaId = TaxaParser.TAXA; |
| 457 |
} else { |
| 458 |
taxaId = options.getDataPartitions(model).get(0).getPrefix() + TaxaParser.TAXA; |
| 459 |
} |
| 460 |
writer.writeIDref(TaxaParser.TAXA, taxaId); |
| 461 |
|
| 462 |
writeDistribution(model.getParameter("treeModel.rootHeight"), true, writer); |
| 463 |
|
| 464 |
writer.writeCloseTag(SpeciationLikelihoodParser.POINT); |
| 465 |
writer.writeCloseTag(SpeciationLikelihoodParser.CALIBRATION); |
| 466 |
|
| 467 |
} else if (options.treeModelOptions.isNodeCalibrated(model) == 1) { |
| 468 |
|
| 469 |
Taxa t = (Taxa) options.getKeysFromValue(options.taxonSetsTreeModel, model).get(0); |
| 470 |
Parameter nodeCalib = options.getStatistic(t); |
| 471 |
|
| 472 |
writer.writeOpenTag(SpeciationLikelihoodParser.CALIBRATION, |
| 473 |
new Attribute[]{ |
| 474 |
new Attribute.Default<String>(SpeciationLikelihoodParser.CORRECTION, prior.getCalibCorrectionType().toString()) |
| 475 |
}); |
| 476 |
writer.writeOpenTag(SpeciationLikelihoodParser.POINT); |
| 477 |
|
| 478 |
writer.writeIDref(TaxaParser.TAXA, t.getId()); |
| 479 |
writeDistribution(nodeCalib, true, writer); |
| 480 |
|
| 481 |
writer.writeCloseTag(SpeciationLikelihoodParser.POINT); |
| 482 |
writer.writeCloseTag(SpeciationLikelihoodParser.CALIBRATION); |
| 483 |
|
| 484 |
if (!options.treeModelOptions.isNodeCalibrated(nodeCalib)) { |
| 485 |
throw new IllegalArgumentException("Calibrated Yule model requires a calibration to be specified for node, " + |
| 486 |
nodeCalib.getName() + "."); |
| 487 |
} |
| 488 |
} |
| 489 |
} |
| 490 |
|
| 491 |
writer.writeCloseTag(SpeciationLikelihoodParser.SPECIATION_LIKELIHOOD); |
| 492 |
|
| 493 |
break; |
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
case SKYLINE: |
| 532 |
|
| 533 |
writer.writeComment("Generate a generalizedSkyLineLikelihood for Bayesian Skyline"); |
| 534 |
writer.writeOpenTag( |
| 535 |
BayesianSkylineLikelihoodParser.SKYLINE_LIKELIHOOD, |
| 536 |
new Attribute[]{ |
| 537 |
new Attribute.Default<String>(XMLParser.ID, prefix + "skyline"), |
| 538 |
new Attribute.Default<String>("linear", |
| 539 |
prior.getSkylineModel() == TreePriorParameterizationType.LINEAR_SKYLINE ? "true" : "false") |
| 540 |
} |
| 541 |
); |
| 542 |
|
| 543 |
|
| 544 |
writer.writeOpenTag(BayesianSkylineLikelihoodParser.POPULATION_SIZES); |
| 545 |
if (prior.getSkylineModel() == TreePriorParameterizationType.LINEAR_SKYLINE) { |
| 546 |
writeParameter(prior.getParameter("skyline.popSize"), prior.getSkylineGroupCount() + 1, writer); |
| 547 |
} else { |
| 548 |
writeParameter(prior.getParameter("skyline.popSize"), prior.getSkylineGroupCount(), writer); |
| 549 |
} |
| 550 |
writer.writeCloseTag(BayesianSkylineLikelihoodParser.POPULATION_SIZES); |
| 551 |
|
| 552 |
|
| 553 |
writer.writeOpenTag(BayesianSkylineLikelihoodParser.GROUP_SIZES); |
| 554 |
writeParameter(prior.getParameter("skyline.groupSize"), prior.getSkylineGroupCount(), writer); |
| 555 |
writer.writeCloseTag(BayesianSkylineLikelihoodParser.GROUP_SIZES); |
| 556 |
|
| 557 |
writer.writeOpenTag(CoalescentLikelihoodParser.POPULATION_TREE); |
| 558 |
writer.writeIDref(TreeModel.TREE_MODEL, prefix + TreeModel.TREE_MODEL); |
| 559 |
writer.writeCloseTag(CoalescentLikelihoodParser.POPULATION_TREE); |
| 560 |
|
| 561 |
writer.writeCloseTag(BayesianSkylineLikelihoodParser.SKYLINE_LIKELIHOOD); |
| 562 |
|
| 563 |
writer.writeText(""); |
| 564 |
writeExponentialMarkovLikelihood(prior, writer); |
| 565 |
|
| 566 |
break; |
| 567 |
|
| 568 |
case EXTENDED_SKYLINE: |
| 569 |
|
| 570 |
break; |
| 571 |
|
| 572 |
case GMRF_SKYRIDE: |
| 573 |
writer.writeComment("Generate a gmrfSkyrideLikelihood for GMRF Bayesian Skyride process"); |
| 574 |
writer.writeOpenTag( |
| 575 |
GMRFSkyrideLikelihoodParser.SKYLINE_LIKELIHOOD, |
| 576 |
new Attribute[]{ |
| 577 |
new Attribute.Default<String>(XMLParser.ID, prefix + "skyride"), |
| 578 |
new Attribute.Default<String>(GMRFSkyrideLikelihoodParser.TIME_AWARE_SMOOTHING, |
| 579 |
prior.getSkyrideSmoothing() == TreePriorParameterizationType.TIME_AWARE_SKYRIDE ? "true" : "false"), |
| 580 |
new Attribute.Default<String>(GMRFSkyrideLikelihoodParser.RANDOMIZE_TREE, |
| 581 |
|
| 582 |
options.getPartitionTreeModels(prior).get(0).getStartingTreeType() == StartingTreeType.UPGMA ? "true" : "false"), |
| 583 |
} |
| 584 |
); |
| 585 |
|
| 586 |
int skyrideIntervalCount = options.taxonList.getTaxonCount() - 1; |
| 587 |
writer.writeOpenTag(GMRFSkyrideLikelihoodParser.POPULATION_PARAMETER); |
| 588 |
writer.writeComment("skyride.logPopSize is in log units unlike other popSize"); |
| 589 |
writeParameter(prior.getParameter("skyride.logPopSize"), skyrideIntervalCount, writer); |
| 590 |
writer.writeCloseTag(GMRFSkyrideLikelihoodParser.POPULATION_PARAMETER); |
| 591 |
|
| 592 |
writer.writeOpenTag(GMRFSkyrideLikelihoodParser.GROUP_SIZES); |
| 593 |
writeParameter(prior.getParameter("skyride.groupSize"), skyrideIntervalCount, writer); |
| 594 |
writer.writeCloseTag(GMRFSkyrideLikelihoodParser.GROUP_SIZES); |
| 595 |
|
| 596 |
writer.writeOpenTag(GMRFSkyrideLikelihoodParser.PRECISION_PARAMETER); |
| 597 |
writeParameter(prior.getParameter("skyride.precision"), 1, writer); |
| 598 |
writer.writeCloseTag(GMRFSkyrideLikelihoodParser.PRECISION_PARAMETER); |
| 599 |
|
| 600 |
writer.writeOpenTag(GMRFSkyrideLikelihoodParser.POPULATION_TREE); |
| 601 |
writer.writeIDref(TreeModel.TREE_MODEL, prefix + TreeModel.TREE_MODEL); |
| 602 |
writer.writeCloseTag(GMRFSkyrideLikelihoodParser.POPULATION_TREE); |
| 603 |
|
| 604 |
writer.writeCloseTag(GMRFSkyrideLikelihoodParser.SKYLINE_LIKELIHOOD); |
| 605 |
|
| 606 |
break; |
| 607 |
|
| 608 |
case SKYGRID: |
| 609 |
break; |
| 610 |
|
| 611 |
default: |
| 612 |
|
| 613 |
writer.writeComment("Generate a coalescent likelihood"); |
| 614 |
writer.writeOpenTag( |
| 615 |
CoalescentLikelihoodParser.COALESCENT_LIKELIHOOD, |
| 616 |
new Attribute[]{new Attribute.Default<String>(XMLParser.ID, prefix + COALESCENT)} |
| 617 |
); |
| 618 |
writer.writeOpenTag(CoalescentLikelihoodParser.MODEL); |
| 619 |
writeNodeHeightPriorModelRef(prior, writer); |
| 620 |
writer.writeCloseTag(CoalescentLikelihoodParser.MODEL); |
| 621 |
writer.writeOpenTag(CoalescentLikelihoodParser.POPULATION_TREE); |
| 622 |
writer.writeIDref(TreeModel.TREE_MODEL, prefix + TreeModel.TREE_MODEL); |
| 623 |
writer.writeCloseTag(CoalescentLikelihoodParser.POPULATION_TREE); |
| 624 |
writer.writeCloseTag(CoalescentLikelihoodParser.COALESCENT_LIKELIHOOD); |
| 625 |
} |
| 626 |
} |
| 627 |
|
| 628 |
void writeNodeHeightPriorModelRef(PartitionTreePrior prior, XMLWriter writer) { |
| 629 |
TreePriorType treePrior = prior.getNodeHeightPrior(); |
| 630 |
String priorPrefix = prior.getPrefix(); |
| 631 |
|
| 632 |
switch (treePrior) { |
| 633 |
case CONSTANT: |
| 634 |
writer.writeIDref(ConstantPopulationModelParser.CONSTANT_POPULATION_MODEL, priorPrefix + "constant"); |
| 635 |
break; |
| 636 |
case EXPONENTIAL: |
| 637 |
writer.writeIDref(ExponentialGrowthModelParser.EXPONENTIAL_GROWTH_MODEL, priorPrefix + "exponential"); |
| 638 |
break; |
| 639 |
case LOGISTIC: |
| 640 |
writer.writeIDref(LogisticGrowthModelParser.LOGISTIC_GROWTH_MODEL, priorPrefix + "logistic"); |
| 641 |
break; |
| 642 |
case EXPANSION: |
| 643 |
writer.writeIDref(ExpansionModelParser.EXPANSION_MODEL, priorPrefix + "expansion"); |
| 644 |
break; |
| 645 |
case SKYLINE: |
| 646 |
writer.writeIDref(BayesianSkylineLikelihoodParser.SKYLINE_LIKELIHOOD, priorPrefix + "skyline"); |
| 647 |
break; |
| 648 |
case GMRF_SKYRIDE: |
| 649 |
writer.writeIDref(GMRFSkyrideLikelihoodParser.SKYLINE_LIKELIHOOD, priorPrefix + "skyride"); |
| 650 |
break; |
| 651 |
case SKYGRID: |
| 652 |
writer.writeIDref(GMRFSkyrideLikelihoodParser.SKYGRID_LIKELIHOOD, priorPrefix + "skygrid"); |
| 653 |
break; |
| 654 |
case YULE: |
| 655 |
case YULE_CALIBRATION: |
| 656 |
writer.writeIDref(YuleModelParser.YULE_MODEL, priorPrefix + YuleModelParser.YULE); |
| 657 |
break; |
| 658 |
case BIRTH_DEATH: |
| 659 |
case BIRTH_DEATH_INCOMPLETE_SAMPLING: |
| 660 |
writer.writeIDref(BirthDeathModelParser.BIRTH_DEATH_MODEL, priorPrefix + BirthDeathModelParser.BIRTH_DEATH); |
| 661 |
break; |
| 662 |
case BIRTH_DEATH_SERIAL_SAMPLING: |
| 663 |
writer.writeIDref(BirthDeathSerialSamplingModelParser.BIRTH_DEATH_SERIAL_MODEL, |
| 664 |
priorPrefix + BirthDeathSerialSamplingModelParser.BDSS); |
| 665 |
break; |
| 666 |
case BIRTH_DEATH_BASIC_REPRODUCTIVE_NUMBER: |
| 667 |
writer.writeIDref(BirthDeathEpidemiologyModelParser.BIRTH_DEATH_EPIDEMIOLOGY, |
| 668 |
priorPrefix + BirthDeathEpidemiologyModelParser.BIRTH_DEATH_EPIDEMIOLOGY); |
| 669 |
break; |
| 670 |
default: |
| 671 |
throw new IllegalArgumentException("No tree prior has been specified so cannot refer to it"); |
| 672 |
} |
| 673 |
} |
| 674 |
|
| 675 |
void writeMultiLociTreePriors(PartitionTreePrior prior, XMLWriter writer) { |
| 676 |
|
| 677 |
String priorPrefix = prior.getPrefix(); |
| 678 |
|
| 679 |
if (prior.getNodeHeightPrior() == TreePriorType.SKYGRID) { |
| 680 |
|
| 681 |
writer.writeComment("Generate a gmrfSkyGridLikelihood for the Bayesian SkyGrid process"); |
| 682 |
writer.writeOpenTag( |
| 683 |
GMRFSkyrideLikelihoodParser.SKYGRID_LIKELIHOOD, |
| 684 |
new Attribute[]{ |
| 685 |
new Attribute.Default<String>(XMLParser.ID, priorPrefix + "skygrid"), |
| 686 |
} |
| 687 |
); |
| 688 |
|
| 689 |
int skyGridIntervalCount = prior.getSkyGridCount(); |
| 690 |
double skyGridInterval = prior.getSkyGridInterval(); |
| 691 |
|
| 692 |
writer.writeOpenTag(GMRFSkyrideLikelihoodParser.POPULATION_PARAMETER); |
| 693 |
writer.writeComment("skygrid.logPopSize is in log units unlike other popSize"); |
| 694 |
writeParameter(prior.getParameter("skygrid.logPopSize"), skyGridIntervalCount, writer); |
| 695 |
writer.writeCloseTag(GMRFSkyrideLikelihoodParser.POPULATION_PARAMETER); |
| 696 |
|
| 697 |
writer.writeOpenTag(GMRFSkyrideLikelihoodParser.PRECISION_PARAMETER); |
| 698 |
writeParameter(prior.getParameter("skygrid.precision"), 1, writer); |
| 699 |
writer.writeCloseTag(GMRFSkyrideLikelihoodParser.PRECISION_PARAMETER); |
| 700 |
|
| 701 |
writer.writeOpenTag(GMRFSkyrideLikelihoodParser.NUM_GRID_POINTS); |
| 702 |
Parameter numGridPoint = prior.getParameter("skygrid.numGridPoints"); |
| 703 |
numGridPoint.setInitial(skyGridIntervalCount - 1); |
| 704 |
writeParameter(numGridPoint, 1, writer); |
| 705 |
writer.writeCloseTag(GMRFSkyrideLikelihoodParser.NUM_GRID_POINTS); |
| 706 |
|
| 707 |
writer.writeOpenTag(GMRFSkyrideLikelihoodParser.CUT_OFF); |
| 708 |
Parameter cutOff = prior.getParameter("skygrid.cutOff"); |
| 709 |
cutOff.setInitial(skyGridInterval); |
| 710 |
writeParameter(cutOff, 1, writer); |
| 711 |
writer.writeCloseTag(GMRFSkyrideLikelihoodParser.CUT_OFF); |
| 712 |
|
| 713 |
writer.writeOpenTag(GMRFSkyrideLikelihoodParser.POPULATION_TREE); |
| 714 |
|
| 715 |
if (options.isShareSameTreePrior()) { |
| 716 |
for (PartitionTreeModel thisModel : options.getPartitionTreeModels()) { |
| 717 |
writer.writeIDref(TreeModel.TREE_MODEL, thisModel.getPrefix() + TreeModel.TREE_MODEL); |
| 718 |
} |
| 719 |
} else { |
| 720 |
writer.writeIDref(TreeModel.TREE_MODEL, options.getPartitionTreeModels(prior).get(0).getPrefix() + TreeModel.TREE_MODEL); |
| 721 |
} |
| 722 |
writer.writeCloseTag(GMRFSkyrideLikelihoodParser.POPULATION_TREE); |
| 723 |
|
| 724 |
writer.writeCloseTag(GMRFSkyrideLikelihoodParser.SKYGRID_LIKELIHOOD); |
| 725 |
|
| 726 |
} else if (prior.getNodeHeightPrior() == TreePriorType.EXTENDED_SKYLINE) { |
| 727 |
|
| 728 |
final String tagName = VariableDemographicModelParser.MODEL_NAME; |
| 729 |
writer.writeComment("Generate a variableDemographic for extended Bayesian skyline process"); |
| 730 |
writer.writeOpenTag(tagName, new Attribute[]{ |
| 731 |
new Attribute.Default<String>(XMLParser.ID, priorPrefix + VariableDemographicModelParser.demoElementName), |
| 732 |
new Attribute.Default<String>(VariableDemographicModelParser.TYPE, prior.getExtendedSkylineModel().toString()), |
| 733 |
|
| 734 |
new Attribute.Default<String>(VariableDemographicModelParser.USE_MIDPOINTS, "true") |
| 735 |
} |
| 736 |
); |
| 737 |
|
| 738 |
Parameter popSize = prior.getParameter(VariableDemographicModelParser.demoElementName + ".popSize"); |
| 739 |
Parameter populationMean = prior.getParameter(VariableDemographicModelParser.demoElementName + ".populationMean"); |
| 740 |
popSize.setInitial(populationMean.getInitial()); |
| 741 |
|
| 742 |
writer.writeOpenTag(VariableDemographicModelParser.POPULATION_SIZES); |
| 743 |
writer.writeComment("popSize value = populationMean value"); |
| 744 |
writer.writeTag(ParameterParser.PARAMETER, |
| 745 |
new Attribute[]{ |
| 746 |
new Attribute.Default<String>(XMLParser.ID, priorPrefix + VariableDemographicModelParser.demoElementName + ".popSize"), |
| 747 |
new Attribute.Default<String>(ParameterParser.VALUE, Double.toString(popSize.getInitial()))}, true); |
| 748 |
|
| 749 |
writer.writeCloseTag(VariableDemographicModelParser.POPULATION_SIZES); |
| 750 |
|
| 751 |
|
| 752 |
writer.writeOpenTag(VariableDemographicModelParser.INDICATOR_PARAMETER); |
| 753 |
writer.writeTag(ParameterParser.PARAMETER, |
| 754 |
new Attribute[]{ |
| 755 |
new Attribute.Default<String>(XMLParser.ID, priorPrefix + VariableDemographicModelParser.demoElementName + ".indicators"), |
| 756 |
new Attribute.Default<String>(ParameterParser.VALUE, Double.toString(0.0))}, true); |
| 757 |
|
| 758 |
writer.writeCloseTag(VariableDemographicModelParser.INDICATOR_PARAMETER); |
| 759 |
|
| 760 |
writer.writeOpenTag(VariableDemographicModelParser.POPULATION_TREES); |
| 761 |
|
| 762 |
if (options.isShareSameTreePrior()) { |
| 763 |
for (PartitionTreeModel model : options.getPartitionTreeModels()) { |
| 764 |
writer.writeOpenTag(VariableDemographicModelParser.POP_TREE, new Attribute[]{ |
| 765 |
new Attribute.Default<String>(SpeciesBindingsParser.PLOIDY, Double.toString(model.getPloidyType().getValue())) |
| 766 |
} |
| 767 |
); |
| 768 |
writer.writeIDref(TreeModel.TREE_MODEL, model.getPrefix() + TreeModel.TREE_MODEL); |
| 769 |
writer.writeCloseTag(VariableDemographicModelParser.POP_TREE); |
| 770 |
} |
| 771 |
} else { |
| 772 |
writer.writeOpenTag(VariableDemographicModelParser.POP_TREE, new Attribute[]{ |
| 773 |
new Attribute.Default<String>(SpeciesBindingsParser.PLOIDY, Double.toString(options.getPartitionTreeModels(prior).get(0).getPloidyType().getValue())) |
| 774 |
} |
| 775 |
); |
| 776 |
writer.writeIDref(TreeModel.TREE_MODEL, options.getPartitionTreeModels(prior).get(0).getPrefix() + TreeModel.TREE_MODEL); |
| 777 |
writer.writeCloseTag(VariableDemographicModelParser.POP_TREE); |
| 778 |
} |
| 779 |
|
| 780 |
writer.writeCloseTag(VariableDemographicModelParser.POPULATION_TREES); |
| 781 |
|
| 782 |
writer.writeCloseTag(tagName); |
| 783 |
|
| 784 |
writer.writeOpenTag(CoalescentLikelihoodParser.COALESCENT_LIKELIHOOD, new Attribute.Default<String>(XMLParser.ID, priorPrefix + COALESCENT)); |
| 785 |
writer.writeOpenTag(CoalescentLikelihoodParser.MODEL); |
| 786 |
writer.writeIDref(tagName, priorPrefix + VariableDemographicModelParser.demoElementName); |
| 787 |
writer.writeCloseTag(CoalescentLikelihoodParser.MODEL); |
| 788 |
writer.writeComment("Take population Tree from demographic"); |
| 789 |
writer.writeCloseTag(CoalescentLikelihoodParser.COALESCENT_LIKELIHOOD); |
| 790 |
|
| 791 |
writer.writeOpenTag(SumStatisticParser.SUM_STATISTIC, |
| 792 |
new Attribute[]{ |
| 793 |
new Attribute.Default<String>(XMLParser.ID, priorPrefix + VariableDemographicModelParser.demoElementName + ".populationSizeChanges"), |
| 794 |
new Attribute.Default<String>("elementwise", "true") |
| 795 |
}); |
| 796 |
writer.writeIDref(ParameterParser.PARAMETER, priorPrefix + VariableDemographicModelParser.demoElementName + ".indicators"); |
| 797 |
writer.writeCloseTag(SumStatisticParser.SUM_STATISTIC); |
| 798 |
writer.writeOpenTag(ExponentialDistributionModel.EXPONENTIAL_DISTRIBUTION_MODEL, |
| 799 |
new Attribute[]{ |
| 800 |
new Attribute.Default<String>(XMLParser.ID, priorPrefix + VariableDemographicModelParser.demoElementName + ".populationMeanDist") |
| 801 |
|
| 802 |
}); |
| 803 |
writer.writeOpenTag(DistributionModelParser.MEAN); |
| 804 |
|
| 805 |
writer.writeComment("prefer populationMean value = 1"); |
| 806 |
populationMean = prior.getParameter(VariableDemographicModelParser.demoElementName + ".populationMean"); |
| 807 |
writer.writeTag(ParameterParser.PARAMETER, |
| 808 |
new Attribute[]{ |
| 809 |
new Attribute.Default<String>(XMLParser.ID, priorPrefix + VariableDemographicModelParser.demoElementName + ".populationMean"), |
| 810 |
new Attribute.Default<String>(ParameterParser.VALUE, Double.toString(populationMean.getInitial()))}, true); |
| 811 |
|
| 812 |
writer.writeCloseTag(DistributionModelParser.MEAN); |
| 813 |
writer.writeCloseTag(ExponentialDistributionModel.EXPONENTIAL_DISTRIBUTION_MODEL); |
| 814 |
} |
| 815 |
} |
| 816 |
|
| 817 |
void writeParameterLog(PartitionTreePrior prior, XMLWriter writer) { |
| 818 |
|
| 819 |
String priorPrefix = prior.getPrefix(); |
| 820 |
|
| 821 |
switch (prior.getNodeHeightPrior()) { |
| 822 |
|
| 823 |
case CONSTANT: |
| 824 |
writeParameterRef(priorPrefix + "constant.popSize", writer); |
| 825 |
break; |
| 826 |
case EXPONENTIAL: |
| 827 |
writeParameterRef(priorPrefix + "exponential.popSize", writer); |
| 828 |
if (prior.getParameterization() == TreePriorParameterizationType.GROWTH_RATE) { |
| 829 |
writeParameterRef(priorPrefix + "exponential.growthRate", writer); |
| 830 |
} else { |
| 831 |
writeParameterRef(priorPrefix + "exponential.doublingTime", writer); |
| 832 |
} |
| 833 |
break; |
| 834 |
case LOGISTIC: |
| 835 |
writeParameterRef(priorPrefix + "logistic.popSize", writer); |
| 836 |
if (prior.getParameterization() == TreePriorParameterizationType.GROWTH_RATE) { |
| 837 |
writeParameterRef(priorPrefix + "logistic.growthRate", writer); |
| 838 |
} else { |
| 839 |
writeParameterRef(priorPrefix + "logistic.doublingTime", writer); |
| 840 |
} |
| 841 |
writeParameterRef(priorPrefix + "logistic.t50", writer); |
| 842 |
break; |
| 843 |
case EXPANSION: |
| 844 |
writeParameterRef(priorPrefix + "expansion.popSize", writer); |
| 845 |
if (prior.getParameterization() == TreePriorParameterizationType.GROWTH_RATE) { |
| 846 |
writeParameterRef(priorPrefix + "expansion.growthRate", writer); |
| 847 |
} else { |
| 848 |
writeParameterRef(priorPrefix + "expansion.doublingTime", writer); |
| 849 |
} |
| 850 |
writeParameterRef(priorPrefix + "expansion.ancestralProportion", writer); |
| 851 |
break; |
| 852 |
case SKYLINE: |
| 853 |
writeParameterRef(priorPrefix + "skyline.popSize", writer); |
| 854 |
writeParameterRef(priorPrefix + "skyline.groupSize", writer); |
| 855 |
break; |
| 856 |
case EXTENDED_SKYLINE: |
| 857 |
writer.writeIDref(SumStatisticParser.SUM_STATISTIC, "demographic.populationSizeChanges"); |
| 858 |
writeParameterRef(priorPrefix + "demographic.populationMean", writer); |
| 859 |
writeParameterRef(priorPrefix + "demographic.popSize", writer); |
| 860 |
writeParameterRef(priorPrefix + "demographic.indicators", writer); |
| 861 |
break; |
| 862 |
case SKYGRID: |
| 863 |
writeParameterRef(priorPrefix + "skygrid.precision", writer); |
| 864 |
writeParameterRef(priorPrefix + "skygrid.logPopSize", writer); |
| 865 |
writeParameterRef(priorPrefix + "skygrid.cutOff", writer); |
| 866 |
|
| 867 |
break; |
| 868 |
case GMRF_SKYRIDE: |
| 869 |
writeParameterRef(priorPrefix + "skyride.precision", writer); |
| 870 |
writeParameterRef(priorPrefix + "skyride.logPopSize", writer); |
| 871 |
writeParameterRef(priorPrefix + "skyride.groupSize", writer); |
| 872 |
break; |
| 873 |
case YULE: |
| 874 |
case YULE_CALIBRATION: |
| 875 |
writeParameterRef(priorPrefix + "yule.birthRate", writer); |
| 876 |
break; |
| 877 |
case BIRTH_DEATH: |
| 878 |
case BIRTH_DEATH_INCOMPLETE_SAMPLING: |
| 879 |
writeParameterRef(priorPrefix + BirthDeathModelParser.MEAN_GROWTH_RATE_PARAM_NAME, writer); |
| 880 |
writeParameterRef(priorPrefix + BirthDeathModelParser.RELATIVE_DEATH_RATE_PARAM_NAME, writer); |
| 881 |
if (prior.getNodeHeightPrior() == TreePriorType.BIRTH_DEATH_INCOMPLETE_SAMPLING) |
| 882 |
writeParameterRef(priorPrefix + BirthDeathModelParser.BIRTH_DEATH + "." |
| 883 |
+ BirthDeathModelParser.SAMPLE_PROB, writer); |
| 884 |
break; |
| 885 |
case BIRTH_DEATH_SERIAL_SAMPLING: |
| 886 |
writeParameterRef(priorPrefix + BirthDeathSerialSamplingModelParser.BDSS + "." |
| 887 |
+ BirthDeathSerialSamplingModelParser.LAMBDA, writer); |
| 888 |
writeParameterRef(priorPrefix + BirthDeathSerialSamplingModelParser.BDSS + "." |
| 889 |
+ BirthDeathSerialSamplingModelParser.RELATIVE_MU, writer); |
| 890 |
|
| 891 |
|
| 892 |
|
| 893 |
writeParameterRef(priorPrefix + BirthDeathSerialSamplingModelParser.BDSS + "." |
| 894 |
+ BirthDeathSerialSamplingModelParser.PSI, writer); |
| 895 |
writeParameterRef(priorPrefix + BirthDeathSerialSamplingModelParser.BDSS + "." |
| 896 |
+ BirthDeathSerialSamplingModelParser.ORIGIN, writer); |
| 897 |
break; |
| 898 |
case BIRTH_DEATH_BASIC_REPRODUCTIVE_NUMBER: |
| 899 |
writeParameterRef(priorPrefix + BirthDeathEpidemiologyModelParser.R0, writer); |
| 900 |
writeParameterRef(priorPrefix + BirthDeathEpidemiologyModelParser.RECOVERY_RATE, writer); |
| 901 |
writeParameterRef(priorPrefix + BirthDeathEpidemiologyModelParser.SAMPLING_PROBABILITY, writer); |
| 902 |
writeParameterRef(priorPrefix + BirthDeathEpidemiologyModelParser.ORIGIN, writer); |
| 903 |
default: |
| 904 |
throw new IllegalArgumentException("No tree prior has been specified so cannot refer to it"); |
| 905 |
} |
| 906 |
|
| 907 |
} |
| 908 |
|
| 909 |
void writeEBSPAnalysisToCSVfile(PartitionTreePrior prior, XMLWriter writer) { |
| 910 |
|
| 911 |
String priorPrefix = prior.getPrefix(); |
| 912 |
|
| 913 |
String logFileName = options.logFileName; |
| 914 |
|
| 915 |
if (prior.getNodeHeightPrior() == TreePriorType.EXTENDED_SKYLINE) { |
| 916 |
writer.writeOpenTag(EBSPAnalysisParser.VD_ANALYSIS, new Attribute[]{ |
| 917 |
new Attribute.Default<String>(XMLParser.ID, priorPrefix + "demographic.analysis"), |
| 918 |
new Attribute.Default<Double>(EBSPAnalysisParser.BURN_IN, 0.1), |
| 919 |
new Attribute.Default<Boolean>(VariableDemographicModelParser.USE_MIDPOINTS, true)} |
| 920 |
); |
| 921 |
|
| 922 |
writer.writeOpenTag(EBSPAnalysisParser.LOG_FILE_NAME); |
| 923 |
writer.writeText(logFileName); |
| 924 |
writer.writeCloseTag(EBSPAnalysisParser.LOG_FILE_NAME); |
| 925 |
|
| 926 |
writer.writeOpenTag(EBSPAnalysisParser.TREE_FILE_NAMES); |
| 927 |
for (String treeFN : options.treeFileName) { |
| 928 |
writer.writeOpenTag(EBSPAnalysisParser.TREE_LOG); |
| 929 |
writer.writeText(treeFN); |
| 930 |
writer.writeCloseTag(EBSPAnalysisParser.TREE_LOG); |
| 931 |
} |
| 932 |
writer.writeCloseTag(EBSPAnalysisParser.TREE_FILE_NAMES); |
| 933 |
|
| 934 |
writer.writeOpenTag(EBSPAnalysisParser.MODEL_TYPE); |
| 935 |
writer.writeText(prior.getExtendedSkylineModel().toString()); |
| 936 |
writer.writeCloseTag(EBSPAnalysisParser.MODEL_TYPE); |
| 937 |
|
| 938 |
writer.writeOpenTag(EBSPAnalysisParser.POPULATION_FIRST_COLUMN); |
| 939 |
writer.writeText(VariableDemographicModelParser.demoElementName + ".popSize1"); |
| 940 |
writer.writeCloseTag(EBSPAnalysisParser.POPULATION_FIRST_COLUMN); |
| 941 |
|
| 942 |
writer.writeOpenTag(EBSPAnalysisParser.INDICATORS_FIRST_COLUMN); |
| 943 |
writer.writeText(VariableDemographicModelParser.demoElementName + ".indicators1"); |
| 944 |
writer.writeCloseTag(EBSPAnalysisParser.INDICATORS_FIRST_COLUMN); |
| 945 |
|
| 946 |
writer.writeCloseTag(EBSPAnalysisParser.VD_ANALYSIS); |
| 947 |
|
| 948 |
writer.writeOpenTag(CSVExporterParser.CSV_EXPORT, |
| 949 |
new Attribute[]{ |
| 950 |
new Attribute.Default<String>(CSVExporterParser.FILE_NAME, |
| 951 |
logFileName.subSequence(0, logFileName.length() - 4) + ".csv"), |
| 952 |
new Attribute.Default<String>(CSVExporterParser.SEPARATOR, ",") |
| 953 |
}); |
| 954 |
writer.writeOpenTag(CSVExporterParser.COLUMNS); |
| 955 |
writer.writeIDref(EBSPAnalysisParser.VD_ANALYSIS, priorPrefix + "demographic.analysis"); |
| 956 |
writer.writeCloseTag(CSVExporterParser.COLUMNS); |
| 957 |
writer.writeCloseTag(CSVExporterParser.CSV_EXPORT); |
| 958 |
} |
| 959 |
} |
| 960 |
|
| 961 |
private void writeExponentialMarkovLikelihood(PartitionTreePrior prior, XMLWriter writer) { |
| 962 |
|
| 963 |
writer.writeOpenTag( |
| 964 |
ExponentialMarkovModel.EXPONENTIAL_MARKOV_MODEL, |
| 965 |
new Attribute[]{new Attribute.Default<String>(XMLParser.ID, prior.getPrefix() + "eml1"), |
| 966 |
new Attribute.Default<String>("jeffreys", "true")} |
| 967 |
); |
| 968 |
|
| 969 |
writeParameterRef(ExponentialMarkovModelParser.CHAIN_PARAMETER, prior.getPrefix() + "skyline.popSize", writer); |
| 970 |
|
| 971 |
writer.writeCloseTag(ExponentialMarkovModel.EXPONENTIAL_MARKOV_MODEL); |
| 972 |
} |
| 973 |
|
| 974 |
public static void writePriorLikelihoodReferenceLog(PartitionTreePrior prior, PartitionTreeModel model, XMLWriter writer) { |
| 975 |
|
| 976 |
String prefix = model.getPrefix(); |
| 977 |
|
| 978 |
switch (prior.getNodeHeightPrior()) { |
| 979 |
|
| 980 |
case YULE: |
| 981 |
case YULE_CALIBRATION: |
| 982 |
case BIRTH_DEATH: |
| 983 |
case BIRTH_DEATH_INCOMPLETE_SAMPLING: |
| 984 |
case BIRTH_DEATH_SERIAL_SAMPLING: |
| 985 |
case BIRTH_DEATH_BASIC_REPRODUCTIVE_NUMBER: |
| 986 |
writer.writeIDref(SpeciationLikelihoodParser.SPECIATION_LIKELIHOOD, prefix + "speciation"); |
| 987 |
break; |
| 988 |
case SKYLINE: |
| 989 |
writer.writeIDref(BayesianSkylineLikelihoodParser.SKYLINE_LIKELIHOOD, prefix + "skyline"); |
| 990 |
|
| 991 |
break; |
| 992 |
case GMRF_SKYRIDE: |
| 993 |
writer.writeIDref(GMRFSkyrideLikelihoodParser.SKYLINE_LIKELIHOOD, prefix + "skyride"); |
| 994 |
break; |
| 995 |
case SKYGRID: |
| 996 |
writer.writeIDref(GMRFSkyrideLikelihoodParser.SKYLINE_LIKELIHOOD, prefix + "skygrid"); |
| 997 |
|
| 998 |
break; |
| 999 |
case LOGISTIC: |
| 1000 |
|
| 1001 |
writer.writeIDref(CoalescentLikelihoodParser.COALESCENT_LIKELIHOOD, prefix + COALESCENT); |
| 1002 |
break; |
| 1003 |
case EXTENDED_SKYLINE: |
| 1004 |
|
| 1005 |
default: |
| 1006 |
writer.writeIDref(CoalescentLikelihoodParser.COALESCENT_LIKELIHOOD, prefix + COALESCENT); |
| 1007 |
} |
| 1008 |
} |
| 1009 |
|
| 1010 |
|
| 1011 |
public void writePriorLikelihoodReference(PartitionTreePrior prior, PartitionTreeModel model, XMLWriter writer) { |
| 1012 |
|
| 1013 |
String prefix = model.getPrefix(); |
| 1014 |
|
| 1015 |
switch (prior.getNodeHeightPrior()) { |
| 1016 |
|
| 1017 |
case YULE: |
| 1018 |
case YULE_CALIBRATION: |
| 1019 |
case BIRTH_DEATH: |
| 1020 |
case BIRTH_DEATH_INCOMPLETE_SAMPLING: |
| 1021 |
case BIRTH_DEATH_SERIAL_SAMPLING: |
| 1022 |
case BIRTH_DEATH_BASIC_REPRODUCTIVE_NUMBER: |
| 1023 |
writer.writeIDref(SpeciationLikelihoodParser.SPECIATION_LIKELIHOOD, prefix + "speciation"); |
| 1024 |
break; |
| 1025 |
case SKYLINE: |
| 1026 |
writer.writeIDref(BayesianSkylineLikelihoodParser.SKYLINE_LIKELIHOOD, prefix + "skyline"); |
| 1027 |
writer.writeIDref(ExponentialMarkovModel.EXPONENTIAL_MARKOV_MODEL, prefix + "eml1"); |
| 1028 |
break; |
| 1029 |
case GMRF_SKYRIDE: |
| 1030 |
writer.writeIDref(GMRFSkyrideLikelihoodParser.SKYLINE_LIKELIHOOD, prefix + "skyride"); |
| 1031 |
break; |
| 1032 |
case SKYGRID: |
| 1033 |
|
| 1034 |
|
| 1035 |
break; |
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
|
| 1040 |
case EXTENDED_SKYLINE: |
| 1041 |
|
| 1042 |
default: |
| 1043 |
writer.writeIDref(CoalescentLikelihoodParser.COALESCENT_LIKELIHOOD, prefix + COALESCENT); |
| 1044 |
} |
| 1045 |
} |
| 1046 |
|
| 1047 |
public void writeMultiLociLikelihoodReference(PartitionTreePrior prior, XMLWriter writer) { |
| 1048 |
|
| 1049 |
String prefix = prior.getPrefix(); |
| 1050 |
|
| 1051 |
|
| 1052 |
if (prior.getNodeHeightPrior() == TreePriorType.EXTENDED_SKYLINE) { |
| 1053 |
|
| 1054 |
writer.writeIDref(CoalescentLikelihoodParser.COALESCENT_LIKELIHOOD, prefix + COALESCENT); |
| 1055 |
|
| 1056 |
writer.writeOpenTag(MixedDistributionLikelihoodParser.DISTRIBUTION_LIKELIHOOD); |
| 1057 |
|
| 1058 |
writer.writeOpenTag(MixedDistributionLikelihoodParser.DISTRIBUTION0); |
| 1059 |
writer.writeIDref(ExponentialDistributionModel.EXPONENTIAL_DISTRIBUTION_MODEL, prefix + "demographic.populationMeanDist"); |
| 1060 |
writer.writeCloseTag(MixedDistributionLikelihoodParser.DISTRIBUTION0); |
| 1061 |
|
| 1062 |
writer.writeOpenTag(MixedDistributionLikelihoodParser.DISTRIBUTION1); |
| 1063 |
writer.writeIDref(ExponentialDistributionModel.EXPONENTIAL_DISTRIBUTION_MODEL, prefix + "demographic.populationMeanDist"); |
| 1064 |
writer.writeCloseTag(MixedDistributionLikelihoodParser.DISTRIBUTION1); |
| 1065 |
|
| 1066 |
writeParameterRef(MixedDistributionLikelihoodParser.DATA, prefix + "demographic.popSize", writer); |
| 1067 |
|
| 1068 |
writeParameterRef(MixedDistributionLikelihoodParser.INDICATORS, prefix + "demographic.indicators", writer); |
| 1069 |
|
| 1070 |
writer.writeCloseTag(MixedDistributionLikelihoodParser.DISTRIBUTION_LIKELIHOOD); |
| 1071 |
} else if (prior.getNodeHeightPrior() == TreePriorType.SKYGRID) { |
| 1072 |
writer.writeIDref(GMRFSkyrideLikelihoodParser.SKYGRID_LIKELIHOOD, prefix + "skygrid"); |
| 1073 |
} |
| 1074 |
|
| 1075 |
} |
| 1076 |
} |