public static Tree findMostCompatibleRootToScaffoldTree(Tree inputTree, Tree model) { List<Tree> bothTrees = new ArrayList<>(Arrays.asList(TreeUtils.cloneAndPruneTrees(new Tree[]{inputTree, model}))); Tree tree = bothTrees.get(0); Tree prunedModel = bothTrees.get(1); if (bothTrees.size() < 2) { if (TreeUtils.VERBOSE_ROOTING) { System.out.println("[RerootByModelTree] Rooting by Modeltree not possible for tree: " + tree.getName() + " because trees have no overlapping taxa!"); } return null; } if (prunedModel.getRoot().childCount() == 2) { findMostCompatibleRoot(tree, prunedModel); } else { findMostCompatibleFakeRoot(tree, prunedModel); } return tree; }
private static void removePolytomies(Tree tree, Comparator<TreeNode> comp) { tree.getRoot().depthFirstIterator().forEach(node -> { int toRemove = node.childCount() - 2; if (toRemove > 0) { ArrayList<TreeNode> children = node.getChildren(); sortChildren(children, comp); for (int i = 0; i < toRemove; i++) { TreeNode remove = children.get(i); tree.removeSubtree(remove); } } }); }
private void checkBinaryClade(TreeNode cladeToCheck, Tree supertree, Set<Object> parentTaxa, Map<Set<Object>, TreeNode> partition, Map<TreeNode, Set<Object>> leafMap) { Set<Set<Object>> supported = new HashSet<>(cladeToCheck.childCount()); for (PPCharacter ppCharacter : ppSet) { if (cladeToCheck.childCount() < 2) { if (cladeToCheck.childCount() == 0) { supertree.removeVertex(cladeToCheck); } else {
TreeNode node = scaffoldCharacterMapping.get(character); if (node != null) { Set<N> toInsert = new HashSet(node.childCount()); for (TreeNode child : node.getChildren()) { if (child.isInnerNode()) {
/** * Returns true if all trees are binary. * * @param trees the trees * @return True, if trees are binary */ public static boolean isBinary(Tree[] trees) { for (Tree tree : trees) { for (TreeNode node : tree.getRoot().depthFirstIterator()) { if (node.isInnerNode() && node.childCount() > 2) { return false; } } } return true; }
private static int findMostCompatibleRoot(Tree tree, Tree prunedModel) { List<Set<String>> rootEdges = new ArrayList<>(prunedModel.getRoot().childCount()); //should be 2 otherwise method will not work for (TreeNode child : prunedModel.getRoot().getChildren()) { rootEdges.add(TreeUtils.getLeafLabels(child));
Set<Object> cladeTaxa = leafMap.get(cladeToCheck); Map<Set<Object>, TreeNode> partition = new HashMap<>(cladeToCheck.childCount()); for (TreeNode child : cladeToCheck.getChildren()) { if (child.isInnerNode()) { if (parent.childCount() > 2) { Collection<TreeNode> toRemove = checkNonBinaryClade(parent, supertree, leafMap); innerNodes.removeAll(toRemove);
List<Set<String>> rootEdge = new ArrayList<Set<String>>(prunedModel.getRoot().childCount()); for (TreeNode child : prunedModel.getRoot().getChildren()) { rootEdge.add(TreeUtils.getLeafLabels(child));
private static int findMostCompatibleFakeRoot(Tree tree, Tree prunedModel) { List<Set<String>> rootEdges = new ArrayList<>(prunedModel.getRoot().childCount()); //should be >2 otherwise use the real root method for (TreeNode child : prunedModel.getRoot().getChildren()) { rootEdges.add(TreeUtils.getLeafLabels(child));
List<Set<String>> rootEdges = new ArrayList<Set<String>>(prunedModel.getRoot().childCount()); for (TreeNode child : prunedModel.getRoot().getChildren()) { rootEdges.add(TreeUtils.getLeafLabels(child));
/** * Computes the number of the given child for this node. * This number is 0 {@literal <=} childNum {@literal <} 'number of children', if the child is a real child of this node. * It is childNum = 'number of children', if the given child is parent of this node. * * @param child: the child, for that its number has to be computed * @return the child number for the given node */ public int getChildNumber(TreeNode child) { if (this.getParent().equalsNode(child)) { return childCount(); } else if (child.isChildOf(this)) { int num = 0; for (TreeNode nodesChild : this.children()) { if (!nodesChild.equalsNode(child)) { num++; } else { break; } } return num; } else { throw new RuntimeException("Given child is no child of this node!"); } }
TreeNode root = (TreeNode) t.getRoot(); pruneTraverse(nt, root, null, labels); if (nt.vertexCount() > 0 && ((TreeNode) nt.getRoot()).childCount() > 0) { newTrees.add(nt);
Tree[] forRooting = TreeUtils.cloneAndPruneTrees(new Tree[]{tree, rootedModel}); if (forRooting[1].getRoot().childCount() == 2) { sumOfErrorScores += findMostCompatibleRoot(forRooting[0], forRooting[1]); } else {
final int childCount = node.childCount(); List<TreeNode> children = new ArrayList<>(childCount); for (TreeNode child : node.children()) {
cc += taxonCounter.get(treeNode); if (cc == node.childCount()) {
public static Tree deleteRootNode(Tree sourceTree, boolean clone) { if (clone) sourceTree = sourceTree.cloneTree(); TreeNode r = sourceTree.getRoot(); if (r.childCount() == 2) { List<TreeNode> children = r.getChildren(); sourceTree.removeVertex(r); TreeNode c1 = children.get(0); TreeNode c2 = children.get(1); if (c1.isInnerNode()) { sourceTree.addEdge(c1, c2); sourceTree.setRoot(c1); } else if (c2.isInnerNode()) { sourceTree.addEdge(c2, c1); sourceTree.setRoot(c2); } else { System.out.println("Could not unroot tree. Tree seems not to be a tree!"); return null; } } return sourceTree; }
double damage_per_child = parent_score / n.childCount();
Partition[] childPartitions = new Partition[treeNodes[i].childCount()]; int z = 0; for (TreeNode n : treeNodes[i].children()) {
if (node.isInnerNode() && node.childCount() == 1) { TreeNode child = node.getChildAt(0); TreeNode parent = node.getParent();
if (newNode.childCount() == 0) { t.removeVertex(newNode); } else if (newNode.childCount() == 1) { TreeNode child = newNode.getChildAt(0); t.removeVertex(newNode);