Debian Codegraph @

src/dr/oldevomodelxml/substmodel/AsymQuadModelParser.java

raw symbols SCIP
1 /*
2 * AsymQuadModelParser.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.Microsatellite;
29 import dr.oldevomodel.substmodel.AsymmetricQuadraticModel;
30 import dr.oldevomodel.substmodel.FrequencyModel;
31 import dr.inference.model.Parameter;
32 import dr.xml.*;
33
34 /**
35 * @author Chieh-Hsi Wu
36 *
37 * Parser for Asymmetric Quadratic Model
38 */
39 public class AsymQuadModelParser extends AbstractXMLObjectParser{
40
41 public static final String EXPANSION_CONSTANT = "ExpansionConstant";
42 public static final String CONTRACTION_CONSTANT = "ContractionConstant";
43 public static final String EXPANSION_LIN = "ExpansionLinear";
44 public static final String CONTRACTION_LIN = "ContractionLinear";
45 public static final String EXPANSION_QUAD = "ExpansionQuad";
46 public static final String CONTRACTION_QUAD = "ContractionQuad";
47 public static final String IS_SUBMODEL = "isSubmodel";
48
49 public String getParserName() {
50 return AsymmetricQuadraticModel.ASYMQUAD_MODEL;
51 }
52
53
54 //AbstractXMLObjectParser implementation
55 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
56
57 Microsatellite microsatellite = (Microsatellite) xo.getChild(Microsatellite.class);
58
59 Parameter expanConst = processModelParameter(xo, EXPANSION_CONSTANT);
60
61 Parameter expanLin = processModelParameter(xo, EXPANSION_LIN);
62
63 Parameter expanQuad = processModelParameter(xo, EXPANSION_QUAD);
64
65 Parameter contractConst = processModelParameter(xo, CONTRACTION_CONSTANT);
66
67 Parameter contractLin = processModelParameter(xo, CONTRACTION_LIN);
68
69 Parameter contractQuad = processModelParameter(xo, CONTRACTION_QUAD);
70
71 //get FrequencyModel
72 FrequencyModel freqModel = null;
73 if(xo.hasChildNamed(FrequencyModelParser.FREQUENCIES)){
74 freqModel = (FrequencyModel)xo.getElementFirstChild(FrequencyModelParser.FREQUENCIES);
75 }
76
77 boolean isSubmodel = xo.getAttribute(IS_SUBMODEL, false);
78
79 return new AsymmetricQuadraticModel(
80 microsatellite,
81 freqModel,
82 expanConst,
83 expanLin,
84 expanQuad,
85 contractConst,
86 contractLin,
87 contractQuad,
88 isSubmodel
89 );
90 }
91
92 private Parameter processModelParameter(XMLObject xo,
93 String parameterName)throws XMLParseException{
94 Parameter param = null;
95 if(xo.hasChildNamed(parameterName)){
96 XMLObject paramXO = xo.getChild(parameterName);
97 param =(Parameter) paramXO.getChild(Parameter.class);
98 }
99 return param;
100 }
101
102 public String getParserDescription() {
103 return "This element represents an instance of the stepwise mutation model of microsatellite evolution.";
104 }
105
106 public XMLSyntaxRule[] getSyntaxRules() {
107 return rules;
108 }
109
110 private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{
111 new ElementRule(Microsatellite.class),
112 new ElementRule(FrequencyModel.class,true),
113 new ElementRule(EXPANSION_CONSTANT,new XMLSyntaxRule[]{new ElementRule(Parameter.class)},true),
114 new ElementRule(CONTRACTION_CONSTANT,new XMLSyntaxRule[]{new ElementRule(Parameter.class)},true),
115 new ElementRule(EXPANSION_LIN,new XMLSyntaxRule[]{new ElementRule(Parameter.class)},true),
116 new ElementRule(CONTRACTION_LIN,new XMLSyntaxRule[]{new ElementRule(Parameter.class)},true),
117 new ElementRule(EXPANSION_QUAD,new XMLSyntaxRule[]{new ElementRule(Parameter.class)},true),
118 new ElementRule(CONTRACTION_QUAD,new XMLSyntaxRule[]{new ElementRule(Parameter.class)},true),
119 AttributeRule.newBooleanRule(IS_SUBMODEL,true)
120 };
121
122 public Class getReturnType() {
123 return AsymmetricQuadraticModel.class;
124 }
125
126 public static boolean requirePattern(){
127 return true;
128 }
129 }
130