Search in sources :

Example 91 with NodeRef

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

the class TMRCASummaryStatistic method getSummaryStatistic.

public double[] getSummaryStatistic(Tree tree) {
    if (taxonList == null) {
        return new double[] { tree.getNodeHeight(tree.getRoot()) };
    }
    try {
        Set<String> leafSet = TreeUtils.getLeavesForTaxa(tree, taxonList);
        NodeRef node = TreeUtils.getCommonAncestorNode(tree, leafSet);
        if (node == null)
            throw new RuntimeException("No node found that is MRCA of " + leafSet);
        return new double[] { tree.getNodeHeight(node) };
    } catch (TreeUtils.MissingTaxonException e) {
        throw new RuntimeException("Missing taxon!");
    }
}
Also used : NodeRef(dr.evolution.tree.NodeRef) TreeUtils(dr.evolution.tree.TreeUtils)

Example 92 with NodeRef

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

the class TreeLength method getSummaryStatistic.

public double[] getSummaryStatistic(Tree tree) {
    double externalLength = 0.0;
    double internalLength = 0.0;
    int externalNodeCount = tree.getExternalNodeCount();
    for (int i = 0; i < externalNodeCount; i++) {
        NodeRef node = tree.getExternalNode(i);
        externalLength += tree.getBranchLength(node);
    }
    int internalNodeCount = tree.getInternalNodeCount();
    for (int i = 0; i < internalNodeCount; i++) {
        NodeRef node = tree.getInternalNode(i);
        if (!tree.isRoot(node)) {
            internalLength += tree.getBranchLength(node);
        }
    }
    return new double[] { internalLength + externalLength };
}
Also used : NodeRef(dr.evolution.tree.NodeRef)

Example 93 with NodeRef

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

the class RankProportionStatistic method getSummaryStatistic.

public double[] getSummaryStatistic(Tree tree) {
    double externalLength = 0.0;
    double internalLength = 0.0;
    double rankLength = 0.0;
    int externalNodeCount = tree.getExternalNodeCount();
    for (int i = 0; i < externalNodeCount; i++) {
        NodeRef node = tree.getExternalNode(i);
        NodeRef parent = tree.getParent(node);
        externalLength += tree.getNodeHeight(parent) - tree.getNodeHeight(node);
    }
    int internalNodeCount = tree.getInternalNodeCount();
    for (int i = 0; i < internalNodeCount; i++) {
        NodeRef node = tree.getInternalNode(i);
        if (!tree.isRoot(node)) {
            NodeRef parent = tree.getParent(node);
            internalLength += tree.getNodeHeight(parent) - tree.getNodeHeight(node);
        }
    }
    if (rank == 1) {
        if (!proportion) {
            return new double[] { externalLength };
        }
        return new double[] { externalLength / (internalLength + externalLength) };
    }
    for (int i = 0; i < internalNodeCount; i++) {
        NodeRef node = tree.getInternalNode(i);
        if (!tree.isRoot(node)) {
            int r = getRank(tree, node);
            if (r == rank) {
                NodeRef parent = tree.getParent(node);
                rankLength += tree.getNodeHeight(parent) - tree.getNodeHeight(node);
            }
        }
    }
    if (!proportion)
        return new double[] { rankLength };
    return new double[] { rankLength / (internalLength + externalLength) };
}
Also used : NodeRef(dr.evolution.tree.NodeRef)

Example 94 with NodeRef

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

the class InternalNodeAttribute method getSummaryStatistic.

public double[] getSummaryStatistic(Tree tree) {
    int internalNodeCount = tree.getInternalNodeCount();
    double[] stats = new double[internalNodeCount - 1];
    int count = 0;
    for (int i = 0; i < internalNodeCount; i++) {
        NodeRef node = tree.getInternalNode(i);
        if (!tree.isRoot(node)) {
            stats[count++] = (Double) tree.getNodeAttribute(node, attributeName);
        }
    }
    return stats;
}
Also used : NodeRef(dr.evolution.tree.NodeRef)

Example 95 with NodeRef

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

the class TreeClusterAlgorithmOperator method findActiveBreakpointsChildren.

private LinkedList<Integer> findActiveBreakpointsChildren(int selectedNodeNumber) {
    //a list of breakpoints...
    LinkedList<Integer> linkedList = new LinkedList<Integer>();
    int[] nodeBreakpointNumber = new int[numNodes];
    //int[] nodeStatus = new int[numNodes];
    //for(int i=0; i < numNodes; i ++){
    //	nodeStatus[i] = -1;
    //}
    //convert to easy process format.
    //for(int i=0; i < (binSize ); i++){
    //	if((int) indicators.getParameterValue(i) ==1){
    //		  nodeStatus[(int)breakPoints.getParameterValue(i)] = i;
    //	}
    //}
    //process the tree and get the vLoc of the viruses..
    //breadth first depth first..
    NodeRef cNode = treeModel.getRoot();
    LinkedList<NodeRef> visitlist = new LinkedList<NodeRef>();
    visitlist.add(cNode);
    //I am not sure if it still works......
    int countProcessed = 0;
    while (visitlist.size() > 0) {
        countProcessed++;
        //assign value to the current node...
        if (treeModel.getParent(cNode) == null) {
            //Parameter curMu = mu.getParameter(0);
            nodeBreakpointNumber[cNode.getNumber()] = cNode.getNumber();
        } else {
            nodeBreakpointNumber[cNode.getNumber()] = nodeBreakpointNumber[treeModel.getParent(cNode).getNumber()];
            if ((int) indicators.getParameterValue(cNode.getNumber()) == 1) {
                //see if parent's status is the same as the selectedIndex
                if (nodeBreakpointNumber[cNode.getNumber()] == selectedNodeNumber) {
                    //System.out.println("hihi");
                    linkedList.add(cNode.getNumber());
                }
                //now, replace this nodeBreakpointNumber with its own node number
                nodeBreakpointNumber[cNode.getNumber()] = cNode.getNumber();
            }
        }
        //add all the children to the queue
        for (int childNum = 0; childNum < treeModel.getChildCount(cNode); childNum++) {
            NodeRef node = treeModel.getChild(cNode, childNum);
            visitlist.add(node);
        }
        //now that we have finished visiting this node, pops it out of the queue
        visitlist.pop();
        if (visitlist.size() > 0) {
            //set the new first node in the queue to visit
            cNode = visitlist.getFirst();
        }
    }
    return linkedList;
}
Also used : NodeRef(dr.evolution.tree.NodeRef) LinkedList(java.util.LinkedList)

Aggregations

NodeRef (dr.evolution.tree.NodeRef)426 ArrayList (java.util.ArrayList)38 LinkedList (java.util.LinkedList)20 Taxon (dr.evolution.util.Taxon)18 Tree (dr.evolution.tree.Tree)14 TreeModel (dr.evomodel.tree.TreeModel)14 Parameter (dr.inference.model.Parameter)14 Clade (dr.evolution.tree.Clade)13 MutableTree (dr.evolution.tree.MutableTree)9 Node (dr.evomodel.arg.ARGModel.Node)9 MultivariateTraitTree (dr.evolution.tree.MultivariateTraitTree)8 BranchMapModel (dr.evomodel.epidemiology.casetocase.BranchMapModel)8 BitSet (java.util.BitSet)8 FixedBitSet (jebl.util.FixedBitSet)8 FlexibleTree (dr.evolution.tree.FlexibleTree)7 AbstractCase (dr.evomodel.epidemiology.casetocase.AbstractCase)7 Matrix (dr.math.matrixAlgebra.Matrix)6 CompoundParameter (dr.inference.model.CompoundParameter)5 TimeScale (dr.evolution.util.TimeScale)4 MicrosatelliteSamplerTreeModel (dr.evomodel.tree.MicrosatelliteSamplerTreeModel)4