Debian Codegraph @

src/dr/evomodelxml/coalescent/BMPriorLikelihoodParser.java

raw symbols SCIP
1 /*
2 * BMPriorLikelihoodParser.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.evomodelxml.coalescent;
27
28 import dr.evomodel.coalescent.BMPriorLikelihood;
29 import dr.evomodel.coalescent.VariableDemographicModel;
30 import dr.inference.distribution.ParametricDistributionModel;
31 import dr.inference.model.Parameter;
32 import dr.xml.*;
33
34 /**
35 */
36 public class BMPriorLikelihoodParser extends AbstractXMLObjectParser { //TODO Parser is still in a bad state
37 public static final String BM = "BrownianMotion";
38 public static final String LOG_SPACE = "logUnits";
39 //static final String NORMALIZE = "normalize";
40
41 //static final String DATA = "data";
42 // static final String TIMES = "times";
43
44 // public static final String MEAN = "mean";
45 public static final String SIGMA = "sigma";
46 // public static final String LAMBDA = "lambda";
47
48 public String getParserDescription() {
49 return "";
50 }
51
52 public Class getReturnType() {
53 return BMPriorLikelihood.class;
54 }
55
56 public String getParserName() {
57 return BM;
58 }
59
60 private Parameter getParam(XMLObject xo, String name) throws XMLParseException {
61 final XMLObject object = xo.getChild(name);
62 // optional
63 if (object == null) {
64 return null;
65 }
66 final Object child = object.getChild(0);
67 if (child instanceof Parameter) {
68 return (Parameter) child;
69 }
70
71 double x = object.getDoubleChild(0);
72 return new Parameter.Default(x);
73 }
74
75 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
76
77 // Parameter mean = getParam(xo, MEAN);
78 Parameter sigma = getParam(xo, SIGMA);
79 // Parameter lambda = getParam(xo, LAMBDA);
80
81 final boolean logSpace = xo.getAttribute(LOG_SPACE, false);
82 // final boolean normalize = xo.getAttribute(NORMALIZE, false);
83
84 VariableDemographicModel m = (VariableDemographicModel) xo.getChild(VariableDemographicModel.class);
85
86 ParametricDistributionModel popMeanPrior = (ParametricDistributionModel) xo.getChild(ParametricDistributionModel.class);
87 return new BMPriorLikelihood(sigma, m, logSpace, popMeanPrior);
88 }
89
90 public XMLSyntaxRule[] getSyntaxRules() {
91
92
93 return new XMLSyntaxRule[]{
94 AttributeRule.newBooleanRule(LOG_SPACE, true),
95
96 new XORRule(
97 new ElementRule(SIGMA, Double.class),
98 new ElementRule(SIGMA, Parameter.class)
99 ),
100
101 // you can't have a XOR (b AND c), yikes
102 // make all optional and check in parser
103 new ElementRule(VariableDemographicModel.class),
104
105 // new ElementRule(DATA, new XMLSyntaxRule[]{new ElementRule(Statistic.class)}, true),
106 // new ElementRule(TIMES, new XMLSyntaxRule[]{new ElementRule(Statistic.class)}, true)
107
108 };
109 }
110 }