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!");
}
}
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 };
}
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) };
}
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;
}
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;
}
Aggregations