Debian Codegraph @

src/dr/oldevomodelxml/substmodel/TwoStateCovarionModelParser.java

raw symbols SCIP
1 /*
2 * TwoStateCovarionModelParser.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.oldevomodelxml.substmodel;
27
28 import dr.evolution.datatype.TwoStateCovarion;
29 import dr.oldevomodel.substmodel.AbstractCovarionDNAModel;
30 import dr.oldevomodel.substmodel.FrequencyModel;
31 import dr.oldevomodel.substmodel.TwoStateCovarionModel;
32 import dr.inference.model.Parameter;
33 import dr.xml.*;
34
35 /**
36 * Parses an element from an DOM document into a TwoStateCovarionModel
37 */
38 public class TwoStateCovarionModelParser extends AbstractXMLObjectParser {
39 public static final String COVARION_MODEL = "covarionModel";
40 public static final String ALPHA = "alpha";
41 public static final String SWITCHING_RATE = "switchingRate";
42
43 public String getParserName() {
44 return COVARION_MODEL;
45 }
46
47 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
48
49 Parameter alphaParameter;
50 Parameter switchingRateParameter;
51
52 XMLObject cxo = xo.getChild(AbstractCovarionDNAModel.FREQUENCIES);
53 FrequencyModel freqModel = (FrequencyModel) cxo.getChild(FrequencyModel.class);
54
55 TwoStateCovarion dataType = TwoStateCovarion.INSTANCE; // fancy new datatype courtesy of Helen
56
57 cxo = xo.getChild(ALPHA);
58 alphaParameter = (Parameter) cxo.getChild(Parameter.class);
59
60 // alpha must be positive and less than 1.0 because the fast rate is normalized to 1.0
61 alphaParameter.addBounds(new Parameter.DefaultBounds(1.0, 0.0, 1));
62
63 cxo = xo.getChild(SWITCHING_RATE);
64 switchingRateParameter = (Parameter) cxo.getChild(Parameter.class);
65
66 if (dataType != freqModel.getDataType()) {
67 throw new XMLParseException("Data type of " + getParserName() + " element does not match that of its frequencyModel.");
68 }
69
70 TwoStateCovarionModel model = new TwoStateCovarionModel(dataType, freqModel, alphaParameter, switchingRateParameter);
71
72 System.out.println(model);
73
74 return model;
75 }
76
77 //************************************************************************
78 // AbstractXMLObjectParser implementation
79 //************************************************************************
80
81 public String getParserDescription() {
82 return "A covarion substitution model on binary data and a hidden rate state with two rates.";
83 }
84
85 public Class getReturnType() {
86 return TwoStateCovarionModel.class;
87 }
88
89 public XMLSyntaxRule[] getSyntaxRules() {
90 return rules;
91 }
92
93 private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{
94 new ElementRule(AbstractCovarionDNAModel.FREQUENCIES, FrequencyModel.class),
95 new ElementRule(ALPHA, new XMLSyntaxRule[]{
96 new ElementRule(Parameter.class, true)}
97 ),
98 new ElementRule(SWITCHING_RATE, new XMLSyntaxRule[]{
99 new ElementRule(Parameter.class, true)}
100 ),
101 };
102 }