| 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.BeautiOptions; |
| 30 |
import dr.app.beauti.options.PartitionTreeModel; |
| 31 |
import dr.app.beauti.util.XMLWriter; |
| 32 |
import dr.evolution.util.Taxa; |
| 33 |
import dr.evomodel.tree.TreeModel; |
| 34 |
import dr.evomodelxml.speciation.SpeciesTreeModelParser; |
| 35 |
import dr.evomodelxml.tree.MonophylyStatisticParser; |
| 36 |
import dr.evomodelxml.tree.TMRCAStatisticParser; |
| 37 |
import dr.evoxml.TaxaParser; |
| 38 |
import dr.evoxml.TaxonParser; |
| 39 |
import dr.util.Attribute; |
| 40 |
import dr.xml.XMLParser; |
| 41 |
|
| 42 |
import java.util.List; |
| 43 |
import java.util.Map; |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
public class TMRCAStatisticsGenerator extends Generator { |
| 52 |
|
| 53 |
|
| 54 |
public TMRCAStatisticsGenerator(BeautiOptions options, ComponentFactory[] components) { |
| 55 |
super(options, components); |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
public void writeTaxonSets(XMLWriter writer, List<Taxa> taxonSets) { |
| 65 |
writer.writeText(""); |
| 66 |
|
| 67 |
for (Taxa taxa : taxonSets) { |
| 68 |
writer.writeOpenTag( |
| 69 |
TaxaParser.TAXA, |
| 70 |
new Attribute[]{ |
| 71 |
new Attribute.Default<String>(XMLParser.ID, taxa.getId()) |
| 72 |
} |
| 73 |
); |
| 74 |
|
| 75 |
for (int j = 0; j < taxa.getTaxonCount(); j++) { |
| 76 |
writer.writeIDref(TaxonParser.TAXON, taxa.getTaxon(j).getId()); |
| 77 |
} |
| 78 |
writer.writeCloseTag(TaxaParser.TAXA); |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
public void writeTMRCAStatistics(XMLWriter writer) { |
| 88 |
List<Taxa> taxonSets; |
| 89 |
Map<Taxa, Boolean> taxonSetsMono; |
| 90 |
|
| 91 |
taxonSets = options.taxonSets; |
| 92 |
taxonSetsMono = options.taxonSetsMono; |
| 93 |
|
| 94 |
writer.writeComment("Taxon Sets"); |
| 95 |
writer.writeText(""); |
| 96 |
for (Taxa taxa : taxonSets) { |
| 97 |
PartitionTreeModel treeModel = options.taxonSetsTreeModel.get(taxa); |
| 98 |
String id = "tmrca(" + treeModel.getPrefix() + taxa.getId() + ")"; |
| 99 |
writeTMRCAStatistic(writer, id, taxa, treeModel, false, options.taxonSetsIncludeStem.get(taxa)); |
| 100 |
|
| 101 |
if (treeModel.hasTipCalibrations()) { |
| 102 |
id = "age(" + treeModel.getPrefix() + taxa.getId() + ")"; |
| 103 |
writeTMRCAStatistic(writer, id, taxa, treeModel, true, options.taxonSetsIncludeStem.get(taxa)); |
| 104 |
} |
| 105 |
|
| 106 |
if (taxonSetsMono.get(taxa)) { |
| 107 |
|
| 108 |
|
| 109 |
writer.writeOpenTag( |
| 110 |
MonophylyStatisticParser.MONOPHYLY_STATISTIC, |
| 111 |
new Attribute[]{ |
| 112 |
new Attribute.Default<String>(XMLParser.ID, "monophyly(" + taxa.getId() + ")"), |
| 113 |
}); |
| 114 |
writer.writeOpenTag(MonophylyStatisticParser.MRCA); |
| 115 |
writer.writeIDref(TaxaParser.TAXA, taxa.getId()); |
| 116 |
writer.writeCloseTag(MonophylyStatisticParser.MRCA); |
| 117 |
writer.writeIDref(TreeModel.TREE_MODEL, treeModel.getPrefix() + TreeModel.TREE_MODEL); |
| 118 |
writer.writeCloseTag(MonophylyStatisticParser.MONOPHYLY_STATISTIC); |
| 119 |
} |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
private void writeTMRCAStatistic(XMLWriter writer, String id, Taxa taxa, PartitionTreeModel treeModel, boolean isAbsolute, boolean includeStem) { |
| 124 |
writer.writeOpenTag(TMRCAStatisticParser.TMRCA_STATISTIC, |
| 125 |
new Attribute[]{ |
| 126 |
new Attribute.Default<String>(XMLParser.ID, id), |
| 127 |
new Attribute.Default<Boolean>(TMRCAStatisticParser.ABSOLUTE, isAbsolute), |
| 128 |
new Attribute.Default<Boolean>(TMRCAStatisticParser.STEM, includeStem), |
| 129 |
} |
| 130 |
); |
| 131 |
writer.writeOpenTag(TMRCAStatisticParser.MRCA); |
| 132 |
writer.writeIDref(TaxaParser.TAXA, taxa.getId()); |
| 133 |
writer.writeCloseTag(TMRCAStatisticParser.MRCA); |
| 134 |
writer.writeIDref(TreeModel.TREE_MODEL, treeModel.getPrefix() + TreeModel.TREE_MODEL); |
| 135 |
writer.writeCloseTag(TMRCAStatisticParser.TMRCA_STATISTIC); |
| 136 |
} |
| 137 |
|
| 138 |
public void writeTMRCAStatisticReferences(XMLWriter writer) { |
| 139 |
for (Taxa taxa : options.taxonSets) { |
| 140 |
|
| 141 |
PartitionTreeModel treeModel = options.taxonSetsTreeModel.get(taxa); |
| 142 |
writer.writeIDref(TMRCAStatisticParser.TMRCA_STATISTIC, "tmrca(" + treeModel.getPrefix() + taxa.getId() + ")"); |
| 143 |
|
| 144 |
} |
| 145 |
for (Taxa taxa : options.taxonSets) { |
| 146 |
|
| 147 |
PartitionTreeModel treeModel = options.taxonSetsTreeModel.get(taxa); |
| 148 |
if (treeModel.hasTipCalibrations()) { |
| 149 |
writer.writeIDref(TMRCAStatisticParser.TMRCA_STATISTIC, "age(" + treeModel.getPrefix() + taxa.getId() + ")"); |
| 150 |
} |
| 151 |
} |
| 152 |
} |
| 153 |
|
| 154 |
} |