merge from 2_4_Release branch
[jalview.git] / src / jalview / io / NewickFile.java
index 9a7f6fb..8dc2389 100755 (executable)
@@ -1,22 +1,21 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
- *
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
+ * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ * 
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
  * as published by the Free Software Foundation; either version 2
  * of the License, or (at your option) any later version.
- *
+ * 
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *
+ * 
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
  */
-
 // NewickFile.java
 // Tree I/O
 // http://evolution.genetics.washington.edu/phylip/newick_doc.html
@@ -84,12 +83,12 @@ public class NewickFile extends FileParse
 
   private com.stevesoft.pat.Regex[] NodeSafeName = new com.stevesoft.pat.Regex[]
   { new com.stevesoft.pat.Regex().perlCode("m/[\\[,:'()]/"), // test for
-                                                              // requiring
-                                                              // quotes
+      // requiring
+      // quotes
       new com.stevesoft.pat.Regex().perlCode("s/'/''/"), // escaping quote
-                                                          // characters
+      // characters
       new com.stevesoft.pat.Regex().perlCode("s/\\/w/_/") // unqoted whitespace
-                                                          // transformation
+  // transformation
   };
 
   char QuoteChar = '\'';
@@ -280,14 +279,14 @@ public class NewickFile extends FileParse
     String commentString2 = null; // comments after simple node props
 
     float DefDistance = (float) 0.001; // @param Default distance for a node -
-                                        // very very small
+    // very very small
     int DefBootstrap = -1; // @param Default bootstrap for a node
 
     float distance = DefDistance;
     int bootstrap = DefBootstrap;
 
     boolean ascending = false; // flag indicating that we are leaving the
-                                // current node
+    // current node
 
     com.stevesoft.pat.Regex majorsyms = new com.stevesoft.pat.Regex(
             "[(\\['),;]");
@@ -430,7 +429,7 @@ public class NewickFile extends FileParse
         if (uqnodename.search(fstring)
                 && ((uqnodename.matchedFrom(1) == 0) || (fstring
                         .charAt(uqnodename.matchedFrom(1) - 1) != ':'))) // JBPNote
-                                                                          // HACK!
+        // HACK!
         {
           if (nodename == null)
           {
@@ -506,8 +505,8 @@ public class NewickFile extends FileParse
           if (c == realroot)
           {
             RootHasDistance = nodehasdistance; // JBPNote This is really
-                                                // UGLY!!! Ensure root node gets
-                                                // its given distance
+            // UGLY!!! Ensure root node gets
+            // its given distance
           }
           parseNHXNodeProps(c, commentString2);
           commentString2 = null;
@@ -585,7 +584,7 @@ public class NewickFile extends FileParse
         nodename = null;
         distance = DefDistance;
         bootstrap = DefBootstrap;
-        commentString2=null;
+        commentString2 = null;
       }
       if (nextcp == 0)
       {
@@ -630,39 +629,40 @@ public class NewickFile extends FileParse
     // tree is output
     if (commentString != null && commentString.startsWith("&&NHX"))
     {
-      StringTokenizer st = new StringTokenizer(commentString.substring(5),":");
+      StringTokenizer st = new StringTokenizer(commentString.substring(5),
+              ":");
       while (st.hasMoreTokens())
       {
         String tok = st.nextToken();
-        int colpos=tok.indexOf("=");
+        int colpos = tok.indexOf("=");
 
-        if (colpos>-1)
+        if (colpos > -1)
         {
           String code = tok.substring(0, colpos);
-          String value = tok.substring(colpos+1);
-          try {
+          String value = tok.substring(colpos + 1);
+          try
+          {
             // parse out code/value pairs
             if (code.toLowerCase().equals("b"))
             {
-              int v=-1;
+              int v = -1;
               Float iv = new Float(value);
               v = iv.intValue(); // jalview only does integer bootstraps
-                                  // currently
+              // currently
               c.setBootstrap(v);
               HasBootstrap = true;
             }
             // more codes here.
-          }
-          catch (Exception e)
+          } catch (Exception e)
           {
-            System.err.println("Couldn't parse code '"+code+"' = '"+value+"'");
+            System.err.println("Couldn't parse code '" + code + "' = '"
+                    + value + "'");
             e.printStackTrace(System.err);
           }
         }
       }
     }
-        
-      
+
   }
 
   /**