Search in sources :

Example 1 with SimpleNode

use of dr.evolution.tree.SimpleNode in project beast-mcmc by beast-dev.

the class SimpleTreeParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    Units.Type units = XMLUnits.Utils.getUnitsAttr(xo);
    boolean usingDates = xo.getAttribute(USING_DATES, false);
    SimpleNode root = (SimpleNode) xo.getChild(SimpleNode.class);
    if (root == null) {
        throw new XMLParseException("node element missing from tree");
    }
    SimpleTree tree = new SimpleTree(root);
    if (usingDates) {
        dr.evolution.util.Date mostRecent = null;
        for (int i = 0; i < tree.getTaxonCount(); i++) {
            dr.evolution.util.Date date = (dr.evolution.util.Date) tree.getTaxonAttribute(i, DATE);
            if (date == null) {
                date = (dr.evolution.util.Date) tree.getNodeAttribute(tree.getExternalNode(i), DATE);
            }
            if (date != null && ((mostRecent == null) || date.after(mostRecent))) {
                mostRecent = date;
            }
        }
        for (int i = 0; i < tree.getInternalNodeCount(); i++) {
            dr.evolution.util.Date date = (dr.evolution.util.Date) tree.getNodeAttribute(tree.getInternalNode(i), DATE);
            if (date != null && ((mostRecent == null) || date.after(mostRecent))) {
                mostRecent = date;
            }
        }
        if (mostRecent == null) {
            throw new XMLParseException("no date elements in tree (and usingDates attribute set)");
        }
        TimeScale timeScale = new TimeScale(mostRecent.getUnits(), true, mostRecent.getAbsoluteTimeValue());
        for (int i = 0; i < tree.getTaxonCount(); i++) {
            dr.evolution.util.Date date = (dr.evolution.util.Date) tree.getTaxonAttribute(i, DATE);
            if (date == null) {
                date = (dr.evolution.util.Date) tree.getNodeAttribute(tree.getExternalNode(i), DATE);
            }
            if (date != null) {
                double height = timeScale.convertTime(date.getTimeValue(), date);
                tree.setNodeHeight(tree.getExternalNode(i), height);
            }
        }
        for (int i = 0; i < tree.getInternalNodeCount(); i++) {
            dr.evolution.util.Date date = (dr.evolution.util.Date) tree.getNodeAttribute(tree.getInternalNode(i), DATE);
            if (date != null) {
                double height = timeScale.convertTime(date.getTimeValue(), date);
                tree.setNodeHeight(tree.getInternalNode(i), height);
            }
        }
        MutableTree.Utils.correctHeightsForTips(tree);
    }
    tree.setUnits(units);
    return tree;
}
Also used : SimpleTree(dr.evolution.tree.SimpleTree) TimeScale(dr.evolution.util.TimeScale) Units(dr.evolution.util.Units) XMLUnits(dr.evoxml.util.XMLUnits) SimpleNode(dr.evolution.tree.SimpleNode)

Example 2 with SimpleNode

use of dr.evolution.tree.SimpleNode in project beast-mcmc by beast-dev.

the class TestCalibratedYuleModel method calibration.

private Tree calibration(final TaxonList taxa, DemographicModel demoModel) throws Exception {
    dr.evolution.coalescent.CoalescentSimulator simulator = new dr.evolution.coalescent.CoalescentSimulator();
    DemographicFunction demoFunction = demoModel.getDemographicFunction();
    SimpleNode[] firstHalfNodes = new SimpleNode[taxa.getTaxonCount() / 2];
    SimpleNode[] secondHalfNodes = new SimpleNode[taxa.getTaxonCount() - taxa.getTaxonCount() / 2];
    for (int i = 0; i < firstHalfNodes.length; i++) {
        firstHalfNodes[i] = new SimpleNode();
        firstHalfNodes[i].setTaxon(taxa.getTaxon(i));
    }
    for (int i = 0; i < secondHalfNodes.length; i++) {
        secondHalfNodes[i] = new SimpleNode();
        secondHalfNodes[i].setTaxon(taxa.getTaxon(i + taxa.getTaxonCount() / 2));
    }
    SimpleNode firstHalfRootNode = simulator.simulateCoalescent(firstHalfNodes, demoFunction);
    SimpleNode[] restNodes = simulator.simulateCoalescent(secondHalfNodes, demoFunction, 0, firstHalfRootNode.getHeight());
    SimpleNode[] together = new SimpleNode[restNodes.length + 1];
    for (int i = 0; i < restNodes.length; i++) {
        together[i + 1] = restNodes[i];
    }
    together[0] = firstHalfRootNode;
    SimpleNode root = simulator.simulateCoalescent(together, demoFunction);
    Tree tree = new SimpleTree(root);
    return tree;
}
Also used : DemographicFunction(dr.evolution.coalescent.DemographicFunction) SimpleTree(dr.evolution.tree.SimpleTree) Tree(dr.evolution.tree.Tree) SimpleTree(dr.evolution.tree.SimpleTree) SimpleNode(dr.evolution.tree.SimpleNode)

Example 3 with SimpleNode

use of dr.evolution.tree.SimpleNode in project beast-mcmc by beast-dev.

the class TraceCorrelationAssert method createPrimateTreeModel.

// ************************** data ****************************
protected TreeModel createPrimateTreeModel() {
    SimpleNode[] nodes = new SimpleNode[10];
    for (int n = 0; n < 10; n++) {
        nodes[n] = new SimpleNode();
    }
    // nodes[0].setHeight(0);
    // human
    nodes[0].setTaxon(taxa[0]);
    // chimp
    nodes[1].setTaxon(taxa[1]);
    // bonobo
    nodes[2].setTaxon(taxa[2]);
    nodes[3].setHeight(0.010772);
    nodes[3].addChild(nodes[1]);
    nodes[3].addChild(nodes[2]);
    nodes[4].setHeight(0.024003);
    nodes[4].addChild(nodes[0]);
    nodes[4].addChild(nodes[3]);
    // gorilla
    nodes[5].setTaxon(taxa[3]);
    nodes[6].setHeight(0.036038);
    nodes[6].addChild(nodes[4]);
    nodes[6].addChild(nodes[5]);
    // orangutan
    nodes[7].setTaxon(taxa[4]);
    nodes[8].setHeight(0.069125);
    nodes[8].addChild(nodes[6]);
    nodes[8].addChild(nodes[7]);
    // siamang
    nodes[9].setTaxon(taxa[5]);
    SimpleNode root = new SimpleNode();
    root.setHeight(0.099582);
    root.addChild(nodes[8]);
    root.addChild(nodes[9]);
    Tree tree = new SimpleTree(root);
    tree.setUnits(Units.Type.YEARS);
    // treeModel
    return new DefaultTreeModel(tree);
}
Also used : SimpleTree(dr.evolution.tree.SimpleTree) Tree(dr.evolution.tree.Tree) DefaultTreeModel(dr.evomodel.tree.DefaultTreeModel) SimpleTree(dr.evolution.tree.SimpleTree) SimpleNode(dr.evolution.tree.SimpleNode)

Example 4 with SimpleNode

use of dr.evolution.tree.SimpleNode in project beast-mcmc by beast-dev.

the class NormalizedSequenceLikelihoodTest method createSillyTreeModel.

protected TreeModel createSillyTreeModel(int numTaxa) {
    SimpleNode[] nodes = new SimpleNode[2 * numTaxa - 1];
    for (int n = 0; n < 2 * numTaxa - 1; n++) {
        nodes[n] = new SimpleNode();
    }
    nodes[0].setTaxon(taxa[0]);
    nodes[1].setTaxon(taxa[1]);
    nodes[2].setHeight(1);
    nodes[2].addChild(nodes[0]);
    nodes[2].addChild(nodes[1]);
    SimpleNode root = nodes[2];
    if (numTaxa == 3) {
        nodes[3].setTaxon(taxa[2]);
        nodes[4].setHeight(2);
        nodes[4].addChild(nodes[2]);
        nodes[4].addChild(nodes[3]);
        root = nodes[4];
    }
    Tree tree = new SimpleTree(root);
    tree.setUnits(Units.Type.YEARS);
    // treeModel
    return new DefaultTreeModel(tree);
}
Also used : Tree(dr.evolution.tree.Tree) SimpleTree(dr.evolution.tree.SimpleTree) DefaultTreeModel(dr.evomodel.tree.DefaultTreeModel) SimpleTree(dr.evolution.tree.SimpleTree) SimpleNode(dr.evolution.tree.SimpleNode)

Example 5 with SimpleNode

use of dr.evolution.tree.SimpleNode in project beast-mcmc by beast-dev.

the class SimpleNodeParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    SimpleNode node = new SimpleNode();
    Taxon taxon = null;
    if (xo.hasAttribute(HEIGHT)) {
        node.setHeight(xo.getDoubleAttribute(HEIGHT));
    }
    if (xo.hasAttribute(RATE)) {
        node.setRate(xo.getDoubleAttribute(RATE));
    }
    for (int i = 0; i < xo.getChildCount(); i++) {
        Object child = xo.getChild(i);
        if (child instanceof dr.evolution.tree.SimpleNode) {
            node.addChild((dr.evolution.tree.SimpleNode) child);
        } else if (child instanceof Taxon) {
            taxon = (Taxon) child;
        } else if (child instanceof Date) {
            node.setAttribute("date", child);
        } else if (child instanceof Attribute) {
            Attribute attr = (Attribute) child;
            String name = attr.getAttributeName();
            Object value = attr.getAttributeValue();
            node.setAttribute(name, value);
        } else if (child instanceof Attribute[]) {
            Attribute[] attrs = (Attribute[]) child;
            for (int j = 0; j < attrs.length; j++) {
                String name = attrs[j].getAttributeName();
                Object value = attrs[j].getAttributeValue();
                node.setAttribute(name, value);
            }
        } else if (child instanceof XMLObject) {
            XMLObject xoc = (XMLObject) child;
            if (xoc.getName().equals(Attributable.ATTRIBUTE)) {
                node.setAttribute(xoc.getStringAttribute(Attributable.NAME), xoc.getAttribute(Attributable.VALUE));
            } else {
                throw new XMLParseException("Unrecognized element" + xoc.getName() + " found in node element!");
            }
        } else {
            throw new XMLParseException("Unrecognized element found in node element!");
        }
    }
    if (taxon != null) {
        node.setTaxon(taxon);
    }
    return node;
}
Also used : Attribute(dr.util.Attribute) Taxon(dr.evolution.util.Taxon) Date(dr.evolution.util.Date) SimpleNode(dr.evolution.tree.SimpleNode)

Aggregations

SimpleNode (dr.evolution.tree.SimpleNode)8 SimpleTree (dr.evolution.tree.SimpleTree)7 Tree (dr.evolution.tree.Tree)3 Taxon (dr.evolution.util.Taxon)2 TimeScale (dr.evolution.util.TimeScale)2 DefaultTreeModel (dr.evomodel.tree.DefaultTreeModel)2 DemographicFunction (dr.evolution.coalescent.DemographicFunction)1 NodeRef (dr.evolution.tree.NodeRef)1 Date (dr.evolution.util.Date)1 TaxonList (dr.evolution.util.TaxonList)1 Units (dr.evolution.util.Units)1 XMLUnits (dr.evoxml.util.XMLUnits)1 Attribute (dr.util.Attribute)1