Debian Codegraph @

src/dr/evomodelxml/substmodel/MutationDeathModelParser.java

raw symbols SCIP
1 /*
2 * MutationDeathModelParser.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.evomodel.substmodel.FrequencyModel;
29 import dr.evomodel.substmodel.MutationDeathModel;
30 import dr.evomodel.substmodel.SubstitutionModel;
31 import dr.evolution.datatype.MutationDeathType;
32 import dr.inference.model.Parameter;
33 import dr.xml.*;
34
35 import java.util.logging.Logger;
36
37 /**
38 * @author Alexander V. Alekseyenko
39 * @author Marc A. Suchard
40 */
41 public class MutationDeathModelParser extends AbstractXMLObjectParser {
42
43 public static final String MD_MODEL = "mutationDeathModel";
44 public static final String MUTATION_RATE = "mutationRate";
45
46 public String getParserName() {
47 return MD_MODEL;
48 }
49
50 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
51 Parameter dummyFreqParameter;
52 Parameter delParam = (Parameter) xo.getChild(Parameter.class);
53
54 Logger.getLogger("dr.evomodel").info("Creating MutationDeath substitution model.\n\tInitial death rate is "
55 + delParam.getParameterValue(0));
56
57 MutationDeathType dT = (MutationDeathType) xo.getChild(MutationDeathType.class);
58
59 SubstitutionModel evoModel = (SubstitutionModel) xo.getChild(SubstitutionModel.class);
60 if (evoModel == null) { // Assuming pure survival model
61 Logger.getLogger("dr.evomodel").info("\tSubstitutionModel not provided assuming pure death/survival model.");
62 dummyFreqParameter = new Parameter.Default(new double[]{1.0, 0.0});
63 } else {
64 dummyFreqParameter = new Parameter.Default(dT.getStateCount());
65 double freqs[] = evoModel.getFrequencyModel().getFrequencies();
66 for (int i = 0; i < freqs.length; ++i) {
67 dummyFreqParameter.setParameterValueQuietly(i, freqs[i]);
68 }
69 dummyFreqParameter.setParameterValueQuietly(dT.getStateCount() - 1, 0.0);
70 }
71
72 FrequencyModel dummyFrequencies = new FrequencyModel(dT, dummyFreqParameter);
73
74 Parameter mutationRate;
75
76 if (xo.hasChildNamed(MUTATION_RATE)) {
77 mutationRate = (Parameter) xo.getElementFirstChild(MUTATION_RATE);
78 } else {
79 mutationRate = new Parameter.Default(new double[]{1.0});
80 }
81 Logger.getLogger("dr.evomodel").info("\tInitial mutation rate is " + mutationRate.getParameterValue(0));
82
83 return new MutationDeathModel(delParam, dT, evoModel, dummyFrequencies, mutationRate);
84 }
85
86 //************************************************************************
87 // AbstractXMLObjectParser implementation
88 //************************************************************************
89
90 public String getParserDescription() {
91 return "This element represents an instance of the MutationDeath model of CTMC evolution with deletions.";
92 }
93
94 public Class getReturnType() {
95 return MutationDeathModel.class;
96 }
97
98 public XMLSyntaxRule[] getSyntaxRules() {
99 return rules;
100 }
101
102 private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{
103 new ElementRule(SubstitutionModel.class, true),
104 new ElementRule(Parameter.class),
105 new ElementRule(MutationDeathType.class),
106 new ElementRule(MUTATION_RATE, new XMLSyntaxRule[]{new ElementRule(Parameter.class)}, true)
107 };
108
109 }