Debian Codegraph @

src/dr/evomodel/arg/ARGTraceAnalysisParser.java

raw symbols SCIP
1 /*
2 * ARGTraceAnalysisParser.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.evomodel.arg;
27
28 import dr.evomodel.tree.TreeTraceAnalysis;
29 import dr.xml.*;
30
31 import java.io.File;
32 import java.io.FileNotFoundException;
33 import java.io.FileReader;
34 import java.io.Reader;
35
36 /**
37 * @author Marc A. Suchard
38 */
39
40 public class ARGTraceAnalysisParser extends AbstractXMLObjectParser {
41
42 public final static String ARG_TRACE_ANALYSIS = "argTraceAnalysis";
43 public final static String BURN_IN = "burnIn";
44 public static final String FILE_NAME = "fileName";
45
46 public String getParserName() {
47 return ARG_TRACE_ANALYSIS;
48 }
49
50 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
51
52 try {
53 Reader reader;
54
55 String fileName = xo.getStringAttribute(FILE_NAME);
56 try {
57 File file = new File(fileName);
58 String name = file.getName();
59 String parent = file.getParent();
60
61 if (!file.isAbsolute()) {
62 parent = System.getProperty("user.dir");
63 }
64
65 // System.out.println("Writing log file to "+parent+System.getProperty("path.separator")+name);
66 reader = new FileReader(new File(parent, name));
67 } catch (FileNotFoundException fnfe) {
68 throw new XMLParseException("File '" + fileName + "' can not be opened for " + getParserName() + " element.");
69 }
70
71 int burnin = -1;
72 if (xo.hasAttribute(BURN_IN)) {
73 // leaving the burnin attribute off will result in 10% being used
74 burnin = xo.getIntegerAttribute(BURN_IN);
75 }
76
77 ARGTraceAnalysis analysis = ARGTraceAnalysis.analyzeLogFile(new Reader[]{reader}, burnin, true);
78
79 analysis.report();
80
81 System.out.println();
82 System.out.flush();
83
84 return analysis;
85 } catch (java.io.IOException ioe) {
86 throw new XMLParseException(ioe.getMessage());
87 }
88 }
89
90 //************************************************************************
91 // AbstractXMLObjectParser implementation
92 //************************************************************************
93
94 public String getParserDescription() {
95 return "Analyses and reports on a trace consisting of trees.";
96 }
97
98 public Class getReturnType() {
99 return TreeTraceAnalysis.class;
100 }
101
102 public XMLSyntaxRule[] getSyntaxRules() {
103 return rules;
104 }
105
106 private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{
107 new StringAttributeRule(FILE_NAME, "name of a tree log file", "trees.log"),
108 AttributeRule.newIntegerRule(BURN_IN, true)
109 };
110 }