Debian Codegraph @

src/dr/oldevomodelxml/substmodel/NtdBMAParser.java

raw symbols SCIP
1 /*
2 * NtdBMAParser.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.xml.*;
29 import dr.oldevomodel.substmodel.FrequencyModel;
30 import dr.oldevomodel.substmodel.NtdBMA;
31 import dr.inference.model.Variable;
32
33 /**
34 * @author Chieh-Hsi Wu
35 * Parser for nucleotide subsitution
36 */
37 public class NtdBMAParser extends AbstractXMLObjectParser {
38 public static final String NTD_BMA = "ntdBMA";
39 public static final String KAPPA = "kappa";
40 public static final String TN = "tn";
41 public static final String AT = "at";
42 public static final String AC = "ac";
43 public static final String GC = "gc";
44 public static final String GT = "gt";
45 public static final String MODEL_CHOOSE = "modelChoose";
46
47 public static final String FREQUENCIES = "frequencies";
48
49 public String getParserName() {
50 return NTD_BMA;
51 }
52
53 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
54
55
56
57 Variable kappa = (Variable) xo.getElementFirstChild(KAPPA);
58 Variable tn = (Variable) xo.getElementFirstChild(TN);
59 Variable ac = (Variable) xo.getElementFirstChild(AC);
60 Variable at = (Variable) xo.getElementFirstChild(AT);
61 Variable gc = (Variable) xo.getElementFirstChild(GC);
62 Variable gt = (Variable) xo.getElementFirstChild(GT);
63 Variable modelChoose = (Variable) xo.getElementFirstChild(MODEL_CHOOSE);
64 XMLObject cxo = xo.getChild(FREQUENCIES);
65 FrequencyModel freqModel = (FrequencyModel) cxo.getChild(FrequencyModel.class);
66
67
68 return new NtdBMA(kappa, tn, ac, at, gc, gt, modelChoose, freqModel);
69 }
70
71 public Class getReturnType() {
72 return NtdBMA.class;
73 }
74
75 public XMLSyntaxRule[] getSyntaxRules() {
76 return rules;
77 }
78
79 private final XMLSyntaxRule[] rules = {
80 new ElementRule(FREQUENCIES,
81 new XMLSyntaxRule[]{new ElementRule(FrequencyModel.class)}),
82 new ElementRule(KAPPA,
83 new XMLSyntaxRule[]{new ElementRule(Variable.class)}, true),
84 new ElementRule(AC,
85 new XMLSyntaxRule[]{new ElementRule(Variable.class)}, true),
86 new ElementRule(AT,
87 new XMLSyntaxRule[]{new ElementRule(Variable.class)}, true),
88 new ElementRule(GC,
89 new XMLSyntaxRule[]{new ElementRule(Variable.class)}, true),
90 new ElementRule(GT,
91 new XMLSyntaxRule[]{new ElementRule(Variable.class)}, true),
92 new ElementRule(MODEL_CHOOSE,
93 new XMLSyntaxRule[]{new ElementRule(Variable.class)}, true),
94 };
95 public String getParserDescription() {
96 return "A model that allows model averaging over nucleotide substitution models.";
97 }
98 }