Search in sources :

Example 1 with EmpiricalTreeDistributionModel

use of dr.evomodel.tree.EmpiricalTreeDistributionModel in project beast-mcmc by beast-dev.

the class EmpiricalTreeDistributionOperatorParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    final double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
    boolean metropolisHastings = false;
    if (xo.hasAttribute(EmpiricalTreeDistributionOperator.METROPOLIS_HASTINGS)) {
        metropolisHastings = xo.getBooleanAttribute(EmpiricalTreeDistributionOperator.METROPOLIS_HASTINGS);
    }
    final EmpiricalTreeDistributionModel treeModel = (EmpiricalTreeDistributionModel) xo.getChild(EmpiricalTreeDistributionModel.class);
    return new EmpiricalTreeDistributionOperator(treeModel, metropolisHastings, weight);
}
Also used : EmpiricalTreeDistributionOperator(dr.evomodel.operators.EmpiricalTreeDistributionOperator) EmpiricalTreeDistributionModel(dr.evomodel.tree.EmpiricalTreeDistributionModel)

Example 2 with EmpiricalTreeDistributionModel

use of dr.evomodel.tree.EmpiricalTreeDistributionModel in project beast-mcmc by beast-dev.

the class EmpiricalTreeDistributionModelParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    final String fileName = xo.getStringAttribute(FILE_NAME);
    // default is random tree
    int startingTree = xo.getAttribute(STARTING_TREE, -1);
    // default is random draw
    boolean iterate = xo.getAttribute(ITERATE, false);
    if (iterate && startingTree < 0) {
        startingTree = 0;
    }
    Logger.getLogger("dr.evomodel").info("Creating the empirical tree distribution model, '" + xo.getId() + "'");
    TaxonList taxa = (TaxonList) xo.getChild(TaxonList.class);
    final File file = FileHelpers.getFile(fileName);
    Tree[] trees = null;
    NexusImporter importer = null;
    try {
        FileReader reader = new FileReader(file);
        importer = new NexusImporter(reader);
        if (!iterate) {
            // Re-order taxon numbers to original TaxonList order
            trees = importer.importTrees(taxa, true);
            reader.close();
        }
    } catch (FileNotFoundException e) {
        throw new XMLParseException(e.getMessage());
    } catch (IOException e) {
        throw new XMLParseException(e.getMessage());
    } catch (Importer.ImportException e) {
        throw new XMLParseException(e.getMessage());
    }
    if (iterate) {
        Logger.getLogger("dr.evomodel").info("    Iterate over each tree from file, " + fileName);
        return new EmpiricalTreeDistributionModel(importer, startingTree);
    } else {
        Logger.getLogger("dr.evomodel").info("    Randomly jump between " + trees.length + " trees from file, " + fileName);
        return new EmpiricalTreeDistributionModel(trees, startingTree);
    }
}
Also used : NexusImporter(dr.evolution.io.NexusImporter) TaxonList(dr.evolution.util.TaxonList) EmpiricalTreeDistributionModel(dr.evomodel.tree.EmpiricalTreeDistributionModel) Tree(dr.evolution.tree.Tree) NexusImporter(dr.evolution.io.NexusImporter) Importer(dr.evolution.io.Importer)

Aggregations

EmpiricalTreeDistributionModel (dr.evomodel.tree.EmpiricalTreeDistributionModel)2 Importer (dr.evolution.io.Importer)1 NexusImporter (dr.evolution.io.NexusImporter)1 Tree (dr.evolution.tree.Tree)1 TaxonList (dr.evolution.util.TaxonList)1 EmpiricalTreeDistributionOperator (dr.evomodel.operators.EmpiricalTreeDistributionOperator)1