本文整理汇总了Java中pal.tree.Node.addChild方法的典型用法代码示例。如果您正苦于以下问题:Java Node.addChild方法的具体用法?Java Node.addChild怎么用?Java Node.addChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pal.tree.Node
的用法示例。
在下文中一共展示了Node.addChild方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: balanced_halved
import pal.tree.Node; //导入方法依赖的package包/类
private void balanced_halved(int nodes, double height) {
if (!isPowerOfTwo(nodes))
throw new RuntimeException("Does not implement balanced tree where number_of_taxa != 2^n");
Node root = NodeFactory.createNode();
List<Node> currentTips = Lists.newArrayList(root);
int totalTips = currentTips.size();
int depth = 0;
while (totalTips < nodes) {
depth++;
List<Node> newTips = Lists.newArrayList();
for (Node n : currentTips) {
double l;
l = height / Math.pow(2, depth);
if (depth == 7) l += l;
Node n1 = NodeFactory.createNode();
n1.setBranchLength(l);
newTips.add(n1);
Node n2 = NodeFactory.createNode();
n2.setBranchLength(l );
newTips.add(n2);
n.addChild(n1);
n.addChild(n2);
}
currentTips.clear();
currentTips.addAll(newTips);
totalTips = currentTips.size();
}
SimpleTree st = new SimpleTree(root);
int seqNumber = 1;
for (Node tip : PhyloUtils.externalNodes(st)) {
tip.setIdentifier(new Identifier("seq_" + seqNumber++));
}
System.out.println(st.toString());
}
示例2: balanced_fixed
import pal.tree.Node; //导入方法依赖的package包/类
private void balanced_fixed(int nodes, double length) {
if (!isPowerOfTwo(nodes))
throw new RuntimeException("Does not implement balanced tree where number_of_taxa != 2^n");
Node root = NodeFactory.createNode();
List<Node> currentTips = Lists.newArrayList(root);
int totalTips = currentTips.size();
while (totalTips < nodes) {
List<Node> newTips = Lists.newArrayList();
for (Node n : currentTips) {
Node n1 = NodeFactory.createNode();
n1.setBranchLength(length);
newTips.add(n1);
Node n2 = NodeFactory.createNode();
n2.setBranchLength(length);
newTips.add(n2);
n.addChild(n1);
n.addChild(n2);
}
currentTips.clear();
currentTips.addAll(newTips);
totalTips = currentTips.size();
}
SimpleTree st = new SimpleTree(root);
int seqNumber = 1;
for (Node tip : PhyloUtils.externalNodes(st)) {
tip.setIdentifier(new Identifier("seq_" + seqNumber++));
}
System.out.println(st.toString());
}
示例3: unbalanced_fixed
import pal.tree.Node; //导入方法依赖的package包/类
private void unbalanced_fixed(int totalNodes, double stepLength) {
int nodeNumber = totalNodes;
Node n1 = NodeFactory.createNode();
n1.setIdentifier(new Identifier("seq_" + nodeNumber--));
n1.setBranchLength(stepLength);
Node n2 = NodeFactory.createNode();
n2.setIdentifier(new Identifier("seq_" + nodeNumber--));
n2.setBranchLength(stepLength);
Node n3 = NodeFactory.createNode();
n3.addChild(n1);
n3.addChild(n2);
Node root = n3;
for (int i : seq(1, totalNodes - 2)) {
root.setBranchLength(stepLength);
Node n4 = NodeFactory.createNode();
n4.addChild(root);
root = n4;
double length = stepLength * (i + 1);
Node n5 = NodeFactory.createNode();
n5.setBranchLength(length);
n5.setIdentifier(new Identifier("seq_" + nodeNumber--));
n4.addChild(n5);
}
SimpleTree st = new SimpleTree(root);
System.out.println(st.toString());
}