public static Tree spanningTree(Tree tree, List<String> labels) { Tree nt = new Tree(); TreeNode root = null; if (labels.size() > 1) {
public Tree buildTree() { TIntObjectMap<TreeNode> nodeMap = new TIntObjectHashMap<>(); Tree tree = new Tree(); Iterator<Edge> it = supertreeEdges.iterator(); while (it.hasNext()) { Edge edge = it.next(); nodeMap.put(edge.treeNode, new TreeNode(edge.treeNodeLabel)); tree.addVertex(nodeMap.get(edge.treeNode)); if (edge.parentNode == 0) { tree.setRoot(nodeMap.get(edge.treeNode)); it.remove(); } } for (Edge edge : supertreeEdges) { tree.addEdge(nodeMap.get(edge.parentNode), nodeMap.get(edge.treeNode)); } tree.setName(String.valueOf(currentscore)); return tree; }
result = new Tree();
Tree nt = new Tree(); nt.setName(t.getName()); TreeNode root = (TreeNode) t.getRoot();
/** * Create a new {@link Tree} that represents the subtree of this tree rooted at the given * node. The returned tree is a new tree that contains clones of the {@link TreeNode}s of this tree. * The node copies are created using {@link TreeNode#cloneNode()} and are * new instances, so you will not have object equality ( n != n.cloneNode() ). Node equality using * {@link TreeNode#equals(Object)} will work at least for labeled nodes (because the labels are compared), but * for performance reasons we do not do deep checks. * <p> * If this tree does not contain the given node, null is returned. * * @param n the root node of the subtree * @return subtree rooted at the given node or null */ public Tree getSubtree(TreeNode n) { if (n == null) throw new NullPointerException(); if (nodes.get(n.getIndex()) != n) { return null; } Tree r = new Tree(); r.setName(getName()); TreeNode root = n.cloneNode(); root.setIndex(-1); // reset index r.addVertex(root); r.setRoot(root); hangIn(root, n, r); return r; }
result = new Tree(); TreeNode cRoot = new TreeNode(); result.addVertex(cRoot);
protected static Tree getTree(Reader r) { NewickStreamTokenizer st = new NewickStreamTokenizer(r); Tree t = new Tree(); StringBuffer label = new StringBuffer(); StringBuffer nhx = new StringBuffer();