| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
} |