use of dr.evomodel.coalescent.EBSPAnalysis in project beast-mcmc by beast-dev.
the class EBSPAnalysisParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
try {
// 10% is brun-in default
final double burnin = xo.getAttribute(BURN_IN, 0.1);
if (burnin < 0) {
throw new XMLParseException("burnIn should be either between 0 and 1 or a positive number");
}
final double[] hpdLevels = xo.hasAttribute(HPD_LEVELS) ? xo.getDoubleArrayAttribute(HPD_LEVELS) : null;
final File log = FileHelpers.getFile(getElementText(xo, LOG_FILE_NAME));
final XMLObject treeFileNames = xo.getChild(TREE_FILE_NAMES);
final int nTrees = treeFileNames.getChildCount();
File[] treeFiles = new File[nTrees];
for (int k = 0; k < nTrees; ++k) {
treeFiles[k] = FileHelpers.getFile(((XMLObject) treeFileNames.getChild(k)).getStringChild(0));
}
String modelTypeName = getElementText(xo, MODEL_TYPE).trim().toUpperCase();
String populationFirstColumn = getElementText(xo, POPULATION_FIRST_COLUMN);
String indicatorsFirstColumn = getElementText(xo, INDICATORS_FIRST_COLUMN);
VariableDemographicModel.Type modelType = VariableDemographicModel.Type.valueOf(modelTypeName);
String rootHeightColumn = null;
int nBins = -1;
if (xo.hasAttribute(NBINS)) {
if (xo.getChild(ROOTHEIGHT_COLUMN) != null) {
rootHeightColumn = getElementText(xo, ROOTHEIGHT_COLUMN);
nBins = xo.getIntegerAttribute(NBINS);
}
}
PrintWriter allDemoWriter = null;
if (xo.getChild(ALLDEMO_COLUMN) != null) {
String fName = getElementText(xo, ALLDEMO_COLUMN);
allDemoWriter = new PrintWriter(new FileWriter(fName));
}
final boolean quantiles = xo.getAttribute(QUANTILES, false);
final boolean logSpace = xo.getAttribute(LOG_SPACE, false);
final boolean useMid = xo.getAttribute(USE_MIDDLE, false);
final int onlyNchanges = xo.getAttribute(N_CHANGES, -1);
return new EBSPAnalysis(log, treeFiles, modelType, populationFirstColumn, indicatorsFirstColumn, rootHeightColumn, nBins, burnin, hpdLevels, quantiles, logSpace, useMid, onlyNchanges, allDemoWriter);
} catch (java.io.IOException ioe) {
throw new XMLParseException(ioe.getMessage());
} catch (Importer.ImportException e) {
throw new XMLParseException(e.toString());
} catch (TraceException e) {
throw new XMLParseException(e.toString());
}
}
Aggregations