本文整理汇总了Java中beast.evolution.tree.Tree.getNodeCount方法的典型用法代码示例。如果您正苦于以下问题:Java Tree.getNodeCount方法的具体用法?Java Tree.getNodeCount怎么用?Java Tree.getNodeCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类beast.evolution.tree.Tree
的用法示例。
在下文中一共展示了Tree.getNodeCount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: proposal
import beast.evolution.tree.Tree; //导入方法依赖的package包/类
/**
* change the parameter and return the hastings ratio.
*
* @return log of Hastings Ratio, or Double.NEGATIVE_INFINITY if proposal should not be accepted *
*/
@Override
public double proposal() {
final Tree tree = treeInput.get(this);
// randomly select internal node
final int nodeCount = tree.getNodeCount();
// Abort if no non-root internal nodes
if (tree.getInternalNodeCount()==1)
return Double.NEGATIVE_INFINITY;
Node node;
do {
final int nodeNr = nodeCount / 2 + 1 + Randomizer.nextInt(nodeCount / 2);
node = tree.getNode(nodeNr);
} while (node.isRoot() || node.isLeaf());
final double upper = node.getParent().getHeight();
final double lower = Math.max(node.getLeft().getHeight(), node.getRight().getHeight());
final double newValue = (Randomizer.nextDouble() * (upper - lower)) + lower;
node.setHeight(newValue);
return 0.0;
}
示例2: setupAttributes
import beast.evolution.tree.Tree; //导入方法依赖的package包/类
private void setupAttributes(Tree tree) {
for (int i = 0; i < tree.getNodeCount(); i++) {
Node node = tree.getNode(i);
Set<String> iter = node.getMetaDataNames();
if (iter != null) {
for (String name : iter) {
attributeNames.add(name);
}
}
}
for (TreeAnnotationPlugin beastObject : beastObjects) {
Set<String> claimed = beastObject.setAttributeNames(attributeNames);
attributeNames.removeAll(claimed);
}
}
示例3: proposal
import beast.evolution.tree.Tree; //导入方法依赖的package包/类
/**
* change the parameter and return the hastings ratio.
*
* @return log of Hastings Ratio, or Double.NEGATIVE_INFINITY if proposal should not be accepted *
*/
@Override
public double proposal() {
final Tree tree = treeInput.get(this);
final int nNodeCount = tree.getNodeCount();
int leafNodeCount = tree.getLeafNodeCount();
//make sure that there is at least one non-fake and non-root internal node
int fakeNodeCount = ((ZeroBranchSATree)tree).getDirectAncestorNodeCount();
if (fakeNodeCount == leafNodeCount-1 || (fakeNodeCount == leafNodeCount-2 && !((ZeroBranchSANode)tree.getRoot()).isFake())) {
return Double.NEGATIVE_INFINITY;
}
// randomly select internal node
Node node;
do {
node = tree.getNode(leafNodeCount + Randomizer.nextInt(nNodeCount / 2));
} while (node.isRoot() || ((ZeroBranchSANode)node).isFake());
final double fUpper = node.getParent().getHeight();
final double fLower = Math.max(node.getLeft().getHeight(), node.getRight().getHeight());
final double newValue = (Randomizer.nextDouble() * (fUpper - fLower)) + fLower;
node.setHeight(newValue);
return 0.0;
}
示例4: proposal
import beast.evolution.tree.Tree; //导入方法依赖的package包/类
/**
* change the parameter and return the hastings ratio.
*
* @return log of Hastings Ratio, or Double.NEGATIVE_INFINITY if proposal should not be accepted *
*/
@Override
public double proposal() {
final Tree tree = treeInput.get(this);
final int nNodeCount = tree.getNodeCount();
int leafNodeCount = tree.getLeafNodeCount();
//make sure that there is at least one non-fake and non-root internal node
int fakeNodeCount = tree.getDirectAncestorNodeCount();
if (fakeNodeCount == leafNodeCount-1 || (fakeNodeCount == leafNodeCount-2 && !tree.getRoot().isFake())) {
return Double.NEGATIVE_INFINITY;
}
// randomly select internal node
Node node;
do {
node = tree.getNode(leafNodeCount + Randomizer.nextInt(nNodeCount / 2));
} while (node.isRoot() || node.isFake());
final double fUpper = node.getParent().getHeight();
final double fLower = Math.max(node.getLeft().getHeight(), node.getRight().getHeight());
final double newValue = (Randomizer.nextDouble() * (fUpper - fLower)) + fLower;
node.setHeight(newValue);
return 0.0;
}
示例5: makeTreeSummaryForAllTrees
import beast.evolution.tree.Tree; //导入方法依赖的package包/类
private SATreeComparingAnalysis.TreeSummary[] makeTreeSummaryForAllTrees(List<Tree> trees, int treeCount){
SATreeComparingAnalysis.TreeSummary[] treeSummary = new TreeSummary[treeCount];
for(int treeIndex=0; treeIndex < treeCount; treeIndex++) {
Tree tree = trees.get(treeIndex);
ArrayList<Integer> dAPattern = new ArrayList<Integer>();
for (int i=tree.getLeafNodeCount(); i< tree.getNodeCount(); i++){
if (((ZeroBranchSANode)tree.getNode(i)).isFake()) {
int descendantsCount = tree.getNode(i).getLeafNodeCount() - 1;
if (descendantsCount > 0) {
for(int j=dAPattern.size(); j<descendantsCount; j++){
dAPattern.add(0);
}
int tmp = dAPattern.get(descendantsCount-1);
tmp++;
dAPattern.set(descendantsCount - 1, tmp);
}
}
}
treeSummary[treeIndex] = new TreeSummary(tree.getRoot().getHeight(), tree.getLeafNodeCount() - ((ZeroBranchSATree)tree).getDirectAncestorNodeCount(), dAPattern);
}
return treeSummary;
}
示例6: countTreesWithDClades
import beast.evolution.tree.Tree; //导入方法依赖的package包/类
public void countTreesWithDClades() throws Exception {
int dCladeCount = 0;
Tree tree;
for (int i =0; i < trace.treeCount; i++) {
tree = trace.beastTrees.get(i);
int j;
for (j=0; j<tree.getNodeCount(); j++)
if (tree.getNode(j).getChildCount() == 1) {
dCladeCount++;
break;
}
}
double a = (double)dCladeCount/trace.treeCount;
System.out.format(dCladeCount + " trees (or %2.2f%%) have sampled internal nodes.%n", a*100);
System.out.println();
}
示例7: printTreeHeights
import beast.evolution.tree.Tree; //导入方法依赖的package包/类
public void printTreeHeights(){
Tree tree;
System.out.print("heights <- c(");
for (int i =0; i < trace.treeCount-1; i++) {
tree = trace.beastTrees.get(i);
System.out.print(tree.getRoot().getHeight() + ",");
}
tree = trace.beastTrees.get(trace.treeCount-1);
System.out.println(tree.getRoot().getHeight() + ")");
System.out.print("lengths <- c(");
for (int i =0; i < trace.treeCount-1; i++) {
tree = trace.beastTrees.get(i);
double length = 0;
for (int j=0; j< tree.getNodeCount(); j++){
length += tree.getNode(j).getLength();
}
System.out.print(length + ",");
}
tree = trace.beastTrees.get(trace.treeCount-1);
System.out.println(tree.getRoot().getHeight() + ")");
}
示例8: wide
import beast.evolution.tree.Tree; //导入方法依赖的package包/类
/**
* @param tree
*/
public double wide(final Tree tree) {
final int nodeCount = tree.getNodeCount();
//make sure that there are at least two distinct non-root nodes which are not direct ancestors.
if (nodeCount == 3 && (tree.getRoot()).isFake()) {
return Double.NEGATIVE_INFINITY;
}
Node i, j, iP, jP;
do {
i = tree.getNode(Randomizer.nextInt(nodeCount));
} while (i.isRoot() || (i).isDirectAncestor());
do {
j = tree.getNode(Randomizer.nextInt(nodeCount));
} while (j.getNr() == i.getNr() || j.isRoot() || (j).isDirectAncestor());
iP = i.getParent();
jP = j.getParent();
if ((iP != jP) && (i != jP) && (j != iP)
&& (j.getHeight() < iP.getHeight())
&& (i.getHeight() < jP.getHeight())) {
exchangeNodes(i, j, iP, jP);
return 0.0;
}
// Couldn't find valid wide move on this beast.tree!
return Double.NEGATIVE_INFINITY;
}
示例9: wide
import beast.evolution.tree.Tree; //导入方法依赖的package包/类
/**
* @param tree
*/
public double wide(final Tree tree) {
final int nodeCount = tree.getNodeCount();
//make sure that there are at least two distinct non-root nodes which are not direct ancestors.
if (nodeCount == 3 && ((ZeroBranchSANode)tree.getRoot()).isFake()) {
return Double.NEGATIVE_INFINITY;
}
Node i, j, iP, jP;
do {
i = tree.getNode(Randomizer.nextInt(nodeCount));
} while (i.isRoot() || ((ZeroBranchSANode)i).isDirectAncestor());
do {
j = tree.getNode(Randomizer.nextInt(nodeCount));
} while (j.getNr() == i.getNr() || j.isRoot() || ((ZeroBranchSANode)j).isDirectAncestor());
iP = i.getParent();
jP = j.getParent();
if ((iP != jP) && (i != jP) && (j != iP)
&& (j.getHeight() < iP.getHeight())
&& (i.getHeight() < jP.getHeight())) {
exchangeNodes(i, j, iP, jP);
return 0.0;
}
// Couldn't find valid wide move on this beast.tree!
return Double.NEGATIVE_INFINITY;
}
示例10: countSampledAncestors
import beast.evolution.tree.Tree; //导入方法依赖的package包/类
/**
* print the number of sampled ancestor in each tree
*
* @param zeroBranchTrees
*/
public void countSampledAncestors(boolean zeroBranchTrees){
Tree tree;
int sAcount;
int totalsAcount = 0;
if (zeroBranchTrees) {
//System.out.println("Sample \t Prior \t Posterior");
for (int i =0; i < trace.treeCount-1; i++) {
tree = trace.beastTrees.get(i);
sAcount=0;
for (int j=0; j<tree.getNodeCount(); j++) {
if (((ZeroBranchSANode)tree.getNode(j)).isFake()) sAcount++;
}
totalsAcount += sAcount;
//System.out.println(i + "\t" + sAcount + "\t" + Randomizer.nextDouble());
}
tree = trace.beastTrees.get(trace.treeCount-1);
sAcount=0;
for (int j=0; j<tree.getNodeCount(); j++) {
if (((ZeroBranchSANode)tree.getNode(j)).isFake()) sAcount++;
}
totalsAcount += sAcount;
//System.out.println(trace.treeCount-1 + "\t" + sAcount + "\t" + Randomizer.nextDouble());
System.out.format("The average number of sampled ancestors per tree is %2.2f", ((double) totalsAcount / trace.treeCount));
System.out.println();
}
}
示例11: collectTimes
import beast.evolution.tree.Tree; //导入方法依赖的package包/类
/**
* extract coalescent times and tip information into array times from tree.
*/
private static void collectTimes(Tree tree, double[] times, int[] childCounts) {
for (int i = 0; i < tree.getNodeCount(); i++) {
NodeRef node = tree.getNode(i);
times[i] = tree.getNodeHeight(node);
childCounts[i] = tree.getChildCount(node);
}
}
示例12: AbstractCoalescentLikelihood
import beast.evolution.tree.Tree; //导入方法依赖的package包/类
public AbstractCoalescentLikelihood(
String name,
Tree tree,
TaxonList includeSubtree,
List<TaxonList> excludeSubtrees) throws Tree.MissingTaxonException {
super(name);
this.tree = tree;
if (includeSubtree != null) {
includedLeafSet = Tree.Utils.getLeavesForTaxa(tree, includeSubtree);
} else {
includedLeafSet = null;
}
if (excludeSubtrees != null) {
excludedLeafSets = new Set[excludeSubtrees.size()];
for (int i = 0; i < excludeSubtrees.size(); i++) {
excludedLeafSets[i] = Tree.Utils.getLeavesForTaxa(tree, excludeSubtrees.get(i));
}
} else {
excludedLeafSets = new Set[0];
}
if (tree instanceof TreeModel) {
addModel((TreeModel) tree);
}
intervals = new Intervals(tree.getNodeCount());
storedIntervals = new Intervals(tree.getNodeCount());
eventsKnown = false;
addStatistic(new DeltaStatistic());
likelihoodKnown = false;
}
示例13: narrow
import beast.evolution.tree.Tree; //导入方法依赖的package包/类
public double narrow(final Tree tree) {
final int nodeCount = tree.getNodeCount();
//make sure that there are at least two distinct non-root nodes which are not direct ancestors.
if (nodeCount == 3 && (tree.getRoot()).isFake()) {
return Double.NEGATIVE_INFINITY;
}
Node i;
do {
i = tree.getNode(Randomizer.nextInt(nodeCount));
} while (i.isRoot() || i.getParent().isRoot() || (i).isDirectAncestor());
final Node iParent = i.getParent();
final Node iGrandParent = iParent.getParent();
Node iUncle = iGrandParent.getLeft();
if (iUncle.getNr() == iParent.getNr()) {
iUncle = iGrandParent.getRight();
//assert (iUncle.getNr() != iParent.getNr());
}
//assert iUncle == getOtherChild(iGrandParent, iParent);
//assert i.getHeight() <= iGrandParent.getHeight();
if (iUncle.getHeight() < iParent.getHeight()) {
exchangeNodes(i, iUncle, iParent, iGrandParent);
return 0.0;
} else {
// Couldn't find valid narrow move on this beast.tree!!
return Double.NEGATIVE_INFINITY;
}
// final int nInternalNodes = tree.getInternalNodeCount(); //TODO look if I can implement this more efficient code for SA trees
// final int leafNodeCount = tree.getLeafNodeCount();
// // make sure that the tree has at least two internal nodes
// if (nInternalNodes <= 1 ) {
// return Double.NEGATIVE_INFINITY;
// }
//
// //choose one of internal nodes that has at least one non-leaf node
// //(there is always at least one such node as long as the tree has at least 2 internal nodes)
// Node iGrandParent;
// do {
// iGrandParent = tree.getNode(leafNodeCount + Randomizer.nextInt(nInternalNodes));
// } while (iGrandParent.getLeft().isLeaf() && iGrandParent.getRight().isLeaf());
//
// Node iParent = iGrandParent.getLeft();
// Node iUncle = iGrandParent.getRight();
// if (iParent.getHeight() < iUncle.getHeight()) {
// iParent = iGrandParent.getRight();
// iUncle = iGrandParent.getLeft();
// }
//
// if( iParent.isLeaf() ) {
// return Double.NEGATIVE_INFINITY;
// }
//
// final Node i;
//
// if (iParent.isFake()) {
// if (iParent.getLeft().isDirectAncestor()) {
// i = iParent.getRight();
// } else i = iParent.getLeft();
// } else {
// i = (Randomizer.nextBoolean() ? iParent.getLeft() : iParent.getRight());
// }
//
// exchangeNodes(i, iUncle, iParent, iGrandParent);
//
// return 0.0;
}
示例14: narrow
import beast.evolution.tree.Tree; //导入方法依赖的package包/类
public double narrow(final Tree tree) {
final int nodeCount = tree.getNodeCount();
//make sure that there are at least two distinct non-root nodes which are not direct ancestors.
if (nodeCount == 3 && ((ZeroBranchSANode)tree.getRoot()).isFake()) {
return Double.NEGATIVE_INFINITY;
}
Node i;
do {
i = tree.getNode(Randomizer.nextInt(nodeCount));
} while (i.isRoot() || i.getParent().isRoot() || ((ZeroBranchSANode)i).isDirectAncestor());
final Node iParent = i.getParent();
final Node iGrandParent = iParent.getParent();
Node iUncle = iGrandParent.getLeft();
if (iUncle.getNr() == iParent.getNr()) {
iUncle = iGrandParent.getRight();
//assert (iUncle.getNr() != iParent.getNr());
}
//assert iUncle == getOtherChild(iGrandParent, iParent);
//assert i.getHeight() <= iGrandParent.getHeight();
if (iUncle.getHeight() < iParent.getHeight()) {
exchangeNodes(i, iUncle, iParent, iGrandParent);
return 0.0;
} else {
// Couldn't find valid narrow move on this beast.tree!!
return Double.NEGATIVE_INFINITY;
}
// final int nInternalNodes = tree.getInternalNodeCount(); //TODO look if I can implement this more efficient code for SA trees
// final int leafNodeCount = tree.getLeafNodeCount();
// // make sure that the tree has at least two internal nodes
// if (nInternalNodes <= 1 ) {
// return Double.NEGATIVE_INFINITY;
// }
//
// //choose one of internal nodes that has at least one non-leaf node
// //(there is always at least one such node as long as the tree has at least 2 internal nodes)
// Node iGrandParent;
// do {
// iGrandParent = tree.getNode(leafNodeCount + Randomizer.nextInt(nInternalNodes));
// } while (iGrandParent.getLeft().isLeaf() && iGrandParent.getRight().isLeaf());
//
// Node iParent = iGrandParent.getLeft();
// Node iUncle = iGrandParent.getRight();
// if (iParent.getHeight() < iUncle.getHeight()) {
// iParent = iGrandParent.getRight();
// iUncle = iGrandParent.getLeft();
// }
//
// if( iParent.isLeaf() ) {
// return Double.NEGATIVE_INFINITY;
// }
//
// final Node i;
//
// if (iParent.isFake()) {
// if (iParent.getLeft().isDirectAncestor()) {
// i = iParent.getRight();
// } else i = iParent.getLeft();
// } else {
// i = (Randomizer.nextBoolean() ? iParent.getLeft() : iParent.getRight());
// }
//
// exchangeNodes(i, iUncle, iParent, iGrandParent);
//
// return 0.0;
}
示例15: main
import beast.evolution.tree.Tree; //导入方法依赖的package包/类
public static void main (String[] arg) throws Exception{
Node root = new Node();
root.setNr(4);
root.setHeight(2.0);
Node left = new Node();
left.setNr(3);
left.setHeight(1.0);
root.setLeft(left);
left.setParent(root);
Node right = new Node();
right.setNr(2);
right.setHeight(2.0);
root.setRight(right);
right.setParent(root);
Node leftLeft = new Node();
leftLeft.setNr(0);
leftLeft.setHeight(0.0);
left.setLeft(leftLeft);
leftLeft.setParent(left);
Node leftRight = new Node();
leftRight.setNr(1);
leftRight.setHeight(1.0);
left.setRight(leftRight);
leftRight.setParent(left);
Tree tree = new Tree(root);
System.out.println("The tree is " + tree.getRoot().toShortNewick(false));
SATreeComparingAnalysis analysis = new SATreeComparingAnalysis();
//process tree. consider Fake SA trees
ArrayList<Integer> dAPattern = new ArrayList<Integer>();
for (int i=tree.getLeafNodeCount(); i< tree.getNodeCount(); i++){
if (((ZeroBranchSANode)tree.getNode(i)).isFake()) {
int descendantsCount = tree.getNode(i).getLeafNodeCount() - 1;
if (descendantsCount > 0) {
for(int j=dAPattern.size(); j<descendantsCount; j++){
dAPattern.add(0);
}
int tmp = dAPattern.get(descendantsCount-1);
tmp++;
dAPattern.set(descendantsCount - 1, tmp);
}
}
}
SATreeComparingAnalysis.TreeSummary treeSummary = analysis.new TreeSummary(tree.getRoot().getHeight(), tree.getLeafNodeCount() - ((ZeroBranchSATree)tree).getDirectAncestorNodeCount(), dAPattern);
System.out.println(treeSummary.dAPattern.toString());
ArrayList<Integer> a = new ArrayList<Integer> (Arrays.asList(new Integer[]{1, 1}));
System.out.println(treeSummary.dAPattern.equals(a));
}