Search in sources :

Example 11 with SimpleTree

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;
}
Also used : TaxonList(dr.evolution.util.TaxonList) ArrayList(java.util.ArrayList) SimpleTree(dr.evolution.tree.SimpleTree) CoalescentSimulator(dr.evomodel.coalescent.CoalescentSimulator) Taxa(dr.evolution.util.Taxa) SimpleTree(dr.evolution.tree.SimpleTree) Tree(dr.evolution.tree.Tree) XMLObject(dr.xml.XMLObject) XMLParseException(dr.xml.XMLParseException)

Example 12 with SimpleTree

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();
}
Also used : NexusImporter(dr.evolution.io.NexusImporter) BufferedReader(java.io.BufferedReader) SimpleTree(dr.evolution.tree.SimpleTree) Tree(dr.evolution.tree.Tree) SimpleTree(dr.evolution.tree.SimpleTree)

Aggregations

SimpleTree (dr.evolution.tree.SimpleTree)12 SimpleNode (dr.evolution.tree.SimpleNode)7 Tree (dr.evolution.tree.Tree)7 TaxonList (dr.evolution.util.TaxonList)4 Taxa (dr.evolution.util.Taxa)3 CoalescentSimulator (dr.evomodel.coalescent.CoalescentSimulator)3 ArrayList (java.util.ArrayList)3 Taxon (dr.evolution.util.Taxon)2 TimeScale (dr.evolution.util.TimeScale)2 TreeModel (dr.evomodel.tree.TreeModel)2 XMLObject (dr.xml.XMLObject)2 XMLParseException (dr.xml.XMLParseException)2 DemographicFunction (dr.evolution.coalescent.DemographicFunction)1 NexusImporter (dr.evolution.io.NexusImporter)1 NodeRef (dr.evolution.tree.NodeRef)1 Units (dr.evolution.util.Units)1 DemographicModel (dr.evomodel.coalescent.DemographicModel)1 XMLUnits (dr.evoxml.util.XMLUnits)1 ParametricDistributionModel (dr.inference.distribution.ParametricDistributionModel)1 BufferedReader (java.io.BufferedReader)1