Debian Codegraph @

src/dr/oldevomodelxml/sitemodel/SampleQuantileLociRatesParser.java

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