Debian Codegraph @

src/dr/oldevomodelxml/sitemodel/DiscretizedLociRatesParser.java

raw symbols SCIP
1 /*
2 * DiscretizedLociRatesParser.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.sitemodel;
27
28 import dr.xml.*;
29 import dr.evomodel.branchratemodel.DiscretizedBranchRates;
30 import dr.oldevomodel.sitemodel.DiscretizedLociRates;
31 import dr.inference.distribution.ParametricDistributionModel;
32 import dr.inference.model.Parameter;
33 import dr.inference.model.CompoundParameter;
34
35 import java.util.logging.Logger;
36
37 /**
38 * @author Chieh-Hsi Wu
39 * Parser of DiscretizedLociRates
40 */
41 public class DiscretizedLociRatesParser extends AbstractXMLObjectParser {
42 public final String DISCRETIZED_LOCI_RATES = "DiscretizedLociRates";
43 public final String NORMALIZE = "normalize";
44 public final String NORMALIZE_MEAN_LOCI_RATE_TO = "normalizeMeanLociRateTo";
45 public final String RATE_CATEGORIES = "rateCategories";
46 public final String CATEGORY_COUNT = "categoryCount";
47 public final String LOCI_RATES = "lociRates";
48 public final String DISTRIBUTION = "distribution";
49
50
51
52 public String getParserName(){
53 return DISCRETIZED_LOCI_RATES;
54 }
55 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
56
57
58 final boolean normalize = xo.getAttribute(NORMALIZE, false);
59 final double normalizeBranchRateTo = xo.getAttribute(NORMALIZE_MEAN_LOCI_RATE_TO, Double.NaN);
60 final int categoryCount = xo.getIntegerAttribute(CATEGORY_COUNT);
61
62 CompoundParameter lociRates = (CompoundParameter) xo.getElementFirstChild(LOCI_RATES);
63 Parameter rateCategoryParameter = (Parameter) xo.getElementFirstChild(RATE_CATEGORIES);
64 ParametricDistributionModel distributionModel = (ParametricDistributionModel) xo.getElementFirstChild(DISTRIBUTION);
65
66
67
68 Logger.getLogger("dr.evomodel").info("Using discretized loci rates model.");
69 Logger.getLogger("dr.evomodel").info("Number of categories: "+categoryCount);
70 Logger.getLogger("dr.evomodel").info(" parametric model = " + distributionModel.getModelName());
71 if(normalize) {
72 Logger.getLogger("dr.evomodel").info(" mean rate is normalized to " + normalizeBranchRateTo);
73 }
74
75
76 return new DiscretizedLociRates(
77 lociRates,
78 rateCategoryParameter,
79 distributionModel,
80 normalize,
81 normalizeBranchRateTo,
82 categoryCount);
83 }
84
85 //************************************************************************
86 // AbstractXMLObjectParser implementation
87 //************************************************************************
88
89 public String getParserDescription() {
90 return
91 "This element returns an discretized loci rate model." +
92 "The loci rates are drawn from a discretized parametric distribution.";
93 }
94
95 public Class getReturnType() {
96 return DiscretizedBranchRates.class;
97 }
98
99 public XMLSyntaxRule[] getSyntaxRules() {
100 return rules;
101 }
102
103 private final XMLSyntaxRule[] rules = {
104 AttributeRule.newBooleanRule(NORMALIZE, true, "Whether the mean rate has to be normalized to a particular value"),
105 AttributeRule.newDoubleRule(NORMALIZE_MEAN_LOCI_RATE_TO, true, "The mean rate to normalize to, if normalizing"),
106 AttributeRule.newIntegerRule(CATEGORY_COUNT, true, "The number of categories that the distribution will be divided into"),
107 new ElementRule(LOCI_RATES, CompoundParameter.class, "The compound parameter that contains all the loci rate parameters", false),
108 new ElementRule(DISTRIBUTION, ParametricDistributionModel.class, "The distribution model for rates among branches", false),
109 new ElementRule(RATE_CATEGORIES, Parameter.class, "The rate categories parameter", false),
110 };
111 }