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);
}
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);
}
}
Aggregations