Debian Codegraph @

src/dr/evomodelxml/treelikelihood/AncestralStateTreeLikelihoodParser.java

raw symbols SCIP
1 /*
2 * AncestralStateTreeLikelihoodParser.java
3 *
4 * Copyright (c) 2002-2016 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.evomodelxml.treelikelihood;
27
28 import dr.evomodel.branchmodel.BranchModel;
29 import dr.evomodel.siteratemodel.GammaSiteRateModel;
30 import dr.evomodel.substmodel.FrequencyModel;
31 import dr.evomodel.substmodel.SubstitutionModel;
32 import dr.evomodel.treelikelihood.AncestralStateBeagleTreeLikelihood;
33 import dr.evomodel.treelikelihood.BeagleTreeLikelihood;
34 import dr.evomodel.treelikelihood.PartialsRescalingScheme;
35 import dr.evolution.alignment.PatternList;
36 import dr.evolution.datatype.DataType;
37 import dr.evolution.util.TaxonList;
38 import dr.evomodel.branchratemodel.BranchRateModel;
39 import dr.evomodel.tree.TreeModel;
40 import dr.oldevomodel.treelikelihood.AncestralStateTreeLikelihood;
41 import dr.evomodel.tipstatesmodel.TipStatesModel;
42 import dr.inference.model.Parameter;
43 import dr.xml.*;
44
45 import java.util.Map;
46 import java.util.Set;
47
48 /**
49 * @author Marc Suchard
50 * @author Andrew Rambaut
51 */
52
53 public class AncestralStateTreeLikelihoodParser extends BeagleTreeLikelihoodParser {
54
55 public static final String RECONSTRUCTING_TREE_LIKELIHOOD = "ancestralTreeLikelihood";
56 public static final String RECONSTRUCTION_TAG = AncestralStateTreeLikelihood.STATES_KEY;
57 public static final String RECONSTRUCTION_TAG_NAME = "stateTagName";
58 public static final String MAP_RECONSTRUCTION = "useMAP";
59 public static final String MARGINAL_LIKELIHOOD = "useMarginalLikelihood";
60
61 public String getParserName() {
62 return RECONSTRUCTING_TREE_LIKELIHOOD;
63 }
64
65 protected BeagleTreeLikelihood createTreeLikelihood(
66 PatternList patternList, //
67 TreeModel treeModel, //
68 BranchModel branchModel, //
69 GammaSiteRateModel siteRateModel, //
70 BranchRateModel branchRateModel, //
71 TipStatesModel tipStatesModel, //
72 boolean useAmbiguities, //
73 PartialsRescalingScheme scalingScheme, //
74 boolean delayScaling,
75 Map<Set<String>, //
76 Parameter> partialsRestrictions, //
77 XMLObject xo //
78 ) throws XMLParseException {
79
80
81 // System.err.println("XML object: " + xo.toString());
82
83 DataType dataType = branchModel.getRootSubstitutionModel().getDataType();
84
85 // default tag is RECONSTRUCTION_TAG
86 String tag = xo.getAttribute(RECONSTRUCTION_TAG_NAME, RECONSTRUCTION_TAG);
87
88 boolean useMAP = xo.getAttribute(MAP_RECONSTRUCTION, false);
89 boolean useMarginalLogLikelihood = xo.getAttribute(MARGINAL_LIKELIHOOD, true);
90
91 if (patternList.areUnique()) {
92 throw new XMLParseException("Ancestral state reconstruction cannot be used with compressed (unique) patterns.");
93 }
94
95 return new AncestralStateBeagleTreeLikelihood( // Current just returns a OldBeagleTreeLikelihood
96 patternList,
97 treeModel,
98 branchModel,
99 siteRateModel,
100 branchRateModel,
101 tipStatesModel,
102 useAmbiguities,
103 scalingScheme,
104 delayScaling,
105 partialsRestrictions,
106 dataType,
107 tag,
108 useMAP,
109 useMarginalLogLikelihood
110 );
111 }
112
113 public XMLSyntaxRule[] getSyntaxRules() {
114 return new XMLSyntaxRule[] {
115 AttributeRule.newBooleanRule(BeagleTreeLikelihoodParser.USE_AMBIGUITIES, true),
116 AttributeRule.newStringRule(RECONSTRUCTION_TAG_NAME, true),
117 new ElementRule(PatternList.class),
118 new ElementRule(TreeModel.class),
119 new ElementRule(GammaSiteRateModel.class),
120 new ElementRule(BranchModel.class, true),
121 new ElementRule(BranchRateModel.class, true),
122 new ElementRule(TipStatesModel.class, true),
123 new ElementRule(SubstitutionModel.class, true),
124 AttributeRule.newStringRule(BeagleTreeLikelihoodParser.SCALING_SCHEME,true),
125 AttributeRule.newStringRule(BeagleTreeLikelihoodParser.DELAY_SCALING,true),
126 new ElementRule(PARTIALS_RESTRICTION, new XMLSyntaxRule[] {
127 new ElementRule(TaxonList.class),
128 new ElementRule(Parameter.class),
129 }, true),
130 new ElementRule(FrequencyModel.class, true),
131 };
132 }
133 }