本文整理汇总了Java中pal.tree.Node类的典型用法代码示例。如果您正苦于以下问题:Java Node类的具体用法?Java Node怎么用?Java Node使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Node类属于pal.tree包,在下文中一共展示了Node类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: printNH2
import pal.tree.Node; //导入依赖的package包/类
public static void printNH2(PrintWriter out, Node node, Map<Node, Attributes> nodeAttributes) {
if (!node.isLeaf()) {
out.print("(");
for (int i = 0; i < node.getChildCount(); i++) {
if (i != 0) {
out.print(",");
}
printNH2(out, node.getChild(i), nodeAttributes);
}
out.print(")");
}
if (!node.isRoot()) {
String id = nodeAttributes.get(node).get(Attributes.Key.REALNAME);
out.print(id);
out.print(":");
FormattedOutput.getInstance().displayDecimal(out, node.getBranchLength(), 7);
}
}
示例2: rootedSupport
import pal.tree.Node; //导入依赖的package包/类
/**
* Calculates rooted support.
*
* @param wTree the weighted tree instance
* @param node the node
* @param support the support
*
* @return the fixed bit set
*/
private FixedBitSet rootedSupport(WeightedTree wTree, Node node, Map<FixedBitSet, Support> support) {
FixedBitSet clade = new FixedBitSet(numTaxa);
if (node.isLeaf()) {
clade.set(idGroup.whichIdNumber(node.getIdentifier().getName()));
} else {
for (int i = 0; i < node.getChildCount(); i++) {
Node n = node.getChild(i);
FixedBitSet childClade = rootedSupport(wTree, n, support);
clade.union(childClade);
}
}
Support s = support.get(clade);
if (s == null) {
s = new Support();
support.put(clade, s);
}
s.add(wTree.getWeight(), TreeUtilities.safeNodeHeight(wTree.getTree(), node), node.getBranchLength());
return clade;
}
示例3: insureConsistency
import pal.tree.Node; //导入依赖的package包/类
/**
* Make sure subtree below node has consistent heights, i.e. node height is higher than it's descendants
*
* @param tree the tree
* @param node the node
*
* @return height of node
*/
public static double insureConsistency(Tree tree, Node node) {
double height = TreeUtilities.safeNodeHeight(tree, node);
if (node.isLeaf()) {
return height;
} else {
for (int i = 0; i < node.getChildCount(); i++) {
Node n = node.getChild(i);
final double childHeight = insureConsistency(tree, n);
height = Math.max(height, childHeight);
}
}
node.setNodeHeight(height);
return height;
}
示例4: insureConsistency
import pal.tree.Node; //导入依赖的package包/类
/**
* Make sure subtree below node has consistent heights, i.e. node height is higher than it's descendants
*
* @param tree the tree
* @param node the node
*
* @return height of node
*/
public static double insureConsistency(Tree tree, Node node) {
double height = TreeUtils.safeNodeHeight(tree, node);
if (node.isLeaf()) {
return height;
} else {
for (int i = 0; i < node.getChildCount(); i++) {
Node n = node.getChild(i);
final double childHeight = insureConsistency(tree, n);
height = Math.max(height, childHeight);
}
}
node.setNodeHeight(height);
return height;
}
示例5: readBranch
import pal.tree.Node; //导入依赖的package包/类
/**
* Reads a branch in. This could be a node or a tip (calls readNode or readTip
* accordingly). It then reads the branch length and SimpleNode that will
* point at the new node or tip.
*/
private Node readBranch() throws IOException, ImportException {
Node branch;
helper.clearLastMetaComment();
if (helper.nextCharacter() == '(') {
// is an internal node
branch = readInternalNode();
} else {
// is an external node
branch = readExternalNode();
}
if (helper.getLastDelimiter() == ':') {
final double length = helper.readDouble(",():;");
branch.setBranchLength(length);
}
return branch;
}
示例6: rootedSupport
import pal.tree.Node; //导入依赖的package包/类
/**
* Calculates rooted support.
*
* @param wTree the weighted tree instance
* @param node the node
* @param support the support
*
* @return the fixed bit set
*/
private FixedBitSet rootedSupport(WeightedTree wTree, Node node, Map<FixedBitSet, Support> support) {
FixedBitSet clade = new FixedBitSet(numTaxa);
if (node.isLeaf()) {
clade.set(idGroup.whichIdNumber(node.getIdentifier().getName()));
} else {
for (int i = 0; i < node.getChildCount(); i++) {
Node n = node.getChild(i);
FixedBitSet childClade = rootedSupport(wTree, n, support);
clade.union(childClade);
}
}
Support s = support.get(clade);
if (s == null) {
s = new Support();
support.put(clade, s);
}
s.add(wTree.getWeight(), TreeUtils.safeNodeHeight(wTree.getTree(), node), node.getBranchLength());
return clade;
}
示例7: printAlignment
import pal.tree.Node; //导入依赖的package包/类
private void printAlignment(PrintWriter out, Tree tree) {
// PrintWriter out = new PrintWriter(System.out);
out.write(" " + tree.getExternalNodeCount() + " " + tree.getExternalNode(0).getSequence().length * 3 + "\n");
for (int i = 0; i < tree.getExternalNodeCount(); i++) {
Node n = tree.getExternalNode(i);
out.write(n.getIdentifier().getName() + " ");
byte[] sequence = n.getSequence();
for (int j = 0; j < sequence.length; j++) {
out.write(GeneticCode.getInstance().getCodonTLA(sequence[j]));
}
out.write("\n");
}
out.write("\n");
out.flush();
}
示例8: RerootedTreeIterator
import pal.tree.Node; //导入依赖的package包/类
public RerootedTreeIterator(Tree t) {
treeRootSaver = new TreeRootSaver(t);
if (t.getExternalNodeCount() == t.getRoot().getChildCount()) {
this.tree = t;
System.out.println(this.tree.toString());
}
else if (t.getRoot().getChildCount() == ROOTED_DEGREE) {
this.tree = TreeManipulator.getUnrooted(t);
} else {
this.tree = t;
}
internalNodes = new Node[this.tree.getInternalNodeCount()];
// Keep a list of all the internal nodes of the tree for iterator
int pos = 0;
for (Node node : PhyloUtils.internalNodes(this.tree)) {
internalNodes[pos++] = node;
}
}
示例9: getAttributes
import pal.tree.Node; //导入依赖的package包/类
private Attributes getAttributes(Node node, List<Substitution> substitutions) {
String name;
if (node.isLeaf() && names.size() > 0) {
name = names.get(Integer.parseInt(getSequenceKey(node).split("_")[1]) - 1);
} else {
// MODIFICATION: Change REALNAME of internal nodes (branches)
//name = getSequenceKey(node);
name = "branch_" + Integer.toString(getBranchNumber(node));
}
Attributes a = new Attributes(Attributes.Key.REALNAME, name);
a.add(Attributes.Key.NUMBER, Integer.toString(getBranchNumber(node)));
if (substitutions.size() > 0) a.add(Attributes.Key.ALLSUBS, substitutions.toString());
Collection<Substitution> nonsynSubs = Collections2.filter(substitutions, Predicates.not(new Substitution.isSynSubPredicate()));
if (nonsynSubs.size() > 0) a.add(Attributes.Key.NONSYNSUBS, nonsynSubs.toString());
a.add(Attributes.Key.FULL,
String.format("%s - %s %s",
a.get(Attributes.Key.NUMBER),
a.get(Attributes.Key.REALNAME),
a.get(Attributes.Key.ALLSUBS)));
a.add(Attributes.Key.NAME_AND_SUBS,
String.format("%s %s",
a.get(Attributes.Key.REALNAME),
a.get(Attributes.Key.NONSYNSUBS)));
return a;
}
示例10: getSequenceKey
import pal.tree.Node; //导入依赖的package包/类
private String getSequenceKey(Node n) {
// MODIFIED: now all labels can be obtained from trees[1]
if (n.isLeaf()) {
return trees[1].getExternalNode(n.getNumber()).getIdentifier().getName();
//return trees[0].getExternalNode(n.getNumber()).getIdentifier().getName();
} else {
return trees[1].getInternalNode(n.getNumber()).getIdentifier().getName();
//return "node#" + trees[1].getInternalNode(n.getNumber()).getIdentifier().getName();
}
}
示例11: nodeDistance
import pal.tree.Node; //导入依赖的package包/类
/**
* Calculates the number of branches from node to most remote tip.
*
* @param node the starting node
*
* @return the node distance
*/
public static int nodeDistance(final Node node) {
if (node.isLeaf()) {
return 0;
}
int d = 0;
for (int i = 0; i < node.getChildCount(); i++) {
Node n = node.getChild(i);
d = Math.max(d, nodeDistance(n));
}
return d + 1;
}
示例12: printlnNodeWithNumberAndLabel
import pal.tree.Node; //导入依赖的package包/类
private static void printlnNodeWithNumberAndLabel(PrintWriter out, Node node, int level,
int numExternalNodes, boolean[] umbrella, int[] position) {
for (int i = 0; i < level - 1; i++) {
if (umbrella[i]) {
putCharAtLevel(out, i, '|', position);
} else {
putCharAtLevel(out, i, ' ', position);
}
}
putCharAtLevel(out, level - 1, '+', position);
int branchNumber;
if (node.isLeaf()) {
branchNumber = node.getNumber() + 1;
} else {
branchNumber = node.getNumber() + 1 + numExternalNodes;
}
String numberAsString = Integer.toString(branchNumber);
int numDashs = position[level] - numberAsString.length();
for (int i = 0; i < numDashs ; i++) {
out.print('-');
}
out.print(numberAsString);
if (node.isLeaf()) {
out.println(" " + node.getIdentifier());
} else {
if (!node.getIdentifier().equals(Identifier.ANONYMOUS)) {
out.print("(" + node.getIdentifier() + ")");
}
out.println();
}
}
示例13: printASCII
import pal.tree.Node; //导入依赖的package包/类
public static void printASCII(Tree tree, PrintWriter out) {
tree.createNodeList();
int numExternalNodes = tree.getExternalNodeCount();
int numInternalNodes = tree.getInternalNodeCount();
int numBranches = numInternalNodes + numExternalNodes - 1;
boolean[] umbrella = new boolean[numExternalNodes];
int[] position = new int[numExternalNodes];
int minLength = (Integer.toString(numBranches)).length() + 1;
int MAXCOLUMN = 40;
Node root = tree.getRoot();
if (root.getNodeHeight() == 0.0) {
NodeUtils.lengths2Heights(root);
}
double proportion = (double) MAXCOLUMN / root.getNodeHeight();
for (int n = 0; n < numExternalNodes; n++) {
umbrella[n] = false;
}
position[0] = 1;
for (int i = root.getChildCount() - 1; i > -1; i--) {
printNodeInASCII(out, root.getChild(i), 1, i, root.getChildCount(),
numExternalNodes, umbrella, position, proportion, minLength);
if (i != 0) {
putCharAtLevel(out, 0, '|', position);
out.println();
}
}
}
示例14: printNH
import pal.tree.Node; //导入依赖的package包/类
public static void printNH(PrintWriter out, Tree tree, Node node,
boolean printLengths, boolean printInternalLabels,
boolean printCladeSupport) {
if (!node.isLeaf()) {
out.print("(");
for (int i = 0; i < node.getChildCount(); i++) {
if (i != 0) {
out.print(",");
}
printNH(out, tree, node.getChild(i), printLengths,
printInternalLabels, printCladeSupport);
}
out.print(")");
}
if (!node.isRoot()) {
if (node.isLeaf() || printInternalLabels) {
String id = node.getIdentifier().toString();
out.print(id);
}
if (printCladeSupport) {
if (tree.getAttribute(node, TREE_CLADE_SUPPORT_ATTRIBUTE) != null) {
double support = (Double) tree.getAttribute(node,
TREE_CLADE_SUPPORT_ATTRIBUTE);
out.printf(":" + FormattedOutput.getInstance().getDecimalString(support, 4));
}
}
if (printLengths) {
out.printf(":" + FormattedOutput.getInstance().getDecimalString(node.getBranchLength(), 10));
}
}
}
示例15: printASCII
import pal.tree.Node; //导入依赖的package包/类
public static void printASCII(Tree tree, PrintWriter out) {
FormattedOutput format = FormattedOutput.getInstance();
tree.createNodeList();
int numExternalNodes = tree.getExternalNodeCount();
int numInternalNodes = tree.getInternalNodeCount();
int numBranches = numInternalNodes + numExternalNodes - 1;
boolean[] umbrella = new boolean[numExternalNodes];
int[] position = new int[numExternalNodes];
int minLength = (Integer.toString(numBranches)).length() + 1;
int MAXCOLUMN = 40;
Node root = tree.getRoot();
if (root.getNodeHeight() == 0.0) {
NodeUtils.lengths2Heights(root);
}
double proportion = (double) MAXCOLUMN / root.getNodeHeight();
for (int n = 0; n < numExternalNodes; n++) {
umbrella[n] = false;
}
position[0] = 1;
for (int i = root.getChildCount() - 1; i > -1; i--) {
printNodeInASCII(out, root.getChild(i), 1, i, root.getChildCount(),
numExternalNodes, umbrella, position, proportion, minLength);
if (i != 0) {
putCharAtLevel(out, 0, '|', position);
out.println();
}
}
}