use of dr.evolution.tree.SimpleTree in project beast-mcmc by beast-dev.
the class GibbsIndependentCoalescentOperator method doOperation.
/**
* change the parameter and return the hastings ratio.
*/
public double doOperation() {
CoalescentSimulator simulator = new CoalescentSimulator();
List<TaxonList> taxonLists = new ArrayList<TaxonList>();
double rootHeight = -1.0;
double oldLikelihood = 0.0;
double newLikelihood = 0.0;
// should have one child that is node
for (int i = 0; i < xo.getChildCount(); i++) {
final Object child = xo.getChild(i);
//careful: Trees are TaxonLists ... (AER); see OldCoalescentSimulatorParser
if (child instanceof Tree) {
//do nothing
} else if (child instanceof TaxonList) {
//taxonLists.add((TaxonList) child);
taxonLists.add((Taxa) child);
//taxa added
break;
}
}
try {
Tree[] trees = new Tree[taxonLists.size()];
// simulate each taxonList separately
for (int i = 0; i < taxonLists.size(); i++) {
trees[i] = simulator.simulateTree(taxonLists.get(i), demoModel);
}
oldLikelihood = coalescent.getLogLikelihood();
SimpleTree simTree = simulator.simulateTree(trees, demoModel, rootHeight, trees.length != 1);
//this would be the normal way to do it
treeModel.beginTreeEdit();
//now it's allowed to adjust the tree structure
treeModel.adoptTreeStructure(simTree);
//endTreeEdit() would then fire the events
treeModel.endTreeEdit();
newLikelihood = coalescent.getLogLikelihood();
} catch (IllegalArgumentException iae) {
try {
throw new XMLParseException(iae.getMessage());
} catch (XMLParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//return oldLikelihood - newLikelihood;
return 0;
}
use of dr.evolution.tree.SimpleTree in project beast-mcmc by beast-dev.
the class ConditionalCladeFrequency method report.
/**
* Creates the report. The estimated posterior of the given tree is printed.
*
* @throws IOException if general I/O error occurs
*/
public void report(Reader r) throws IOException, Importer.ImportException {
System.err.println("making report");
ArrayList<Tree> referenceTrees = new ArrayList<Tree>();
BufferedReader reader = new BufferedReader(r);
String line = reader.readLine();
if (line.toUpperCase().startsWith("#NEXUS")) {
NexusImporter importer = new NexusImporter(reader);
Tree[] trees = importer.importTrees(null);
for (Tree tree : trees) {
referenceTrees.add(tree);
SimpleTree sTree = new SimpleTree(tree);
System.out.println("Estimated marginal posterior by condiational clade frequencies:");
System.out.println(getTreeProbability(sTree) + "\t\t" + sTree);
}
} else {
throw new RuntimeException("Could not read reference tree. Only Nexus format is supported.");
}
System.out.flush();
}
Aggregations