Debian Codegraph @

src/dr/oldevomodelxml/substmodel/LinearBiasModelParser.java

raw symbols SCIP
1 /*
2 * LinearBiasModelParser.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.FrequencyModel;
30 import dr.oldevomodel.substmodel.LinearBiasModel;
31 import dr.oldevomodel.substmodel.OnePhaseModel;
32 import dr.inference.model.Parameter;
33 import dr.xml.*;
34 /**
35 * @author Chieh-Hsi Wu
36 *
37 * Parser for LinearBiasModel of Microsatellite.
38 */
39 public class LinearBiasModelParser extends AbstractXMLObjectParser {
40 public static final String SUBMODEL = "Submodel";
41 public static final String BIAS_CONSTANT = "BiasConstant";
42 public static final String BIAS_LINEAR = "BiasLinear";
43 public static final String ESTIMATE_SUBMODEL_PARAMS = "estimateSubmodelParameters";
44 public static final String LOGISTICS = "logistics";
45 public static final String IS_SUBMODEL = "isSubmodel";
46
47
48 public String getParserName() {
49 return LinearBiasModel.LINEAR_BIAS_MODEL;
50 }
51
52
53 //AbstractXMLObjectParser implementation
54 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
55 OnePhaseModel subModel = (OnePhaseModel) xo.getElementFirstChild(SUBMODEL);
56 Microsatellite dataType = (Microsatellite)subModel.getDataType();
57
58 Parameter biasConst = null;
59 if(xo.hasChildNamed(BIAS_CONSTANT)){
60 biasConst =(Parameter) xo.getElementFirstChild(BIAS_CONSTANT);
61 }
62
63 Parameter biasLin = null;
64 if(xo.hasChildNamed(BIAS_LINEAR)){
65 biasLin = (Parameter) xo.getElementFirstChild(BIAS_LINEAR);
66 }
67
68 //get FrequencyModel
69 FrequencyModel freqModel = null;
70 if(xo.hasChildNamed(FrequencyModelParser.FREQUENCIES)){
71 freqModel = (FrequencyModel)xo.getElementFirstChild(FrequencyModelParser.FREQUENCIES);
72 }
73
74 boolean estimateSubmodelParams = false;
75 if(xo.hasAttribute(ESTIMATE_SUBMODEL_PARAMS)){
76 estimateSubmodelParams = xo.getBooleanAttribute(ESTIMATE_SUBMODEL_PARAMS);
77 }
78 System.out.println("Is estimating submodel parameter(s): "+estimateSubmodelParams);
79
80 boolean logistics = false;
81 if(xo.hasAttribute(LOGISTICS)){
82 logistics = xo.getBooleanAttribute(LOGISTICS);
83 }
84 System.out.println("Using logistic regression: "+ logistics);
85
86 boolean isSubmodel = false;
87 if(xo.hasAttribute(IS_SUBMODEL)){
88 isSubmodel = xo.getBooleanAttribute(IS_SUBMODEL);
89 }
90 System.out.println("Is a submodel: "+isSubmodel);
91
92 return new LinearBiasModel(
93 dataType,
94 freqModel,
95 subModel,
96 biasConst,
97 biasLin,
98 logistics,
99 estimateSubmodelParams,
100 isSubmodel
101 );
102 }
103
104 public String getParserDescription() {
105 return "This element represents an instance of the stepwise mutation model of microsatellite evolution.";
106 }
107
108 public XMLSyntaxRule[] getSyntaxRules() {
109 return rules;
110 }
111
112 private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{
113 new ElementRule(FrequencyModelParser.FREQUENCIES, new XMLSyntaxRule[]{
114 new ElementRule(FrequencyModel.class)},true),
115 new ElementRule(SUBMODEL,new XMLSyntaxRule[]{new ElementRule(OnePhaseModel.class)}),
116 new ElementRule(Microsatellite.class),
117 new ElementRule(BIAS_CONSTANT,new XMLSyntaxRule[]{new ElementRule(Parameter.class)},true),
118 new ElementRule(BIAS_LINEAR,new XMLSyntaxRule[]{new ElementRule(Parameter.class)},true),
119 new StringAttributeRule(ESTIMATE_SUBMODEL_PARAMS,"whether or not to esitmate the parameters of the submodel",true),
120 AttributeRule.newBooleanRule(LOGISTICS,true),
121 AttributeRule.newBooleanRule(IS_SUBMODEL,true)
122 };
123
124 public Class getReturnType() {
125 return LinearBiasModel.class;
126 }
127
128
129 }