private static String getNewickSubtree(Node n) { if (n.numChildren() == 0) { return new String(n.getId() + ":" + n.getDistToParent()); } else { StringBuffer str = new StringBuffer("("); int i; for (i = 0; i < (n.numChildren() - 1); i++) str.append(getNewickSubtree(n.getChild(i)) + ", "); str.append(getNewickSubtree(n.getChild(i))); str.append("):" + n.getDistToParent()); return str.toString(); } }
public static double getDistToRoot(Node n) { double dist = 0; Node p = n; int steps = 0; // System.out.println("Computing dist to root :"); while (p != null) { dist += p.getDistToParent(); steps++; // System.out.println("Step " + steps + " dist to parent : " + p.getDistToParent() + " total : // " + dist); p = p.getParent(); } return dist; }