Merge branch 'kjvdh/features/PhylogenyViewer_tabbedsupport' into merge/2_11_2/kjvdh...
[jalview.git] / src / jalview / io / NewickFile.java
index 7444b5f..a283691 100755 (executable)
@@ -26,6 +26,8 @@
 // TODO: Extended SequenceNodeI to hold parsed NHX strings
 package jalview.io;
 
+import java.util.Locale;
+
 import jalview.datamodel.SequenceNode;
 import jalview.util.MessageManager;
 
@@ -35,6 +37,8 @@ import java.io.FileReader;
 import java.io.IOException;
 import java.util.StringTokenizer;
 
+import com.stevesoft.pat.Regex;
+
 /**
  * Parse a new hanpshire style tree Caveats: NHX files are NOT supported and the
  * tree distances and topology are unreliable when they are parsed. TODO: on
@@ -87,13 +91,13 @@ public class NewickFile extends FileParse
 
   boolean printRootInfo = true;
 
-  private com.stevesoft.pat.Regex[] NodeSafeName = new com.stevesoft.pat.Regex[] {
-      new com.stevesoft.pat.Regex().perlCode("m/[\\[,:'()]/"), // test for
+  private Regex[] NodeSafeName = new Regex[] {
+      new Regex().perlCode("m/[\\[,:'()]/"), // test for
       // requiring
       // quotes
-      new com.stevesoft.pat.Regex().perlCode("s/'/''/"), // escaping quote
+      new Regex().perlCode("s/'/''/"), // escaping quote
       // characters
-      new com.stevesoft.pat.Regex().perlCode("s/\\/w/_/") // unqoted whitespace
+      new Regex().perlCode("s/\\/w/_/") // unqoted whitespace
       // transformation
   };
 
@@ -292,8 +296,7 @@ public class NewickFile extends FileParse
     boolean ascending = false; // flag indicating that we are leaving the
     // current node
 
-    com.stevesoft.pat.Regex majorsyms = new com.stevesoft.pat.Regex(
-            "[(\\['),;]");
+    Regex majorsyms = new Regex("[(\\['),;]");
 
     int nextcp = 0;
     int ncp = cp;
@@ -314,8 +317,6 @@ public class NewickFile extends FileParse
 
           continue;
         }
-
-        ;
         d++;
 
         if (c.right() == null)
@@ -354,8 +355,7 @@ public class NewickFile extends FileParse
       // Deal with quoted fields
       case '\'':
 
-        com.stevesoft.pat.Regex qnodename = new com.stevesoft.pat.Regex(
-                "'([^']|'')+'");
+        Regex qnodename = new Regex("'([^']|'')+'");
 
         if (qnodename.searchFrom(nf, fcp))
         {
@@ -363,8 +363,7 @@ public class NewickFile extends FileParse
           nodename = new String(
                   qnodename.stringMatched().substring(1, nl - 1));
           // unpack any escaped colons
-          com.stevesoft.pat.Regex xpandquotes = com.stevesoft.pat.Regex
-                  .perlCode("s/''/'/");
+          Regex xpandquotes = Regex.perlCode("s/''/'/");
           String widernodename = xpandquotes.replaceAll(nodename);
           nodename = widernodename;
           // jump to after end of quoted nodename
@@ -398,8 +397,7 @@ public class NewickFile extends FileParse
            * '"+nf.substring(cp,fcp)+"'"); }
            */
           // verify termination.
-          com.stevesoft.pat.Regex comment = new com.stevesoft.pat.Regex(
-                  "]");
+          Regex comment = new Regex("]");
           if (comment.searchFrom(nf, fcp))
           {
             // Skip the comment field
@@ -415,8 +413,6 @@ public class NewickFile extends FileParse
             Error = ErrorStringrange(Error, "Unterminated comment", 3, fcp,
                     nf);
           }
-
-          ;
         }
         // Parse simpler field strings
         String fstring = nf.substring(ncp, fcp);
@@ -432,12 +428,9 @@ public class NewickFile extends FileParse
                   + fstring.substring(cend + 1);
 
         }
-        com.stevesoft.pat.Regex uqnodename = new com.stevesoft.pat.Regex(
-                "\\b([^' :;\\](),]+)");
-        com.stevesoft.pat.Regex nbootstrap = new com.stevesoft.pat.Regex(
-                "\\s*([0-9+]+)\\s*:");
-        com.stevesoft.pat.Regex ndist = new com.stevesoft.pat.Regex(
-                ":([-0-9Ee.+]+)");
+        Regex uqnodename = new Regex("\\b([^' :;\\](),]+)");
+        Regex nbootstrap = new Regex("\\s*([0-9+]+)\\s*:");
+        Regex ndist = new Regex(":([-0-9Ee.+]+)");
 
         if (!parsednodename && uqnodename.search(fstring)
                 && ((uqnodename.matchedFrom(1) == 0) || (fstring
@@ -477,7 +470,7 @@ public class NewickFile extends FileParse
           {
             try
             {
-              bootstrap = (new Integer(nbootstrap.stringMatched(1)))
+              bootstrap = (Integer.valueOf(nbootstrap.stringMatched(1)))
                       .intValue();
               hasBootstrap = true;
             } catch (Exception e)
@@ -494,8 +487,8 @@ public class NewickFile extends FileParse
         {
           try
           {
-            distance = (new Float(ndist.stringMatched(1))).floatValue();
-            hasDistances = true;
+            distance = (Float.valueOf(ndist.stringMatched(1))).floatValue();
+            HasDistances = true;
             nodehasdistance = true;
           } catch (Exception e)
           {
@@ -658,10 +651,10 @@ public class NewickFile extends FileParse
           try
           {
             // parse out code/value pairs
-            if (code.toLowerCase().equals("b"))
+            if (code.toLowerCase(Locale.ROOT).equals("b"))
             {
               int v = -1;
-              Float iv = new Float(value);
+              Float iv = Float.valueOf(value);
               v = iv.intValue(); // jalview only does integer bootstraps
               // currently
               c.setBootstrap(v);
@@ -940,7 +933,11 @@ public class NewickFile extends FileParse
     }
   }
 
-  // Test
+  /**
+   * 
+   * @param args
+   * @j2sIgnore
+   */
   public static void main(String[] args)
   {
     try
@@ -970,7 +967,7 @@ public class NewickFile extends FileParse
       trf.parse();
       System.out.println("Original file :\n");
 
-      com.stevesoft.pat.Regex nonl = new com.stevesoft.pat.Regex("\n+", "");
+      Regex nonl = new Regex("\n+", "");
       System.out.println(nonl.replaceAll(newickfile.toString()) + "\n");
 
       System.out.println("Parsed file.\n");