/** * Returns Identifiers. The position in the array represents the row/column * in the matrix returned by {@link #computeMatrix(java.util.List)} * * If you specify a prefix, it is used for trees which have no name * (prefix #counter). * * @param trees * @return */ public static String[] getIDs(List<Tree> trees, String prefix) { String[] ids = new String[trees.size()]; if (prefix == null) prefix = ""; for (int i = 0; i < trees.size(); i++) { ids[i] = trees.get(i).getName(); if (ids[i] == null) ids[i] = prefix + " " + i; } return ids; }
@Override public void writeOutput(List<Tree> treesToWrite) throws IOException { super.writeOutput(treesToWrite); //write scoring file for beam search trees if (isFullOutput()) { String name = getOutputFile().toString(); String[] ext = name.split("[.]"); name = name.replace("." + ext[ext.length - 1], ".score"); try (BufferedWriter wr = Files.newBufferedWriter(Paths.get(name))) { for (Tree tree : treesToWrite) { String s = tree.getName(); wr.write(s == null ? "NaN" : s); wr.write(System.lineSeparator()); } } catch (Exception e) { e.printStackTrace(); } } } }
public void addTree(Tree tree) { String name = tree.getName(); this.treeList.add(tree); for (TreeNode treeNode : tree.vertices()) { if (!addInternaleTaxa && treeNode.isLeaf()) taxa.addTaxon(treeNode.getLabel()); } String nn = taxa.translate(name); if (nn == null) { nn = "tree_" + treeList.size(); } this.trees.put(nn, tree); }
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; }
System.out.println("[RerootByModelTree] Rooting by Modeltree not possible for tree: " + tree.getName() + " because trees have no overlapping taxa!"); } else { if (TreeUtils.VERBOSE_ROOTING) { System.out.println("[RerootByModelTree] No root found for tree: " + tree.getName() + " that corresponds to the modelTree");
if (bothTrees.size() < 2) { if (TreeUtils.VERBOSE_ROOTING) { System.out.println("[RerootByModelLeastTaxa] Rooting by Modeltree not possible for tree: " + tree.getName() + " because trees have no overlapping taxa!"); System.out.println("[RerootByModelLeastTaxa] Rooting with respect to model tree not possible for tree: " + tree.getName() + ", find best alternative root.");
int i = 1; for (Tree supertree : superTrees) { CLI.LOGGER_WRAPPER.debug("SuperTree " + i++ +" with Score: " + supertree.getName() + System.lineSeparator() + Newick.getStringFromTree(supertree));
for (Tree t : trees) { Tree nt = new Tree(); nt.setName(t.getName()); TreeNode root = (TreeNode) t.getRoot(); pruneTraverse(nt, root, null, labels);
/** * 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; }