Debian Codegraph @

src/dr/oldevomodelxml/substmodel/TwoPhaseModelParser.java

raw symbols SCIP
1 /*
2 * TwoPhaseModelParser.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.OnePhaseModel;
31 import dr.oldevomodel.substmodel.TwoPhaseModel;
32 import dr.inference.model.Parameter;
33 import dr.xml.*;
34
35 /**
36 * @author Chieh-Hsi Wu
37 *
38 * Parser for Two Phase Model of microsatellites.
39 *
40 */
41 public class TwoPhaseModelParser extends AbstractXMLObjectParser{
42 public static final String SUBMODEL = "Submodel";
43 public static final String GEO_PARAM = "GeoParam";
44 public static final String ONEPHASEPR_PARAM ="OnePhasePrParam";
45 public static final String TRANS_PARAM = "TransformParam";
46 public static final double UPPER = 1.0;
47 public static final double LOWER = 0.0;
48 public static final String ESTIMATE_SUBMODEL_PARAMS = "estimateSubmodelParameters";
49
50 public String getParserName() {
51 return TwoPhaseModel.TWO_PHASE_MODEL;
52 }
53
54 //AbstractXMLObjectParser implementation
55 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
56
57 OnePhaseModel subModel = (OnePhaseModel) xo.getElementFirstChild(SUBMODEL);
58 Microsatellite dataType = (Microsatellite)xo.getChild(Microsatellite.class);
59
60 Parameter.Default geoParam =(Parameter.Default) xo.getElementFirstChild(GEO_PARAM);
61
62 Parameter paramP = (Parameter) xo.getElementFirstChild(ONEPHASEPR_PARAM);
63
64 Parameter limitE = null;
65 if(xo.hasChildNamed(TRANS_PARAM)){
66 limitE = (Parameter) xo.getElementFirstChild(TRANS_PARAM);
67 }
68
69 boolean estimateSubmodelParams = xo.getAttribute(ESTIMATE_SUBMODEL_PARAMS,false);
70
71 FrequencyModel freqModel = null;
72 if(xo.hasChildNamed(FrequencyModelParser.FREQUENCIES)){
73 freqModel = (FrequencyModel)xo.getElementFirstChild(FrequencyModelParser.FREQUENCIES);
74 }
75
76 return new TwoPhaseModel(dataType, freqModel, subModel, paramP, geoParam, limitE, estimateSubmodelParams);
77 }
78
79 public String getParserDescription() {
80 return "This element represents an instance of the Two Phase Model of microsatellite evolution.";
81 }
82
83 public XMLSyntaxRule[] getSyntaxRules() {
84 return rules;
85 }
86
87 private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{
88 new ElementRule(Microsatellite.class),
89 new ElementRule(FrequencyModelParser.FREQUENCIES, new XMLSyntaxRule[]{new ElementRule(FrequencyModel.class)},true),
90 new ElementRule(SUBMODEL,new XMLSyntaxRule[]{new ElementRule(OnePhaseModel.class)}),
91 new ElementRule(ONEPHASEPR_PARAM,new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
92 new ElementRule(GEO_PARAM,new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
93 new ElementRule(TRANS_PARAM,new XMLSyntaxRule[]{new ElementRule(Parameter.class)},true),
94 new StringAttributeRule(ESTIMATE_SUBMODEL_PARAMS,"whether or not to esitmate the parameters of the submodel",true)
95 };
96
97 public Class getReturnType() {
98 return TwoPhaseModel.class;
99 }
100
101
102 }