Debian Codegraph @

src/dr/evomodelxml/substmodel/HKYParser.java

raw symbols SCIP
1 /*
2 * HKYParser.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.inference.model.Parameter;
29 import dr.xml.*;
30 import dr.evomodel.substmodel.FrequencyModel;
31 import dr.evomodel.substmodel.nucleotide.HKY;
32
33 import java.util.logging.Logger;
34
35 /**
36 * @author Alexei Drummond
37 * @author Andrew Rambaut
38 */
39 public class HKYParser extends AbstractXMLObjectParser {
40
41 public static final String HKY_MODEL = "hkyModel";
42 public static final String KAPPA = "kappa";
43 public static final String FREQUENCIES = "frequencies";
44
45 public String getParserName() {
46 return HKY_MODEL;
47 }
48
49 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
50
51 Parameter kappaParam = (Parameter) xo.getElementFirstChild(KAPPA);
52 FrequencyModel freqModel = (FrequencyModel) xo.getElementFirstChild(FrequencyModelParser.FREQUENCIES);
53
54 if (kappaParam.getId() == null && kappaParam.getParameterValue(0) == 1.0) {
55 Logger.getLogger("dr.evomodel").info("\nCreating JC substitution model.");
56 } else {
57 Logger.getLogger("dr.evomodel").info("\nCreating HKY substitution model. Initial kappa = " +
58 kappaParam.getParameterValue(0));
59 }
60 return new HKY(kappaParam, freqModel);
61 }
62
63 //************************************************************************
64 // AbstractXMLObjectParser implementation
65 //************************************************************************
66
67 public String getParserDescription() {
68 return "This element represents an instance of the HKY85 " +
69 "(Hasegawa, Kishino & Yano, 1985) model of nucleotide evolution.";
70 }
71
72 public Class getReturnType() {
73 return HKY.class;
74 }
75
76 public XMLSyntaxRule[] getSyntaxRules() {
77 return rules;
78 }
79
80 private final XMLSyntaxRule[] rules = {
81 new ElementRule(FrequencyModelParser.FREQUENCIES,
82 new XMLSyntaxRule[]{new ElementRule(FrequencyModel.class)}),
83 new ElementRule(KAPPA,
84 new XMLSyntaxRule[]{new ElementRule(Parameter.class)})
85 };
86
87 }