本文整理汇总了Java中beast.evolution.tree.Tree.getLeafNodeCount方法的典型用法代码示例。如果您正苦于以下问题:Java Tree.getLeafNodeCount方法的具体用法?Java Tree.getLeafNodeCount怎么用?Java Tree.getLeafNodeCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类beast.evolution.tree.Tree
的用法示例。
在下文中一共展示了Tree.getLeafNodeCount方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: calculateTreeLogLikelihood
import beast.evolution.tree.Tree; //导入方法依赖的package包/类
protected double calculateTreeLogLikelihood(final Tree tree, final double rho, final double a) {
final int taxonCount = tree.getLeafNodeCount();
final double r = birthDiffRateParameterInput.get().getValue();
double logL = logTreeProbability(taxonCount, r, rho, a);
double scaleFactor;
if(scalerParameter == null){
scaleFactor = scaler.getScaleFactor();
}else{
scaleFactor = scalerParameter.getValue();
}
final Node [] nodes = tree.getNodesAsArray();
for (int i = taxonCount; i < nodes.length; i++) {
assert ( ! nodes[i].isLeaf() );
logL += calcLogNodeProbability(nodes[i], r, rho, a, taxonCount,scaleFactor);
}
return logL;
}
示例2: 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;
}
示例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 = 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;
}
示例4: changeTaxaNumbers
import beast.evolution.tree.Tree; //导入方法依赖的package包/类
public void changeTaxaNumbers(Tree tree, Map<String,String> newTranslationMap) {
for (int i=0; i < tree.getLeafNodeCount(); i++) {
String taxon = newTranslationMap.get(String.valueOf(i));
int oldIndex = i;
for (int j=i; j < tree.getLeafNodeCount(); j++) {
if (tree.getNode(j).getID().equals(taxon)) {
oldIndex = j;
break;
}
}
if (i != oldIndex) {
tree.getNode(i).setNr(oldIndex);
tree.getNode(oldIndex).setNr(i);
// tree.initArray TODO implement this, but an array of nodes is private so...
}
}
}
示例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: listSA
import beast.evolution.tree.Tree; //导入方法依赖的package包/类
/**
* retern the list of sampled ancestors, WARNING works only for zeroBranchTrees
* @param tree
* @return
*/
public ArrayList<String> listSA(Tree tree, boolean useRanking){
ArrayList<String> sampledAncestors = new ArrayList<String>();
count = 0;
for (int i=0; i<tree.getLeafNodeCount(); i++){
if (((ZeroBranchSANode)tree.getNode(i)).isDirectAncestor()) {
if (useRanking) {
sampledAncestors.add(Integer.toString(getRank(tree, tree.getNode(i))));
} else {
sampledAncestors.add(tree.getNode(i).getID());
if (tree.getNode(i).getID().equals("0")) {
count++;
}
}
}
}
return sampledAncestors;
}
示例7: resetGeneTreeTipHeights
import beast.evolution.tree.Tree; //导入方法依赖的package包/类
private void resetGeneTreeTipHeights() {
final SpeciesTreeInterface speciesTree = speciesTreeInput.get();
final Map<String, Integer> tipNames = speciesTree.getTipNumberMap();
final List<Tree> geneTrees = genes.get();
for (final Tree gtree : geneTrees) {
final int leafNodeCount = gtree.getLeafNodeCount();
for (int geneLeafNr = 0; geneLeafNr < leafNodeCount; geneLeafNr++) {
final Node geneLeaf = gtree.getNode(geneLeafNr);
final int speciesLeafNr = tipNames.get(geneLeaf.getID());
final Node speciesLeaf = speciesTree.getNode(speciesLeafNr);
geneLeaf.setHeight(speciesLeaf.getHeight());
}
}
}
示例8: getNodesToOperateOn
import beast.evolution.tree.Tree; //导入方法依赖的package包/类
private List<Node> getNodesToOperateOn() {
Tree tree = treeInput.get();
ArrayList<Node> nodeList = new ArrayList<>();
if (useNodeNumbers) {
int leafNodeCount = tree.getLeafNodeCount();
} else {
for (int i = 0; i < taxonIndices.length; i++) {
nodeList.add(tree.getNode(taxonIndices[i]));
}
}
return nodeList;
}
开发者ID:CompEvol,项目名称:sampled-ancestors,代码行数:15,代码来源:SampledNodeDateRandomWalkerForZeroBranchSATrees.java
示例9: listSA
import beast.evolution.tree.Tree; //导入方法依赖的package包/类
/**
* retern the list of sampled ancestors
* @param tree
* @return
*/
public ArrayList<String> listSA(Tree tree, boolean useRanking){
ArrayList<String> sampledAncestors = new ArrayList<String>();
for (int i=0; i<tree.getLeafNodeCount(); i++){
if (tree.getNode(i).isDirectAncestor()) {
if (useRanking) {
sampledAncestors.add(Integer.toString(getRank(tree, tree.getNode(i))));
} else {
sampledAncestors.add(tree.getNode(i).getID());
}
}
}
return sampledAncestors;
}
示例10: getCanonicalNodeSpacing
import beast.evolution.tree.Tree; //导入方法依赖的package包/类
private double getCanonicalNodeSpacing(Tree tree) {
return 1.0 / (tree.getLeafNodeCount() - 1);
}
示例11: 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));
}