Debian Codegraph @

src/dr/evomodelxml/substmodel/BinaryCovarionModelParser.java

raw symbols SCIP
1 /*
2 * BinaryCovarionModelParser.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.substmodel;
27
28 import dr.evomodel.substmodel.BinaryCovarionModel;
29 import dr.evolution.datatype.TwoStateCovarion;
30 import dr.inference.model.Parameter;
31 import dr.xml.*;
32
33 /**
34 * Parses an element from an DOM document into a TwoStateCovarionModel
35 */
36 public class BinaryCovarionModelParser extends AbstractXMLObjectParser {
37 public static final String COVARION_MODEL = dr.oldevomodelxml.substmodel.BinaryCovarionModelParser.COVARION_MODEL;
38 public static final String ALPHA = dr.oldevomodelxml.substmodel.BinaryCovarionModelParser.ALPHA;
39 public static final String SWITCHING_RATE = dr.oldevomodelxml.substmodel.BinaryCovarionModelParser.SWITCHING_RATE;
40 public static final String FREQUENCIES = dr.oldevomodelxml.substmodel.BinaryCovarionModelParser.FREQUENCIES;
41 public static final String HIDDEN_FREQUENCIES = dr.oldevomodelxml.substmodel.BinaryCovarionModelParser.HIDDEN_FREQUENCIES;
42 public static final String VERSION = dr.oldevomodelxml.substmodel.BinaryCovarionModelParser.VERSION;
43 public static final dr.oldevomodel.substmodel.BinaryCovarionModel.Version DEFAULT_VERSION =
44 dr.oldevomodelxml.substmodel.BinaryCovarionModelParser.DEFAULT_VERSION;
45
46 public String getParserName() {
47 return COVARION_MODEL;
48 }
49
50 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
51
52 Parameter alphaParameter;
53 Parameter switchingRateParameter;
54
55 XMLObject cxo = xo.getChild(FREQUENCIES);
56 Parameter frequencies = (Parameter) cxo.getChild(Parameter.class);
57
58 cxo = xo.getChild(HIDDEN_FREQUENCIES);
59 Parameter hiddenFrequencies = (Parameter) cxo.getChild(Parameter.class);
60
61 cxo = xo.getChild(ALPHA);
62 alphaParameter = (Parameter) cxo.getChild(Parameter.class);
63
64 // alpha must be positive and less than 1.0 because the fast rate is normalized to 1.0
65 alphaParameter.addBounds(new Parameter.DefaultBounds(1.0, 0.0, 1));
66 hiddenFrequencies.addBounds(new Parameter.DefaultBounds(1.0, 0.0, hiddenFrequencies.getDimension()));
67 frequencies.addBounds(new Parameter.DefaultBounds(1.0, 0.0, frequencies.getDimension()));
68
69 cxo = xo.getChild(SWITCHING_RATE);
70 switchingRateParameter = (Parameter) cxo.getChild(Parameter.class);
71
72 dr.oldevomodel.substmodel.BinaryCovarionModel.Version version = DEFAULT_VERSION;
73 if (xo.hasAttribute(VERSION)) {
74 version = dr.oldevomodel.substmodel.BinaryCovarionModel.Version.parseFromString(xo.getStringAttribute(VERSION));
75 }
76
77 BinaryCovarionModel model = new BinaryCovarionModel(TwoStateCovarion.INSTANCE,
78 frequencies, hiddenFrequencies, alphaParameter, switchingRateParameter, version);
79
80 System.out.println(model);
81
82 return model;
83 }
84
85 //************************************************************************
86 // AbstractXMLObjectParser implementation
87 //************************************************************************
88
89 public String getParserDescription() {
90 return "A covarion substitution model on binary data and a hidden rate state with two rates.";
91 }
92
93 public Class getReturnType() {
94 return BinaryCovarionModel.class;
95 }
96
97 public XMLSyntaxRule[] getSyntaxRules() {
98 return rules;
99 }
100
101 private final XMLSyntaxRule[] rules = {
102 new ElementRule(FREQUENCIES, Parameter.class),
103 new ElementRule(HIDDEN_FREQUENCIES, Parameter.class),
104 new ElementRule(ALPHA,
105 new XMLSyntaxRule[]{
106 new ElementRule(Parameter.class, true)}
107 ),
108 new ElementRule(SWITCHING_RATE,
109 new XMLSyntaxRule[]{
110 new ElementRule(Parameter.class, true)}
111 ),
112 AttributeRule.newStringRule(VERSION, true),
113 };
114
115
116 }