resolves JAL-804
[jalview.git] / src / jalview / analysis / NJTree.java
index 6dca7f8..e11e1f5 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5)
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
  * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
  * 
  * This file is part of Jalview.
@@ -267,15 +267,16 @@ public class NJTree
   }
 
   /**
-   * DOCUMENT ME!
+   * Generate a string representation of the Tree
    * 
-   * @return DOCUMENT ME!
+   * @return Newick File with all tree data available
    */
   public String toString()
   {
     jalview.io.NewickFile fout = new jalview.io.NewickFile(getTopNode());
 
-    return fout.print(false, true); // distances only
+    return fout.print(isHasBootstrap(),
+    isHasDistances(), isHasRootDistance()); // output all data available for tree
   }
 
   /**
@@ -345,7 +346,24 @@ public class NJTree
       }
     }
   }
+  /**
+   * rename any nodes according to their associated sequence.
+   * This will modify the tree's metadata! (ie the original NewickFile or newly generated BinaryTree's label data) 
+   */
+  public void renameAssociatedNodes() {
+    applyToNodes(new NodeTransformI() {
 
+      @Override
+      public void transform(BinaryNode node)
+      {
+        Object el = node.element();
+        if (el!=null && el instanceof SequenceI)
+        {
+          node.setName(((SequenceI)el).getName());
+        }
+      }
+    });
+  }
   /**
    * DOCUMENT ME!
    */
@@ -740,8 +758,9 @@ public class NJTree
           {
             try
             {
-              score += pwmatrix.getPairwiseScore(sequenceString[i]
-                      .charAt(k), sequenceString[j].charAt(k));
+              score += pwmatrix.getPairwiseScore(
+                      sequenceString[i].charAt(k),
+                      sequenceString[j].charAt(k));
             } catch (Exception ex)
             {
               System.err.println("err creating BLOSUM62 tree");