private static void renameTreeLeavesLeftToRight(Phylogeny tree) { PhylogenyNodeIterator iterator = tree.iteratorPreorder(); int i = 0; while (iterator.hasNext()) { PhylogenyNode currentNode = iterator.next(); if (currentNode.isExternal()) { currentNode.setName(i + ""); i++; } } }
private final String printProgressNodeToString(final PhylogenyNode n) { if (n.isExternal()) { if (ForesterUtil.isEmpty(n.getName())) { return Long.toString(n.getId()); } return n.getName(); } return n.getId() + " (" + (ForesterUtil.isEmpty(n.getChildNode1().getName()) ? n.getChildNode1().getId() : n.getChildNode1().getName()) + "+" + (ForesterUtil.isEmpty(n.getChildNode2().getName()) ? n.getChildNode2().getId() : n.getChildNode2().getName()) + ")"; }
public static void renameTreeLeavesRandomly(Phylogeny tree) { Random random = new Random(); List<PhylogenyNode> leaves = new ArrayList(); PhylogenyNodeIterator iterator = tree.iteratorPostorder(); while (iterator.hasNext()) { PhylogenyNode node = iterator.next(); if (node.isExternal()) { leaves.add(node); } } int i = 0; while (!leaves.isEmpty()) { int leafIndex = random.nextInt(leaves.size()); PhylogenyNode currentLeaf = leaves.get(leafIndex); currentLeaf.setName(i + ""); leaves.remove(leafIndex); i++; } }