| 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.evomodelxml.coalescent; |
| 27 |
|
| 28 |
import dr.evolution.io.Importer; |
| 29 |
import dr.evomodel.coalescent.GPSkytrackAnalysis; |
| 30 |
import dr.inference.model.Parameter; |
| 31 |
|
| 32 |
import dr.inference.trace.TraceException; |
| 33 |
import dr.util.FileHelpers; |
| 34 |
import dr.xml.*; |
| 35 |
|
| 36 |
import java.io.File; |
| 37 |
|
| 38 |
|
| 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 |
|
| 48 |
|
| 49 |
|
| 50 |
public static final String N_GRID = "numGridPoints"; |
| 51 |
|
| 52 |
|
| 53 |
|
| 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 |
|
| 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 |
|
| 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 |
} |