Search in sources :

Example 1 with BigFastTreeModel

use of dr.evomodel.bigfasttree.BigFastTreeModel in project beast-mcmc by beast-dev.

the class BigFastTreeModelParser method parseXMLObject.

/**
 * @return a tree object based on the XML element it was passed.
 */
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    Tree tree = (Tree) xo.getChild(Tree.class);
    boolean fixHeights = xo.getAttribute(FIX_HEIGHTS, false);
    boolean fixTree = xo.getAttribute(FIX_TREE, false);
    BigFastTreeModel treeModel = new BigFastTreeModel(xo.getId(), tree, fixHeights, fixTree);
    Logger.getLogger("dr.evomodel").info("\nCreating the big fast tree model, '" + xo.getId() + "'");
    // for (int i = 0; i < xo.getChildCount(); i++) {
    // if (xo.getChild(i) instanceof XMLObject) {
    // 
    // XMLObject cxo = (XMLObject) xo.getChild(i);
    // 
    // if (cxo.getName().equals(ROOT_HEIGHT)) {
    // 
    // ParameterParser.replaceParameter(cxo, treeModel.getRootHeightParameter());
    // 
    // } else if (cxo.getName().equals(LEAF_HEIGHT)) {
    // 
    // String taxonName;
    // if (cxo.hasAttribute(TAXON)) {
    // taxonName = cxo.getStringAttribute(TAXON);
    // } else {
    // throw new XMLParseException("taxa element missing from leafHeight element in treeModel element");
    // }
    // 
    // int index = treeModel.getTaxonIndex(taxonName);
    // if (index == -1) {
    // throw new XMLParseException("taxon " + taxonName + " not found for leafHeight element in treeModel element");
    // }
    // NodeRef node = treeModel.getExternalNode(index);
    // 
    // Parameter newParameter = treeModel.getLeafHeightParameter(node);
    // 
    // ParameterParser.replaceParameter(cxo, newParameter);
    // 
    // Taxon taxon = treeModel.getTaxon(index);
    // 
    // setUncertaintyBounds(newParameter, taxon);
    // 
    // } else if (cxo.getName().equals(LEAF_HEIGHTS)) {
    // // get a set of leaf height parameters out as a compound parameter...
    // 
    // TaxonList taxa = (TaxonList)cxo.getChild(TaxonList.class);
    // Parameter offsetParameter = (Parameter)cxo.getChild(Parameter.class);
    // 
    // CompoundParameter leafHeights = new CompoundParameter("leafHeights");
    // for (Taxon taxon : taxa) {
    // int index = treeModel.getTaxonIndex(taxon);
    // if (index == -1) {
    // throw new XMLParseException("taxon " + taxon.getId() + " not found for leafHeight element in treeModel element");
    // }
    // NodeRef node = treeModel.getExternalNode(index);
    // 
    // Parameter newParameter = treeModel.getLeafHeightParameter(node);
    // 
    // leafHeights.addParameter(newParameter);
    // 
    // setUncertaintyBounds(newParameter, taxon);
    // }
    // 
    // ParameterParser.replaceParameter(cxo, leafHeights);
    // 
    // } else if (cxo.getName().equals(NODE_HEIGHTS)) {
    // 
    // boolean rootNode = cxo.getAttribute(ROOT_NODE, false);
    // boolean internalNodes = cxo.getAttribute(INTERNAL_NODES, false);
    // boolean leafNodes = cxo.getAttribute(LEAF_NODES, false);
    // 
    // if (!rootNode && !internalNodes && !leafNodes) {
    // throw new XMLParseException("one or more of root, internal or leaf nodes must be selected for the nodeHeights element");
    // }
    // 
    // ParameterParser.replaceParameter(cxo, treeModel.createNodeHeightsParameter(rootNode, internalNodes, leafNodes));
    // 
    // } else {
    // throw new XMLParseException("illegal child element in " + getParserName() + ": " + cxo.getName());
    // }
    // 
    // } else if (xo.getChild(i) instanceof Tree) {
    // // do nothing - already handled
    // } else {
    // throw new XMLParseException("illegal child element in  " + getParserName() + ": " + xo.getChildName(i) + " " + xo.getChild(i));
    // }
    // }
    // Logger.getLogger("dr.evomodel").info("  initial tree topology = " + TreeUtils.uniqueNewick(treeModel, treeModel.getRoot()));
    Logger.getLogger("dr.evomodel").info("  taxon count = " + treeModel.getExternalNodeCount());
    Logger.getLogger("dr.evomodel").info("  tree height = " + treeModel.getNodeHeight(treeModel.getRoot()));
    return treeModel;
}
Also used : BigFastTreeModel(dr.evomodel.bigfasttree.BigFastTreeModel) Tree(dr.evolution.tree.Tree)

Example 2 with BigFastTreeModel

use of dr.evomodel.bigfasttree.BigFastTreeModel in project beast-mcmc by beast-dev.

the class BigFastTreeTreeIntervalsTest method testOrderChange.

// 0.5
// 1.0           +------ 0 * [1.5]
// +----------------------- |(7) *  [2]
// 1.0           |                        |                                             +-- 1 * [0]
// +----------------------- |(8) *  [3]              +---------------------------------------------|(6) [0.1]
// |                        |                                                                      +--- 2 * [0]
// |                        |                1.5
// |(10) &  [4]             +-------------------------------- 3 * [1.5]
// |                                                       2.0
// |        1.5                   +----------------------------------------------------- 4 & [0.5]
// +-----------------------------|(9) & [2.5]     1.51
// +-------------------------------------------- 5 & [0.99]
public void testOrderChange() throws TreeUtils.MissingTaxonException, IOException, Importer.ImportException {
    NewickImporter importer = new NewickImporter("(((0:0.5,(1:1.0,2:1.0)n6:1.0)n7:1.0,3:1.5)n8:1.0,(4:2.0,5:1.51)n9:1.5)n10;");
    tree = new BigFastTreeModel(importer.importTree(null));
    IntervalList bigFastIntervals = new BigFastTreeIntervals(tree);
    IntervalList intervals = new TreeIntervals(tree, null, null);
    bigFastIntervals.calculateIntervals();
    // node             1-2,6,  4  , 5  ,  0  ,  3, 7  , 9  , 8  , 10
    boolean pass = true;
    NodeRef parent = tree.getNode(6);
    NodeRef sibling = tree.getNode(2);
    NodeRef grandParent = tree.getParent(parent);
    NodeRef j = tree.getNode(2);
    tree.beginTreeEdit();
    tree.removeChild(grandParent, parent);
    tree.removeChild(parent, sibling);
    tree.addChild(grandParent, sibling);
    NodeRef jParent = tree.getParent(j);
    tree.removeChild(jParent, j);
    tree.addChild(jParent, parent);
    tree.addChild(parent, j);
    tree.setNodeHeight(parent, 0.1);
    tree.endTreeEdit();
    bigFastIntervals.calculateIntervals();
    List<Integer> missed = new ArrayList<>();
    for (int i = 0; i < bigFastIntervals.getIntervalCount(); i++) {
        if (bigFastIntervals.getInterval(i) != intervals.getInterval(i)) {
            System.out.println("expected: " + intervals.getInterval(i) + " got: " + bigFastIntervals.getInterval(i));
            missed.add(i);
        }
    }
    System.out.println(missed);
    assertEquals(0, missed.size());
}
Also used : NodeRef(dr.evolution.tree.NodeRef) BigFastTreeIntervals(dr.evomodel.bigfasttree.BigFastTreeIntervals) IntervalList(dr.evolution.coalescent.IntervalList) NewickImporter(dr.evolution.io.NewickImporter) BigFastTreeModel(dr.evomodel.bigfasttree.BigFastTreeModel) ArrayList(java.util.ArrayList) TreeIntervals(dr.evomodel.coalescent.TreeIntervals) BigFastTreeIntervals(dr.evomodel.bigfasttree.BigFastTreeIntervals)

Example 3 with BigFastTreeModel

use of dr.evomodel.bigfasttree.BigFastTreeModel in project beast-mcmc by beast-dev.

the class BigFastTreeTreeIntervalsTest method setUp.

public void setUp() throws Exception {
    NewickImporter importer = new NewickImporter("(((0:0.5,(1:1.0,2:1.0)n6:1.0)n7:1.0,3:1.5)n8:1.0,(4:2.0,5:1.51)n9:1.5)n10;");
    MathUtils.setSeed(7);
    tree = new BigFastTreeModel(importer.importTree(null));
}
Also used : NewickImporter(dr.evolution.io.NewickImporter) BigFastTreeModel(dr.evomodel.bigfasttree.BigFastTreeModel)

Example 4 with BigFastTreeModel

use of dr.evomodel.bigfasttree.BigFastTreeModel in project beast-mcmc by beast-dev.

the class ConstraintsTreeLikelihoodTest method testShouldThrowError.

public void testShouldThrowError() throws IOException, Importer.ImportException {
    NewickImporter importer = new NewickImporter("((1,2),3);");
    NewickImporter constraintsImporter = new NewickImporter("((1,2),4)");
    Tree tree = importer.importTree(null);
    Tree constraintsTree = constraintsImporter.importTree(null);
    targetTree = new BigFastTreeModel(tree);
    try {
        new ConstraintsTreeLikelihood("MYSTAT", targetTree, constraintsTree);
        fail("Missing exception");
    } catch (TreeUtils.MissingTaxonException e) {
        // Optionally make sure you get the correct message, too
        assertEquals("4", e.getMessage());
    }
}
Also used : ConstraintsTreeLikelihood(dr.evomodel.bigfasttree.constrainedtree.ConstraintsTreeLikelihood) NewickImporter(dr.evolution.io.NewickImporter) BigFastTreeModel(dr.evomodel.bigfasttree.BigFastTreeModel) Tree(dr.evolution.tree.Tree) TreeUtils(dr.evolution.tree.TreeUtils)

Example 5 with BigFastTreeModel

use of dr.evomodel.bigfasttree.BigFastTreeModel in project beast-mcmc by beast-dev.

the class RzhetskyNeiBranchLengthsTreeTrest method setUp.

// +------------------------------------------------ 0
// +----------------------- |
// |                        +------------------------------------------------ 1
// |
// +-------------------------------------------------------------------------------------------------- 2
public void setUp() throws Exception {
    super.setUp();
    MathUtils.setSeed(1);
    NewickImporter importer = new NewickImporter("((0:1,1:1):0.5,2:2);");
    timeTree = new BigFastTreeModel(importer.importTree(null));
    m = new DistanceMatrix(timeTree);
    m.setElement(0, 0, 0);
    m.setElement(0, 1, 2);
    m.setElement(0, 2, 3.5);
    m.setElement(1, 0, 2);
    m.setElement(1, 1, 0);
    m.setElement(1, 2, 3.5);
    m.setElement(2, 0, 3.5);
    m.setElement(2, 1, 3.5);
    m.setElement(2, 2, 0);
}
Also used : NewickImporter(dr.evolution.io.NewickImporter) BigFastTreeModel(dr.evomodel.bigfasttree.BigFastTreeModel) DistanceMatrix(dr.evolution.distance.DistanceMatrix)

Aggregations

BigFastTreeModel (dr.evomodel.bigfasttree.BigFastTreeModel)7 NewickImporter (dr.evolution.io.NewickImporter)6 Tree (dr.evolution.tree.Tree)4 ConstraintsTreeLikelihood (dr.evomodel.bigfasttree.constrainedtree.ConstraintsTreeLikelihood)2 IntervalList (dr.evolution.coalescent.IntervalList)1 DistanceMatrix (dr.evolution.distance.DistanceMatrix)1 NodeRef (dr.evolution.tree.NodeRef)1 TreeUtils (dr.evolution.tree.TreeUtils)1 BigFastTreeIntervals (dr.evomodel.bigfasttree.BigFastTreeIntervals)1 CladeNodeModel (dr.evomodel.bigfasttree.constrainedtree.CladeNodeModel)1 TreeIntervals (dr.evomodel.coalescent.TreeIntervals)1 TreeModel (dr.evomodel.tree.TreeModel)1 ArrayList (java.util.ArrayList)1