Debian Codegraph @

src/dr/app/beauti/generator/TMRCAStatisticsGenerator.java

raw symbols SCIP
1 /*
2 * TMRCAStatisticsGenerator.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
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 * @author Alexei Drummond
48 * @author Andrew Rambaut
49 * @author Walter Xie
50 */
51 public class TMRCAStatisticsGenerator extends Generator {
52
53
54 public TMRCAStatisticsGenerator(BeautiOptions options, ComponentFactory[] components) {
55 super(options, components);
56 }
57
58 /**
59 * Generate additional taxon sets
60 *
61 * @param writer the writer
62 * @param taxonSets a list of taxa to write
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 * Generate tmrca statistics
84 *
85 * @param writer the writer
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 // && treeModel.getPartitionTreePrior().getNodeHeightPrior() != TreePriorType.YULE
108 // && options.getKeysFromValue(options.taxonSetsTreeModel, treeModel).size() > 1) {
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 ); // make tmrca(tree.name) eay to read in log for Tracer
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 // make tmrca(tree.name) eay to read in log for Tracer
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 // make tmrca(tree.name) eay to read in log for Tracer
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 }