| 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.AbstractPartitionData; |
| 30 |
import dr.app.beauti.options.BeautiOptions; |
| 31 |
import dr.app.beauti.options.PartitionTreeModel; |
| 32 |
import dr.app.beauti.util.XMLWriter; |
| 33 |
import dr.evolution.datatype.DataType; |
| 34 |
import dr.evomodel.tree.TMRCAStatistic; |
| 35 |
import dr.evomodel.tree.TreeModel; |
| 36 |
import dr.evomodelxml.coalescent.OldCoalescentSimulatorParser; |
| 37 |
import dr.evomodelxml.tree.MicrosatelliteSamplerTreeModelParser; |
| 38 |
import dr.evomodelxml.tree.TMRCAStatisticParser; |
| 39 |
import dr.evomodelxml.tree.TreeLengthStatisticParser; |
| 40 |
import dr.evomodelxml.tree.TreeModelParser; |
| 41 |
import dr.evoxml.MicrosatellitePatternParser; |
| 42 |
import dr.evoxml.UPGMATreeParser; |
| 43 |
import dr.inference.model.ParameterParser; |
| 44 |
import dr.util.Attribute; |
| 45 |
import dr.xml.XMLParser; |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
public class TreeModelGenerator extends Generator { |
| 53 |
|
| 54 |
public TreeModelGenerator(BeautiOptions options, ComponentFactory[] components) { |
| 55 |
super(options, components); |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
void writeTreeModel(PartitionTreeModel model, XMLWriter writer) { |
| 65 |
|
| 66 |
String prefix = model.getPrefix(); |
| 67 |
|
| 68 |
final String treeModelName = prefix + TreeModel.TREE_MODEL; |
| 69 |
|
| 70 |
writer.writeComment("Generate a tree model"); |
| 71 |
writer.writeTag(TreeModel.TREE_MODEL, new Attribute.Default<String>(XMLParser.ID, treeModelName), false); |
| 72 |
|
| 73 |
final String STARTING_TREE = InitialTreeGenerator.STARTING_TREE; |
| 74 |
|
| 75 |
switch (model.getStartingTreeType()) { |
| 76 |
case USER: |
| 77 |
writer.writeIDref("tree", prefix + STARTING_TREE); |
| 78 |
break; |
| 79 |
case UPGMA: |
| 80 |
writer.writeIDref(UPGMATreeParser.UPGMA_TREE, prefix + STARTING_TREE); |
| 81 |
break; |
| 82 |
case RANDOM: |
| 83 |
writer.writeIDref(OldCoalescentSimulatorParser.COALESCENT_TREE, prefix + STARTING_TREE); |
| 84 |
break; |
| 85 |
default: |
| 86 |
throw new IllegalArgumentException("Unknown StartingTreeType"); |
| 87 |
} |
| 88 |
|
| 89 |
writer.writeOpenTag(TreeModelParser.ROOT_HEIGHT); |
| 90 |
writer.writeTag(ParameterParser.PARAMETER, |
| 91 |
new Attribute.Default<String>(XMLParser.ID, treeModelName + "." + TreeModelParser.ROOT_HEIGHT), true); |
| 92 |
writer.writeCloseTag(TreeModelParser.ROOT_HEIGHT); |
| 93 |
|
| 94 |
|
| 95 |
writer.writeOpenTag(TreeModelParser.NODE_HEIGHTS, new Attribute.Default<String>(TreeModelParser.INTERNAL_NODES, "true")); |
| 96 |
writer.writeTag(ParameterParser.PARAMETER, |
| 97 |
new Attribute.Default<String>(XMLParser.ID, treeModelName + "." + "internalNodeHeights"), true); |
| 98 |
writer.writeCloseTag(TreeModelParser.NODE_HEIGHTS); |
| 99 |
|
| 100 |
writer.writeOpenTag(TreeModelParser.NODE_HEIGHTS, |
| 101 |
new Attribute[]{ |
| 102 |
new Attribute.Default<String>(TreeModelParser.INTERNAL_NODES, "true"), |
| 103 |
new Attribute.Default<String>(TreeModelParser.ROOT_NODE, "true") |
| 104 |
}); |
| 105 |
writer.writeTag(ParameterParser.PARAMETER, |
| 106 |
new Attribute.Default<String>(XMLParser.ID, treeModelName + "." + "allInternalNodeHeights"), true); |
| 107 |
writer.writeCloseTag(TreeModelParser.NODE_HEIGHTS); |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
generateInsertionPoint(ComponentGenerator.InsertionPoint.IN_TREE_MODEL, model, writer); |
| 175 |
|
| 176 |
writer.writeCloseTag(TreeModel.TREE_MODEL); |
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
writer.writeComment("Statistic for sum of the branch lengths of the tree (tree length)"); |
| 189 |
writer.writeTag(TreeLengthStatisticParser.TREE_LENGTH_STATISTIC, |
| 190 |
new Attribute[]{ |
| 191 |
new Attribute.Default<String>(XMLParser.ID, prefix + "treeLength"), |
| 192 |
}, false); |
| 193 |
writer.writeIDref(TreeModel.TREE_MODEL, treeModelName); |
| 194 |
writer.writeCloseTag(TreeLengthStatisticParser.TREE_LENGTH_STATISTIC); |
| 195 |
|
| 196 |
if (model.hasTipCalibrations()) { |
| 197 |
writer.writeComment("Statistic for time of most recent common ancestor of tree"); |
| 198 |
writer.writeTag(TMRCAStatisticParser.TMRCA_STATISTIC, |
| 199 |
new Attribute[]{ |
| 200 |
new Attribute.Default<String>(XMLParser.ID, prefix + "age(root)"), |
| 201 |
new Attribute.Default<String>(TMRCAStatisticParser.ABSOLUTE, "true") |
| 202 |
}, false); |
| 203 |
writer.writeIDref(TreeModel.TREE_MODEL, treeModelName); |
| 204 |
writer.writeCloseTag(TMRCAStatisticParser.TMRCA_STATISTIC); |
| 205 |
} |
| 206 |
|
| 207 |
if (model.getDataType().getType() == DataType.MICRO_SAT) { |
| 208 |
for (AbstractPartitionData partitionData : options.getDataPartitions(model)) { |
| 209 |
writer.writeComment("Generate a microsatellite tree model"); |
| 210 |
writer.writeTag(MicrosatelliteSamplerTreeModelParser.TREE_MICROSATELLITE_SAMPLER_MODEL, |
| 211 |
new Attribute.Default<String>(XMLParser.ID, partitionData.getName() + "." + |
| 212 |
MicrosatelliteSamplerTreeModelParser.TREE_MICROSATELLITE_SAMPLER_MODEL), false); |
| 213 |
|
| 214 |
writer.writeOpenTag(MicrosatelliteSamplerTreeModelParser.TREE); |
| 215 |
writer.writeIDref(TreeModel.TREE_MODEL, treeModelName); |
| 216 |
writer.writeCloseTag(MicrosatelliteSamplerTreeModelParser.TREE); |
| 217 |
|
| 218 |
writer.writeOpenTag(MicrosatelliteSamplerTreeModelParser.INTERNAL_VALUES); |
| 219 |
writer.writeTag(ParameterParser.PARAMETER, new Attribute[]{ |
| 220 |
new Attribute.Default<String>(XMLParser.ID, partitionData.getName() + "." + |
| 221 |
MicrosatelliteSamplerTreeModelParser.TREE_MICROSATELLITE_SAMPLER_MODEL + ".internalNodesParameter"), |
| 222 |
new Attribute.Default<Integer>(ParameterParser.DIMENSION, model.getDimension())}, true); |
| 223 |
writer.writeCloseTag(MicrosatelliteSamplerTreeModelParser.INTERNAL_VALUES); |
| 224 |
|
| 225 |
writer.writeOpenTag(MicrosatelliteSamplerTreeModelParser.EXTERNAL_VALUES); |
| 226 |
|
| 227 |
writer.writeIDref(MicrosatellitePatternParser.MICROSATPATTERN, partitionData.getName()); |
| 228 |
|
| 229 |
writer.writeCloseTag(MicrosatelliteSamplerTreeModelParser.EXTERNAL_VALUES); |
| 230 |
|
| 231 |
writer.writeCloseTag(MicrosatelliteSamplerTreeModelParser.TREE_MICROSATELLITE_SAMPLER_MODEL); |
| 232 |
} |
| 233 |
} |
| 234 |
} |
| 235 |
} |