Debian Codegraph @

src/dr/oldevomodelxml/substmodel/MutationDeathModelParser.java

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