Search in sources :

Example 1 with EBSPAnalysis

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());
    }
}
Also used : EBSPAnalysis(dr.evomodel.coalescent.EBSPAnalysis) VariableDemographicModel(dr.evomodel.coalescent.VariableDemographicModel) FileWriter(java.io.FileWriter) TraceException(dr.inference.trace.TraceException) File(java.io.File) PrintWriter(java.io.PrintWriter) Importer(dr.evolution.io.Importer)

Aggregations

Importer (dr.evolution.io.Importer)1 EBSPAnalysis (dr.evomodel.coalescent.EBSPAnalysis)1 VariableDemographicModel (dr.evomodel.coalescent.VariableDemographicModel)1 TraceException (dr.inference.trace.TraceException)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 PrintWriter (java.io.PrintWriter)1