JAL-3210 Improvements to eclipse detection. New src tree and SwingJS updated from...
[jalview.git] / src / jalview / analysis / ParseProperties.java
index 8a1df43..9937a47 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2b1)
- * Copyright (C) 2014 The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
  * 
  * This file is part of Jalview.
  * 
  */
 package jalview.analysis;
 
-import com.stevesoft.pat.Regex;
+import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.SequenceI;
+import jalview.util.Platform;
 
-import jalview.datamodel.*;
+import com.stevesoft.pat.Regex;
 
 public class ParseProperties
 {
@@ -55,9 +58,9 @@ public class ParseProperties
   public int getScoresFromDescription(String ScoreName,
           String ScoreDescriptions, String regex, boolean repeat)
   {
-    return getScoresFromDescription(new String[]
-    { ScoreName }, new String[]
-    { ScoreDescriptions }, regex, repeat);
+    return getScoresFromDescription(new String[] { ScoreName },
+            new String[]
+            { ScoreDescriptions }, regex, repeat);
   }
 
   public int getScoresFromDescription(String[] ScoreNames,
@@ -84,12 +87,11 @@ public class ParseProperties
    *          description string of each sequence
    * @return total number of sequences that matched the regex
    */
-  public int getScoresFromDescription(SequenceI[] seqs,
-          String[] ScoreNames, String[] ScoreDescriptions, String regex,
-          boolean repeat)
+  public int getScoresFromDescription(SequenceI[] seqs, String[] ScoreNames,
+          String[] ScoreDescriptions, String regex, boolean repeat)
   {
     int count = 0;
-    Regex pattern = new Regex(regex);
+    Regex pattern = Platform.newRegex(regex, null);
     if (pattern.numSubs() > ScoreNames.length)
     {
       // Check that we have enough labels and descriptions for any parsed
@@ -101,7 +103,9 @@ public class ParseProperties
       ScoreNames = tnames;
       String descrbase = ScoreDescriptions[onamelen - 1];
       if (descrbase == null)
+      {
         descrbase = "Score parsed from (" + regex + ")";
+      }
       tnames = new String[pattern.numSubs() + 1];
       System.arraycopy(ScoreDescriptions, 0, tnames, 0,
               ScoreDescriptions.length);
@@ -116,7 +120,9 @@ public class ParseProperties
     {
       String descr = seqs[i].getDescription();
       if (descr == null)
+      {
         continue;
+      }
       int pos = 0;
       boolean added = false;
       int reps = 0;
@@ -136,11 +142,12 @@ public class ParseProperties
             continue;
           }
           // add score to sequence annotation.
-          AlignmentAnnotation an = new AlignmentAnnotation(ScoreNames[cols]
-                  + ((reps > 0) ? "_" + reps : ""),
+          AlignmentAnnotation an = new AlignmentAnnotation(
+                  ScoreNames[cols] + ((reps > 0) ? "_" + reps : ""),
                   ScoreDescriptions[cols], null);
           an.setScore(score);
-          System.out.println("Score: " + ScoreNames[cols] + "=" + score); // DEBUG
+          System.out.println(seqs[i].getName() + " score: '"
+                  + ScoreNames[cols] + "' = " + score); // DEBUG
           an.setSequenceRef(seqs[i]);
           seqs[i].addAlignmentAnnotation(an);
           al.addAnnotation(an);
@@ -155,29 +162,4 @@ public class ParseProperties
     }
     return count;
   }
-
-  public static void main(String argv[])
-  {
-    SequenceI[] seqs = new SequenceI[]
-    { new Sequence("sq1", "THISISAPLACEHOLDER"),
-        new Sequence("sq2", "THISISAPLACEHOLDER"),
-        new Sequence("sq3", "THISISAPLACEHOLDER"),
-        new Sequence("sq4", "THISISAPLACEHOLDER") };
-    seqs[0].setDescription("1 mydescription1");
-    seqs[1].setDescription("mydescription2");
-    seqs[2].setDescription("2. 0.1 mydescription3");
-    seqs[3].setDescription("3 0.01 mydescription4");
-    // seqs[4].setDescription("5 mydescription5");
-    Alignment al = new Alignment(seqs);
-    ParseProperties pp = new ParseProperties(al);
-    String regex = ".*([-0-9.+]+)";
-    System.out.println("Matched "
-            + pp.getScoresFromDescription("my Score",
-                    "my Score Description", regex, true) + " for " + regex);
-    regex = ".*([-0-9.+]+).+([-0-9.+]+).*";
-    System.out.println("Matched "
-            + pp.getScoresFromDescription("my Score",
-                    "my Score Description", regex, true) + " for " + regex);
-    System.out.println("Finished.");
-  }
 }