Debian Codegraph @

src/dr/evomodelxml/coalescent/GPSkytrackAnalysisParser.java

raw symbols SCIP
1 /*
2 * GPSkytrackAnalysisParser.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.evolution.io.Importer;
29 import dr.evomodel.coalescent.GPSkytrackAnalysis;
30 import dr.inference.model.Parameter;
31 //import dr.evomodel.coalescent.GaussianProcessSkytrackLikelihood;
32 import dr.inference.trace.TraceException;
33 import dr.util.FileHelpers;
34 import dr.xml.*;
35
36 import java.io.File;
37 //import java.io.FileWriter;
38 //import java.io.PrintWriter;
39
40 /**
41 */
42 public class GPSkytrackAnalysisParser extends AbstractXMLObjectParser {
43
44 public static final String GP_ANALYSIS = "GPAnalysis";
45 public static final String FILE_NAME = "fileName";
46 public static final String BURN_IN = "burnIn";
47 // public static final String HPD_LEVELS = "Confidencelevels";
48 // public static final String QUANTILES = "useQuantiles";
49 // public static final String LOG_SPACE = VariableDemographicModelParser.LOG_SPACE;
50 public static final String N_GRID = "numGridPoints";
51 // public static final String N_CHANGES = "nChanges";
52
53 // public static final String TREE_LOG = "treeOfLoci";
54
55 public static final String LOG_FILE_NAME = "logFileName";
56
57 private String getElementText(XMLObject xo, String childName) throws XMLParseException {
58 return xo.getChild(childName).getStringChild(0);
59 }
60
61 public String getParserName() {
62 return GP_ANALYSIS;
63 }
64
65 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
66 System.err.println("The Summary Statistics are being created...");
67
68 try {
69
70 // 10% is brun-in default
71 final double burnin = xo.getAttribute(BURN_IN, 0.1);
72 if (burnin < 0) {
73 throw new XMLParseException("burnIn should be either between 0 and 1 or a positive number");
74 }
75
76
77
78 Parameter numGridPoints = new Parameter.Default(0,1);
79 if (xo.getChild(N_GRID) != null) {
80 XMLObject cxo = xo.getChild(N_GRID);
81 numGridPoints = (Parameter) cxo.getChild(Parameter.class);
82 }
83
84
85 final File log = FileHelpers.getFile(getElementText(xo, LOG_FILE_NAME));
86
87
88 return new dr.evomodel.coalescent.GPSkytrackAnalysis(log,burnin,numGridPoints);
89
90 } catch (java.io.IOException ioe) {
91 throw new XMLParseException(ioe.getMessage());
92 } catch (Importer.ImportException e) {
93 throw new XMLParseException(e.toString());
94 } catch (TraceException e) {
95 throw new XMLParseException(e.toString());
96 }
97 }
98
99 //************************************************************************
100 // AbstractXMLObjectParser implementation
101 //************************************************************************
102
103 public String getParserDescription() {
104 return "reconstruct population graph from GPSkytrack run.";
105 }
106
107 public Class getReturnType() {
108 return GPSkytrackAnalysis.class;
109 }
110
111 public XMLSyntaxRule[] getSyntaxRules() {
112 return rules;
113 }
114
115 private final XMLSyntaxRule[] rules = {
116 AttributeRule.newDoubleRule(BURN_IN, true, "The number of states (not sampled states, but" +
117 " actual states) that are discarded from the beginning of the trace and are excluded from " +
118 "the analysis"),
119 new ElementRule(LOG_FILE_NAME, String.class, "The name of a BEAST log file"),
120 new ElementRule(N_GRID, new XMLSyntaxRule[]{
121 new ElementRule(Parameter.class)
122 })
123 };
124
125 }