| 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.components.ancestralstates.AncestralStatesComponentOptions; |
| 30 |
import dr.app.beauti.options.*; |
| 31 |
import dr.app.beauti.types.TreePriorType; |
| 32 |
import dr.app.beauti.util.XMLWriter; |
| 33 |
import dr.evolution.datatype.DataType; |
| 34 |
import dr.evolution.util.Taxa; |
| 35 |
import dr.evomodel.branchratemodel.BranchRateModel; |
| 36 |
import dr.evomodel.branchratemodel.MixtureModelBranchRates; |
| 37 |
import dr.evomodel.tree.TMRCAStatistic; |
| 38 |
import dr.evomodel.tree.TreeLengthStatistic; |
| 39 |
import dr.evomodel.tree.TreeModel; |
| 40 |
import dr.evomodelxml.branchratemodel.*; |
| 41 |
import dr.evomodelxml.tree.TreeLengthStatisticParser; |
| 42 |
import dr.evomodelxml.treelikelihood.MarkovJumpsTreeLikelihoodParser; |
| 43 |
import dr.inference.model.CompoundLikelihood; |
| 44 |
import dr.oldevomodelxml.clock.ACLikelihoodParser; |
| 45 |
import dr.evomodelxml.coalescent.CoalescentLikelihoodParser; |
| 46 |
import dr.evomodelxml.coalescent.GMRFSkyrideLikelihoodParser; |
| 47 |
import dr.evomodelxml.speciation.*; |
| 48 |
import dr.evomodelxml.tree.TMRCAStatisticParser; |
| 49 |
import dr.evomodelxml.tree.TreeLoggerParser; |
| 50 |
import dr.evomodelxml.tree.TreeModelParser; |
| 51 |
import dr.inference.model.ParameterParser; |
| 52 |
import dr.inferencexml.distribution.MixedDistributionLikelihoodParser; |
| 53 |
import dr.inferencexml.loggers.ColumnsParser; |
| 54 |
import dr.inferencexml.loggers.LoggerParser; |
| 55 |
import dr.inferencexml.model.CompoundLikelihoodParser; |
| 56 |
import dr.oldevomodelxml.treelikelihood.AncestralStateTreeLikelihoodParser; |
| 57 |
import dr.oldevomodelxml.treelikelihood.TreeLikelihoodParser; |
| 58 |
import dr.util.Attribute; |
| 59 |
import dr.xml.XMLParser; |
| 60 |
|
| 61 |
import java.util.ArrayList; |
| 62 |
import java.util.List; |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
public class LogGenerator extends Generator { |
| 70 |
|
| 71 |
private final static String TREE_FILE_LOG = "treeFileLog"; |
| 72 |
private final static String SUB_TREE_FILE_LOG = "substTreeFileLog"; |
| 73 |
|
| 74 |
public LogGenerator(BeautiOptions options, ComponentFactory[] components) { |
| 75 |
super(options, components); |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
public void writeLogToScreen(XMLWriter writer, ClockModelGenerator clockModelGenerator, |
| 85 |
SubstitutionModelGenerator substitutionModelGenerator) { |
| 86 |
writer.writeComment("write log to screen"); |
| 87 |
|
| 88 |
writer.writeOpenTag(LoggerParser.LOG, |
| 89 |
new Attribute[]{ |
| 90 |
new Attribute.Default<String>(XMLParser.ID, "screenLog"), |
| 91 |
new Attribute.Default<String>(LoggerParser.LOG_EVERY, options.echoEvery + "") |
| 92 |
}); |
| 93 |
|
| 94 |
if (options.hasData()) { |
| 95 |
writer.writeOpenTag(ColumnsParser.COLUMN, |
| 96 |
new Attribute[]{ |
| 97 |
new Attribute.Default<String>(ColumnsParser.LABEL, "Joint"), |
| 98 |
new Attribute.Default<String>(ColumnsParser.DECIMAL_PLACES, "4"), |
| 99 |
new Attribute.Default<String>(ColumnsParser.WIDTH, "12") |
| 100 |
} |
| 101 |
); |
| 102 |
writer.writeIDref(CompoundLikelihoodParser.JOINT, "joint"); |
| 103 |
writer.writeCloseTag(ColumnsParser.COLUMN); |
| 104 |
} |
| 105 |
|
| 106 |
writer.writeOpenTag(ColumnsParser.COLUMN, |
| 107 |
new Attribute[]{ |
| 108 |
new Attribute.Default<String>(ColumnsParser.LABEL, "Prior"), |
| 109 |
new Attribute.Default<String>(ColumnsParser.DECIMAL_PLACES, "4"), |
| 110 |
new Attribute.Default<String>(ColumnsParser.WIDTH, "12") |
| 111 |
} |
| 112 |
); |
| 113 |
writer.writeIDref(CompoundLikelihoodParser.PRIOR, "prior"); |
| 114 |
writer.writeCloseTag(ColumnsParser.COLUMN); |
| 115 |
|
| 116 |
if (options.hasData()) { |
| 117 |
writer.writeOpenTag(ColumnsParser.COLUMN, |
| 118 |
new Attribute[]{ |
| 119 |
new Attribute.Default<String>(ColumnsParser.LABEL, "Likelihood"), |
| 120 |
new Attribute.Default<String>(ColumnsParser.DECIMAL_PLACES, "4"), |
| 121 |
new Attribute.Default<String>(ColumnsParser.WIDTH, "12") |
| 122 |
} |
| 123 |
); |
| 124 |
writer.writeIDref(CompoundLikelihoodParser.LIKELIHOOD, "likelihood"); |
| 125 |
writer.writeCloseTag(ColumnsParser.COLUMN); |
| 126 |
} |
| 127 |
|
| 128 |
for (PartitionTreeModel model : options.getPartitionTreeModels()) { |
| 129 |
writer.writeOpenTag(ColumnsParser.COLUMN, |
| 130 |
new Attribute[]{ |
| 131 |
|
| 132 |
|
| 133 |
(model.hasTipCalibrations() ? |
| 134 |
new Attribute.Default<String>(ColumnsParser.LABEL, model.getPrefix() + "age(root)") : |
| 135 |
new Attribute.Default<String>(ColumnsParser.LABEL, model.getPrefix() + "rootHeight") |
| 136 |
), |
| 137 |
new Attribute.Default<String>(ColumnsParser.SIGNIFICANT_FIGURES, "6"), |
| 138 |
new Attribute.Default<String>(ColumnsParser.WIDTH, "12") |
| 139 |
} |
| 140 |
); |
| 141 |
|
| 142 |
if (model.hasTipCalibrations()) { |
| 143 |
writer.writeIDref(TMRCAStatisticParser.TMRCA_STATISTIC, model.getPrefix() + "age(root)"); |
| 144 |
} else { |
| 145 |
writer.writeIDref(ParameterParser.PARAMETER, model.getPrefix() + TreeModel.TREE_MODEL + "." + TreeModelParser.ROOT_HEIGHT); |
| 146 |
} |
| 147 |
|
| 148 |
writer.writeCloseTag(ColumnsParser.COLUMN); |
| 149 |
} |
| 150 |
|
| 151 |
for (PartitionClockModel model : options.getPartitionClockModels()) { |
| 152 |
|
| 153 |
if (model.performModelAveraging() || !model.getClockRateParameter().isFixed()) { |
| 154 |
writer.writeOpenTag(ColumnsParser.COLUMN, |
| 155 |
new Attribute[]{ |
| 156 |
new Attribute.Default<String>(ColumnsParser.LABEL, clockModelGenerator.getClockRateString(model)), |
| 157 |
new Attribute.Default<String>(ColumnsParser.SIGNIFICANT_FIGURES, "6"), |
| 158 |
new Attribute.Default<String>(ColumnsParser.WIDTH, "12") |
| 159 |
} |
| 160 |
); |
| 161 |
|
| 162 |
clockModelGenerator.writeAllClockRateRefs(model, writer); |
| 163 |
|
| 164 |
writer.writeCloseTag(ColumnsParser.COLUMN); |
| 165 |
} |
| 166 |
|
| 167 |
} |
| 168 |
|
| 169 |
for (PartitionSubstitutionModel model : options.getPartitionSubstitutionModels()) { |
| 170 |
if (model.getDataType().getType() == DataType.MICRO_SAT) |
| 171 |
substitutionModelGenerator.writeMicrosatSubstModelParameterRef(model, writer); |
| 172 |
} |
| 173 |
|
| 174 |
generateInsertionPoint(ComponentGenerator.InsertionPoint.IN_SCREEN_LOG, writer); |
| 175 |
|
| 176 |
writer.writeCloseTag(LoggerParser.LOG); |
| 177 |
|
| 178 |
generateInsertionPoint(ComponentGenerator.InsertionPoint.AFTER_SCREEN_LOG, writer); |
| 179 |
} |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
public void writeLogToFile(XMLWriter writer, |
| 191 |
TreePriorGenerator treePriorGenerator, |
| 192 |
ClockModelGenerator clockModelGenerator, |
| 193 |
SubstitutionModelGenerator substitutionModelGenerator, |
| 194 |
TreeLikelihoodGenerator treeLikelihoodGenerator, |
| 195 |
TMRCAStatisticsGenerator tmrcaStatisticsGenerator) { |
| 196 |
writer.writeComment("write log to file"); |
| 197 |
|
| 198 |
if (options.logFileName == null) { |
| 199 |
options.logFileName = options.fileNameStem + ".log"; |
| 200 |
} |
| 201 |
writer.writeOpenTag(LoggerParser.LOG, |
| 202 |
new Attribute[]{ |
| 203 |
new Attribute.Default<String>(XMLParser.ID, "fileLog"), |
| 204 |
new Attribute.Default<String>(LoggerParser.LOG_EVERY, options.logEvery + ""), |
| 205 |
new Attribute.Default<String>(LoggerParser.FILE_NAME, options.logFileName), |
| 206 |
new Attribute.Default<Boolean>(LoggerParser.ALLOW_OVERWRITE_LOG, options.allowOverwriteLog) |
| 207 |
}); |
| 208 |
|
| 209 |
if (options.hasData()) { |
| 210 |
writer.writeIDref(CompoundLikelihoodParser.JOINT, "joint"); |
| 211 |
} |
| 212 |
writer.writeIDref(CompoundLikelihoodParser.PRIOR, "prior"); |
| 213 |
if (options.hasData()) { |
| 214 |
writer.writeIDref(CompoundLikelihoodParser.LIKELIHOOD, "likelihood"); |
| 215 |
} |
| 216 |
|
| 217 |
for (PartitionTreeModel model : options.getPartitionTreeModels()) { |
| 218 |
writer.writeIDref(ParameterParser.PARAMETER, model.getPrefix() + TreeModel.TREE_MODEL + "." + TreeModelParser.ROOT_HEIGHT); |
| 219 |
} |
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
for (PartitionTreeModel model : options.getPartitionTreeModels()) { |
| 224 |
if (model.hasTipCalibrations()) { |
| 225 |
writer.writeIDref(TMRCAStatisticParser.TMRCA_STATISTIC, model.getPrefix() + "age(root)"); |
| 226 |
} |
| 227 |
} |
| 228 |
|
| 229 |
for (PartitionTreeModel model : options.getPartitionTreeModels()) { |
| 230 |
writer.writeIDref(TreeLengthStatisticParser.TREE_LENGTH_STATISTIC, model.getPrefix() + "treeLength"); |
| 231 |
} |
| 232 |
|
| 233 |
tmrcaStatisticsGenerator.writeTMRCAStatisticReferences(writer); |
| 234 |
|
| 235 |
for (PartitionTreePrior prior : options.getPartitionTreePriors()) { |
| 236 |
treePriorGenerator.writeParameterLog(prior, writer); |
| 237 |
} |
| 238 |
|
| 239 |
for (PartitionSubstitutionModel model : options.getPartitionSubstitutionModels()) { |
| 240 |
substitutionModelGenerator.writeLog(model, writer); |
| 241 |
} |
| 242 |
|
| 243 |
for (PartitionClockModel model : options.getPartitionClockModels()) { |
| 244 |
clockModelGenerator.writeLog(model, writer); |
| 245 |
} |
| 246 |
|
| 247 |
for (PartitionClockModel model : options.getPartitionClockModels()) { |
| 248 |
clockModelGenerator.writeLogStatistic(model, writer); |
| 249 |
} |
| 250 |
|
| 251 |
generateInsertionPoint(ComponentGenerator.InsertionPoint.IN_FILE_LOG_PARAMETERS, writer); |
| 252 |
|
| 253 |
treeLikelihoodGenerator.writeTreeLikelihoodReferences(writer); |
| 254 |
clockModelGenerator.writeClockLikelihoodReferences(writer); |
| 255 |
|
| 256 |
generateInsertionPoint(ComponentGenerator.InsertionPoint.IN_FILE_LOG_LIKELIHOODS, writer); |
| 257 |
|
| 258 |
|
| 259 |
for (PartitionTreeModel model : options.getPartitionTreeModels()) { |
| 260 |
PartitionTreePrior prior = model.getPartitionTreePrior(); |
| 261 |
if (prior.getNodeHeightPrior() != TreePriorType.EXTENDED_SKYLINE && |
| 262 |
prior.getNodeHeightPrior() != TreePriorType.SKYGRID) { |
| 263 |
|
| 264 |
treePriorGenerator.writePriorLikelihoodReferenceLog(prior, model, writer); |
| 265 |
writer.writeText(""); |
| 266 |
} |
| 267 |
} |
| 268 |
|
| 269 |
for (PartitionTreePrior prior : options.getPartitionTreePriors()) { |
| 270 |
if (prior.getNodeHeightPrior() == TreePriorType.EXTENDED_SKYLINE) { |
| 271 |
writer.writeIDref(CoalescentLikelihoodParser.COALESCENT_LIKELIHOOD, prior.getPrefix() + COALESCENT); |
| 272 |
} else if (prior.getNodeHeightPrior() == TreePriorType.SKYGRID) { |
| 273 |
writer.writeIDref(GMRFSkyrideLikelihoodParser.SKYGRID_LIKELIHOOD, prior.getPrefix() + "skygrid"); |
| 274 |
} |
| 275 |
} |
| 276 |
|
| 277 |
writer.writeCloseTag(LoggerParser.LOG); |
| 278 |
|
| 279 |
generateInsertionPoint(ComponentGenerator.InsertionPoint.AFTER_FILE_LOG, writer); |
| 280 |
|
| 281 |
} |
| 282 |
|
| 283 |
public void writeDemographicLogToFile(XMLWriter writer, |
| 284 |
TreePriorGenerator treePriorGenerator, |
| 285 |
ClockModelGenerator clockModelGenerator, |
| 286 |
SubstitutionModelGenerator substitutionModelGenerator, |
| 287 |
TreeLikelihoodGenerator treeLikelihoodGenerator) { |
| 288 |
writer.writeComment("demographic log file"); |
| 289 |
|
| 290 |
if (options.demographicLogFileName == null) { |
| 291 |
options.demographicLogFileName = options.fileNameStem + ".demo.log"; |
| 292 |
} |
| 293 |
|
| 294 |
String header = "Demographic Model: " + options.demographicModelName; |
| 295 |
writer.writeOpenTag(LoggerParser.LOG, |
| 296 |
new Attribute[]{ |
| 297 |
new Attribute.Default<String>(XMLParser.ID, "fileLog"), |
| 298 |
new Attribute.Default<String>(LoggerParser.HEADER, header + ""), |
| 299 |
new Attribute.Default<String>(LoggerParser.LOG_EVERY, options.logEvery + ""), |
| 300 |
new Attribute.Default<String>(LoggerParser.FILE_NAME, options.logFileName), |
| 301 |
new Attribute.Default<Boolean>(LoggerParser.ALLOW_OVERWRITE_LOG, options.allowOverwriteLog) |
| 302 |
}); |
| 303 |
|
| 304 |
if (options.hasData()) { |
| 305 |
writer.writeIDref(CompoundLikelihoodParser.JOINT, "joint"); |
| 306 |
} |
| 307 |
writer.writeIDref(CompoundLikelihoodParser.PRIOR, "prior"); |
| 308 |
|
| 309 |
for (PartitionTreeModel model : options.getPartitionTreeModels()) { |
| 310 |
writer.writeIDref(ParameterParser.PARAMETER, model.getPrefix() + TreeModel.TREE_MODEL + "." + TreeModelParser.ROOT_HEIGHT); |
| 311 |
} |
| 312 |
|
| 313 |
for (Taxa taxa : options.taxonSets) { |
| 314 |
|
| 315 |
PartitionTreeModel treeModel = options.taxonSetsTreeModel.get(taxa); |
| 316 |
writer.writeIDref(TMRCAStatisticParser.TMRCA_STATISTIC, "tmrca(" + treeModel.getPrefix() + taxa.getId() + ")"); |
| 317 |
} |
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
for (PartitionTreePrior prior : options.getPartitionTreePriors()) { |
| 324 |
|
| 325 |
treePriorGenerator.writeParameterLog(prior, writer); |
| 326 |
} |
| 327 |
|
| 328 |
|
| 329 |
for (PartitionSubstitutionModel model : options.getPartitionSubstitutionModels()) { |
| 330 |
substitutionModelGenerator.writeLog(model, writer); |
| 331 |
} |
| 332 |
|
| 333 |
for (PartitionClockModel model : options.getPartitionClockModels()) { |
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
clockModelGenerator.writeLog(model, writer); |
| 354 |
} |
| 355 |
|
| 356 |
for (PartitionClockModel model : options.getPartitionClockModels()) { |
| 357 |
clockModelGenerator.writeLogStatistic(model, writer); |
| 358 |
} |
| 359 |
|
| 360 |
generateInsertionPoint(ComponentGenerator.InsertionPoint.IN_FILE_LOG_PARAMETERS, writer); |
| 361 |
|
| 362 |
treeLikelihoodGenerator.writeTreeLikelihoodReferences(writer); |
| 363 |
clockModelGenerator.writeClockLikelihoodReferences(writer); |
| 364 |
|
| 365 |
generateInsertionPoint(ComponentGenerator.InsertionPoint.IN_FILE_LOG_LIKELIHOODS, writer); |
| 366 |
|
| 367 |
|
| 368 |
for (PartitionTreeModel model : options.getPartitionTreeModels()) { |
| 369 |
PartitionTreePrior prior = model.getPartitionTreePrior(); |
| 370 |
treePriorGenerator.writePriorLikelihoodReferenceLog(prior, model, writer); |
| 371 |
writer.writeText(""); |
| 372 |
} |
| 373 |
|
| 374 |
for (PartitionTreePrior prior : options.getPartitionTreePriors()) { |
| 375 |
if (prior.getNodeHeightPrior() == TreePriorType.EXTENDED_SKYLINE) { |
| 376 |
writer.writeIDref(CoalescentLikelihoodParser.COALESCENT_LIKELIHOOD, prior.getPrefix() + COALESCENT); |
| 377 |
} else if (prior.getNodeHeightPrior() == TreePriorType.SKYGRID) { |
| 378 |
writer.writeIDref(GMRFSkyrideLikelihoodParser.SKYGRID_LIKELIHOOD, prior.getPrefix() + "skygrid"); |
| 379 |
} |
| 380 |
} |
| 381 |
|
| 382 |
writer.writeCloseTag(LoggerParser.LOG); |
| 383 |
|
| 384 |
generateInsertionPoint(ComponentGenerator.InsertionPoint.AFTER_FILE_LOG, writer); |
| 385 |
|
| 386 |
} |
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
public void writeTreeLogToFile(XMLWriter writer) { |
| 394 |
writer.writeComment("write tree log to file"); |
| 395 |
|
| 396 |
for (PartitionTreeModel tree : options.getPartitionTreeModels()) { |
| 397 |
String treeLogFileName; |
| 398 |
if (options.substTreeLog) { |
| 399 |
treeLogFileName = options.fileNameStem + "." + tree.getPrefix() + "(time).trees"; |
| 400 |
} else { |
| 401 |
treeLogFileName = options.fileNameStem + "." + tree.getPrefix() + "trees"; |
| 402 |
} |
| 403 |
|
| 404 |
if (options.treeFileName.get(0).endsWith(".txt")) { |
| 405 |
treeLogFileName += ".txt"; |
| 406 |
} |
| 407 |
|
| 408 |
writeTreeLogToFile(writer, treeLogFileName, tree); |
| 409 |
} |
| 410 |
|
| 411 |
if (options.substTreeLog) { |
| 412 |
|
| 413 |
for (PartitionTreeModel tree : options.getPartitionTreeModels()) { |
| 414 |
String treeLogFileName = options.fileNameStem + "." + tree.getPrefix() + |
| 415 |
"(subst).trees"; |
| 416 |
if (options.treeFileName.get(0).endsWith(".txt")) { |
| 417 |
treeLogFileName += ".txt"; |
| 418 |
} |
| 419 |
|
| 420 |
writeSubstTreeLogToFile(writer, treeLogFileName, tree); |
| 421 |
} |
| 422 |
} |
| 423 |
|
| 424 |
generateInsertionPoint(ComponentGenerator.InsertionPoint.AFTER_TREES_LOG, writer); |
| 425 |
} |
| 426 |
|
| 427 |
private void writeTreeLogToFile(XMLWriter writer, String treeLogFileName, PartitionTreeModel tree) { |
| 428 |
List<Attribute> attributes = new ArrayList<Attribute>(); |
| 429 |
|
| 430 |
attributes.add(new Attribute.Default<String>(XMLParser.ID, tree.getPrefix() + TREE_FILE_LOG)); |
| 431 |
attributes.add(new Attribute.Default<String>(TreeLoggerParser.LOG_EVERY, options.logEvery + "")); |
| 432 |
attributes.add(new Attribute.Default<String>(TreeLoggerParser.NEXUS_FORMAT, "true")); |
| 433 |
attributes.add(new Attribute.Default<String>(TreeLoggerParser.FILE_NAME, treeLogFileName)); |
| 434 |
attributes.add(new Attribute.Default<String>(TreeLoggerParser.SORT_TRANSLATION_TABLE, "true")); |
| 435 |
|
| 436 |
writer.writeOpenTag(TreeLoggerParser.LOG_TREE, attributes); |
| 437 |
|
| 438 |
writer.writeIDref(TreeModel.TREE_MODEL, tree.getPrefix() + TreeModel.TREE_MODEL); |
| 439 |
|
| 440 |
writeTreeTraits(writer, tree); |
| 441 |
|
| 442 |
if (options.hasData()) { |
| 443 |
|
| 444 |
writer.writeIDref(CompoundLikelihoodParser.JOINT, "joint"); |
| 445 |
} |
| 446 |
|
| 447 |
generateInsertionPoint(ComponentGenerator.InsertionPoint.IN_TREES_LOG, tree, writer); |
| 448 |
|
| 449 |
writer.writeCloseTag(TreeLoggerParser.LOG_TREE); |
| 450 |
} |
| 451 |
|
| 452 |
private void writeSubstTreeLogToFile(XMLWriter writer, String treeLogFileName, PartitionTreeModel tree) { |
| 453 |
|
| 454 |
writer.writeOpenTag(TreeLoggerParser.LOG_TREE, |
| 455 |
new Attribute[]{ |
| 456 |
new Attribute.Default<String>(XMLParser.ID, tree.getPrefix() + SUB_TREE_FILE_LOG), |
| 457 |
new Attribute.Default<String>(TreeLoggerParser.LOG_EVERY, options.logEvery + ""), |
| 458 |
new Attribute.Default<String>(TreeLoggerParser.NEXUS_FORMAT, "true"), |
| 459 |
new Attribute.Default<String>(TreeLoggerParser.FILE_NAME, treeLogFileName), |
| 460 |
new Attribute.Default<String>(TreeLoggerParser.BRANCH_LENGTHS, TreeLoggerParser.SUBSTITUTIONS) |
| 461 |
}); |
| 462 |
writer.writeIDref(TreeModel.TREE_MODEL, tree.getPrefix() + TreeModel.TREE_MODEL); |
| 463 |
|
| 464 |
PartitionClockModel model = options.getPartitionClockModels(options.getDataPartitions(tree)).get(0); |
| 465 |
String tag = ""; |
| 466 |
String id = model.getPrefix() + BranchRateModel.BRANCH_RATES; |
| 467 |
|
| 468 |
switch (model.getClockType()) { |
| 469 |
case STRICT_CLOCK: |
| 470 |
tag = StrictClockBranchRatesParser.STRICT_CLOCK_BRANCH_RATES; |
| 471 |
break; |
| 472 |
|
| 473 |
case UNCORRELATED: |
| 474 |
if (model.performModelAveraging()) { |
| 475 |
tag = MixtureModelBranchRatesParser.MIXTURE_MODEL_BRANCH_RATES; |
| 476 |
} else { |
| 477 |
tag = model.isContinuousQuantile() ? |
| 478 |
ContinuousBranchRatesParser.CONTINUOUS_BRANCH_RATES : |
| 479 |
DiscretizedBranchRatesParser.DISCRETIZED_BRANCH_RATES; |
| 480 |
} |
| 481 |
break; |
| 482 |
|
| 483 |
case RANDOM_LOCAL_CLOCK: |
| 484 |
tag = RandomLocalClockModelParser.LOCAL_BRANCH_RATES; |
| 485 |
break; |
| 486 |
|
| 487 |
case FIXED_LOCAL_CLOCK: |
| 488 |
tag = LocalClockModelParser.LOCAL_CLOCK_MODEL; |
| 489 |
break; |
| 490 |
case AUTOCORRELATED: |
| 491 |
tag = ACLikelihoodParser.AC_LIKELIHOOD; |
| 492 |
break; |
| 493 |
|
| 494 |
default: |
| 495 |
throw new IllegalArgumentException("Unknown clock model"); |
| 496 |
} |
| 497 |
writer.writeIDref(tag, id); |
| 498 |
writeTreeTrait(writer, tag, id, BranchRateModel.RATE, model.getPrefix() + BranchRateModel.RATE); |
| 499 |
|
| 500 |
writer.writeCloseTag(TreeLoggerParser.LOG_TREE); |
| 501 |
} |
| 502 |
|
| 503 |
|
| 504 |
private void writeTreeTraits(XMLWriter writer, PartitionTreeModel tree) { |
| 505 |
for (PartitionClockModel model : options.getPartitionClockModels(options.getDataPartitions(tree))) { |
| 506 |
|
| 507 |
String prefix = model.getPrefix(); |
| 508 |
|
| 509 |
switch (model.getClockType()) { |
| 510 |
case STRICT_CLOCK: |
| 511 |
writeTreeTrait(writer, StrictClockBranchRatesParser.STRICT_CLOCK_BRANCH_RATES, |
| 512 |
prefix + BranchRateModel.BRANCH_RATES, |
| 513 |
BranchRateModel.RATE, prefix + BranchRateModel.RATE); |
| 514 |
break; |
| 515 |
|
| 516 |
case UNCORRELATED: |
| 517 |
writeTreeTrait(writer, model.performModelAveraging() ? MixtureModelBranchRatesParser.MIXTURE_MODEL_BRANCH_RATES : model.isContinuousQuantile() ? |
| 518 |
ContinuousBranchRatesParser.CONTINUOUS_BRANCH_RATES : |
| 519 |
DiscretizedBranchRatesParser.DISCRETIZED_BRANCH_RATES, |
| 520 |
prefix + BranchRateModel.BRANCH_RATES, |
| 521 |
BranchRateModel.RATE, prefix + BranchRateModel.RATE); |
| 522 |
break; |
| 523 |
|
| 524 |
case RANDOM_LOCAL_CLOCK: |
| 525 |
writeTreeTrait(writer, RandomLocalClockModelParser.LOCAL_BRANCH_RATES, |
| 526 |
prefix + BranchRateModel.BRANCH_RATES, |
| 527 |
BranchRateModel.RATE, prefix + BranchRateModel.RATE); |
| 528 |
break; |
| 529 |
|
| 530 |
case FIXED_LOCAL_CLOCK: |
| 531 |
writeTreeTrait(writer, LocalClockModelParser.LOCAL_CLOCK_MODEL, |
| 532 |
prefix + BranchRateModel.BRANCH_RATES, |
| 533 |
BranchRateModel.RATE, prefix + BranchRateModel.RATE); |
| 534 |
break; |
| 535 |
|
| 536 |
case AUTOCORRELATED: |
| 537 |
writer.writeIDref(ACLikelihoodParser.AC_LIKELIHOOD, |
| 538 |
prefix + BranchRateModel.BRANCH_RATES); |
| 539 |
writeTreeTrait(writer, ACLikelihoodParser.AC_LIKELIHOOD, |
| 540 |
prefix + BranchRateModel.BRANCH_RATES, |
| 541 |
BranchRateModel.RATE, model.getPrefix() + BranchRateModel.RATE); |
| 542 |
break; |
| 543 |
|
| 544 |
default: |
| 545 |
throw new IllegalArgumentException("Unknown clock model"); |
| 546 |
} |
| 547 |
} |
| 548 |
} |
| 549 |
|
| 550 |
private void writeTreeTrait(XMLWriter writer, String treeTraitTag, String treeTraitID, String traitName, String traitTag) { |
| 551 |
|
| 552 |
writer.writeOpenTag(TreeLoggerParser.TREE_TRAIT, |
| 553 |
new Attribute[]{ |
| 554 |
new Attribute.Default<String>(TreeLoggerParser.NAME, traitName), |
| 555 |
new Attribute.Default<String>(TreeLoggerParser.TAG, traitTag) |
| 556 |
}); |
| 557 |
writer.writeIDref(treeTraitTag, treeTraitID); |
| 558 |
|
| 559 |
writer.writeCloseTag(TreeLoggerParser.TREE_TRAIT); |
| 560 |
|
| 561 |
} |
| 562 |
} |