Debian Codegraph @

src/dr/evoxml/PearsonCorrelationParser.java

raw symbols SCIP
1 /*
2 * PearsonCorrelationParser.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.evoxml;
27
28 import dr.xml.*;
29 import dr.inference.model.Parameter;
30 import dr.inference.model.PearsonCorrelation;
31
32 /**
33 * @author Simon Greenhill
34 */
35
36 public class PearsonCorrelationParser extends AbstractXMLObjectParser {
37
38 public static final String PEARSON_CORRELATION = "pearsonCorrelation";
39 public static final String LOG = "log";
40
41 public String getParserName() { return PEARSON_CORRELATION; }
42
43 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
44
45 boolean log = xo.getAttribute(LOG, false);
46 Parameter X = (Parameter)xo.getChild(0);
47 Parameter Y = (Parameter)xo.getChild(1);
48
49 // System.out.println("Correlating " + X + " with " + Y + " using log = " + log);
50 PearsonCorrelation pearsonCorrelation = new PearsonCorrelation(X, Y, log);
51 return pearsonCorrelation;
52
53 }
54
55 //************************************************************************
56 // AbstractXMLObjectParser implementation
57 //************************************************************************
58
59 public String getParserDescription() {
60 return "A Pearson Correlation between two Parameters";
61 }
62
63 public String getExample() {
64 return "<pearsonCorrelation id=\"r\" log=\"true\">\n"+
65 " <parameter idref=\"param1\"/>\n"+
66 " <parameter idref=\"param2\"/>\n"+
67 "</pearsonCorrelation>\n";
68 }
69
70 public Class getReturnType() { return PearsonCorrelation.class; }
71
72 public XMLSyntaxRule[] getSyntaxRules() { return rules; }
73
74 private final XMLSyntaxRule[] rules = {
75 // There should be two and only two Parameters (X & Y)
76 new ElementRule(Parameter.class, 2, 2),
77 // the optional log attribute has to be a Boolean
78 AttributeRule.newBooleanRule(LOG, true),
79 };
80
81 }