Debian Codegraph @

src/dr/evomodelxml/coalescent/GMRFPopSizeStatisticParser.java

raw symbols SCIP
1 /*
2 * GMRFPopSizeStatisticParser.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.GMRFPopSizeStatistic;
29 import dr.evomodel.coalescent.GMRFSkyrideLikelihood;
30 import dr.xml.*;
31
32 /**
33 *
34 */
35 public class GMRFPopSizeStatisticParser extends AbstractXMLObjectParser {
36
37 public final static String TIMES = "time";
38 public final static String FROM = "from";
39 public final static String TO = "to";
40 public final static String NUMBER_OF_INTERVALS = "number";
41 public final static String GMRF_POP_SIZE_STATISTIC = "gmrfPopSizeStatistic";
42
43 public String getParserName() {
44 return GMRF_POP_SIZE_STATISTIC;
45 }
46
47 public String getParserDescription() {
48 return "The pop sizes at the given times";
49 }
50
51 public Class getReturnType() {
52 return GMRFPopSizeStatistic.class;
53 }
54
55 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
56
57 double[] times;
58
59 if (xo.hasAttribute(FROM)) {
60 double from = xo.getDoubleAttribute(FROM);
61 double to = xo.getDoubleAttribute(TO);
62 int number = xo.getIntegerAttribute(NUMBER_OF_INTERVALS);
63
64 double length = (to - from) / number;
65
66 times = new double[number + 1];
67
68 for (int i = 0; i < times.length; i++) {
69 times[i] = from + i * length;
70 }
71 } else {
72 times = xo.getDoubleArrayAttribute(TIMES);
73 }
74
75 GMRFSkyrideLikelihood gsl = (GMRFSkyrideLikelihood) xo.getChild(GMRFSkyrideLikelihood.class);
76
77 return new GMRFPopSizeStatistic(times, gsl);
78 }
79
80 public XMLSyntaxRule[] getSyntaxRules() {
81 return new XMLSyntaxRule[]{
82 AttributeRule.newDoubleRule(FROM, true),
83 AttributeRule.newDoubleRule(TO, true),
84 AttributeRule.newIntegerRule(NUMBER_OF_INTERVALS, true),
85 AttributeRule.newDoubleArrayRule(TIMES, true),
86
87 new ElementRule(GMRFSkyrideLikelihood.class),
88 };
89 }
90
91 }