Search in sources :

Example 1 with MutableTree

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

the class LogCombiner method rescaleTree.

private void rescaleTree(Tree tree, double scale) {
    if (tree instanceof MutableTree) {
        MutableTree mutableTree = (MutableTree) tree;
        for (int i = 0; i < tree.getNodeCount(); i++) {
            NodeRef node = tree.getNode(i);
            if (node != tree.getRoot()) {
                double length = tree.getBranchLength(node);
                mutableTree.setBranchLength(node, length * scale);
            }
        }
    } else {
        throw new IllegalArgumentException("Tree not mutable");
    }
}
Also used : MutableTree(dr.evolution.tree.MutableTree) NodeRef(dr.evolution.tree.NodeRef)

Example 2 with MutableTree

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

the class SimulateTrait method simulate.

/**
	 * simulates a trait ona tree.
	 * @param clone if true, use copy of the tree, otherwise use given tree
	 * @return the simulated tree.
	 */
public Tree simulate(Tree tree, double value, boolean clone) {
    Tree binaryTree = null;
    if (clone) {
        binaryTree = new FlexibleTree(tree);
        ((FlexibleTree) binaryTree).resolveTree();
    } else {
        binaryTree = tree;
    }
    simulate((MutableTree) binaryTree, binaryTree.getRoot(), value);
    return binaryTree;
}
Also used : FlexibleTree(dr.evolution.tree.FlexibleTree) FlexibleTree(dr.evolution.tree.FlexibleTree) Tree(dr.evolution.tree.Tree) MutableTree(dr.evolution.tree.MutableTree)

Example 3 with MutableTree

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

the class MulSpeciesBindings method makeCompatible.

// jh
public void makeCompatible(double rootHeight) {
    for (GeneTreeInfo t : getGeneTrees()) {
        MutableTree tree = t.tree;
        for (int i = 0; i < tree.getExternalNodeCount(); i++) {
            final NodeRef node = tree.getExternalNode(i);
            final NodeRef p = tree.getParent(node);
            tree.setNodeHeight(p, rootHeight + tree.getNodeHeight(p));
        }
        MutableTree.Utils.correctHeightsForTips(tree);
        // (todo) ugly re-init - can I do something better?
        t.wasChanged();
        t.getCoalInfo();
        t.wasBacked = false;
    //t.wasChanged();
    }
}
Also used : MutableTree(dr.evolution.tree.MutableTree) NodeRef(dr.evolution.tree.NodeRef)

Example 4 with MutableTree

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

the class SpeciesBindings method makeCompatible.

public void makeCompatible(double rootHeight) {
    for (GeneTreeInfo t : getGeneTrees()) {
        MutableTree tree = t.tree;
        for (int i = 0; i < tree.getExternalNodeCount(); i++) {
            final NodeRef node = tree.getExternalNode(i);
            final NodeRef p = tree.getParent(node);
            tree.setNodeHeight(p, rootHeight + tree.getNodeHeight(p));
        }
        MutableTree.Utils.correctHeightsForTips(tree);
        // (todo) ugly re-init - can I do something better?
        t.wasChanged();
        t.getCoalInfo();
        t.wasBacked = false;
    //t.wasChanged();
    }
}
Also used : MutableTree(dr.evolution.tree.MutableTree) NodeRef(dr.evolution.tree.NodeRef)

Example 5 with MutableTree

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

the class MigrateTreeImporter method importTrees.

public Tree[] importTrees(TaxonList taxonList) throws IOException, ImportException {
    Tree[] trees = super.importTrees(taxonList);
    for (Tree tree : trees) {
        // convert toPops to pops
        for (int i = 0; i < tree.getNodeCount(); i++) {
            NodeRef node = tree.getNode(i);
            Object toPop = tree.getNodeAttribute(node, TO_POP);
            Object pop = tree.getNodeAttribute(node, POP);
            if (toPop != null && pop != null && !toPop.equals(pop)) {
                String nodeName = node.getNumber() + "";
                if (tree.isExternal(node)) {
                    nodeName = tree.getTaxonId(node.getNumber());
                }
                if (tree.isRoot(node))
                    nodeName = "root";
                throw new RuntimeException(TO_POP + " = " + toPop + ", " + POP + " = " + pop + " in node " + nodeName);
            }
            if (pop == null && toPop != null) {
                ((MutableTree) tree).setNodeAttribute(node, POP, toPop);
            }
        }
        // convert fromPops to pops
        for (int i = 0; i < tree.getNodeCount(); i++) {
            NodeRef node = tree.getNode(i);
            if (!tree.isRoot(node)) {
                NodeRef parent = tree.getParent(node);
                Object fromPop = tree.getNodeAttribute(node, FROM_POP);
                Object pop = tree.getNodeAttribute(parent, POP);
                if (fromPop != null && pop != null && !fromPop.equals(pop)) {
                    throw new RuntimeException(FROM_POP + " = " + fromPop + ", " + POP + " = " + pop);
                }
                if (pop == null && fromPop != null) {
                    ((MutableTree) tree).setNodeAttribute(parent, POP, fromPop);
                }
            }
        }
        // fill gaps with parent pops
        fillInternalGaps(tree, tree.getRoot());
        fillExternalGaps(tree);
    }
    return trees;
}
Also used : MutableTree(dr.evolution.tree.MutableTree) NodeRef(dr.evolution.tree.NodeRef) Tree(dr.evolution.tree.Tree) MutableTree(dr.evolution.tree.MutableTree)

Aggregations

MutableTree (dr.evolution.tree.MutableTree)5 NodeRef (dr.evolution.tree.NodeRef)4 Tree (dr.evolution.tree.Tree)2 FlexibleTree (dr.evolution.tree.FlexibleTree)1