public static Tree[] cloneTrees(Tree... trees) { if (trees == null) return null; if (trees.length == 0) return new Tree[0]; Tree[] newTrees = new Tree[trees.length]; for (int i = 0; i < trees.length; i++) { newTrees[i] = trees[i].cloneTree(); } return newTrees; }
/** * Clones all trees * * @param trees the source trees * @return clones the cloned trees */ public static List<Tree> cloneTrees(List<Tree> trees) { if (trees == null) return null; if (trees.size() == 0) return Collections.emptyList(); List<Tree> newTrees = new ArrayList<>(trees.size()); for (Tree tree : trees) { newTrees.add(tree.cloneTree()); } return newTrees; }
private void buildNormTrees() { normalizedTrees = new ArrayList<Tree>(trees.size()); for (int i = 0; i < factors.length; i++) { double factor = factors[i]; Tree clone = trees.get(i).cloneTree(); if (factor != 1d) { Set<Edge> edges = new HashSet<Edge>(clone.edgeCount()); for (TreeNode node : clone.getRoot().depthFirstIterator()) { edges.addAll(node.getAllEdges()); } for (Edge edge : edges) { edge.setWeight(edge.getWeight() * factor); } } normalizedTrees.add(clone); } }
/** * Clones the tree and removes al inner vertices on the tree. Due to cloning * the given tree is not modified * * @param sourceTree the source tree * @return clone clone of the soruce treee without any innter vertex labels */ public static Tree deleteInnerLabels(Tree sourceTree) { Tree tree = sourceTree.cloneTree(); for (TreeNode node : tree.vertices()) { if (node.isInnerNode()) { node.setLabel(null); } } return tree; }
/** * Creates a copy of the given tree and renames all vertices according to the translation table. * If strict pattersn is set, all source names are translated to valid nexus taxon names. * * @param tree the source tree * @param translation the translation table * @param strictPatterns use only valid nexus taxon names * @return tree translated tree */ public static Tree renameNodes(Tree tree, Map<String, String> translation, boolean strictPatterns) { Tree t = tree.cloneTree(); for (TreeNode node : t.vertices()) { if (node.getLabel() != null) { String newName = null; if (strictPatterns) newName = translation.get(NexusTaxaBlock.translate(node.getLabel())); else { newName = translation.get(node.getLabel()); } if (newName != null) { node.setLabel(newName); } } } return t; }
public void calculateNaive() { result = null; Tree t1 = trees.get(0).cloneTree(); //because t1 gets modified Tree t2 = trees.get(1);
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; }
if (clade.size() > 2 && (numTaxa - clade.size()) > 2) { Tree rootedModel = unrootedModel.cloneTree(); List<TreeNode> nodes = new LinkedList<>(); for (String s : clade) {
public void calculatePairwise() { result = null; Tree t1 = trees.get(0).cloneTree(); //because t1 gets modified Tree t2 = trees.get(1);