JAL-1807 Bob's first commit -- Applet loaded; needs image
[jalview.git] / src / jalview / analysis / ParseProperties.java
index 211f4e2..5fe7adb 100644 (file)
@@ -1,26 +1,32 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
- * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
  * 
- * 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 file is part of Jalview.
  * 
- * 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.
+ * Jalview 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 3
+ * of the License, or (at your option) any later version.
+ *  
+ * Jalview 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
+ * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
  */
 package jalview.analysis;
 
-import com.stevesoft.pat.Regex;
+//import com.stevesoft.pat.Regex;
 
-import jalview.datamodel.*;
+import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.SequenceI;
+import jalview.jsdev.RegExp;
+import jalview.jsdev.api.RegExpInterface;
 
 public class ParseProperties
 {
@@ -69,17 +75,17 @@ public class ParseProperties
    * Extract scores for sequences by applying regex to description string.
    * 
    * @param seqs
-   *                seuqences to extract annotation from.
+   *          seuqences to extract annotation from.
    * @param ScoreNames
-   *                labels for each numeric field in regex match
+   *          labels for each numeric field in regex match
    * @param ScoreDescriptions
-   *                description for each numeric field in regex match
+   *          description for each numeric field in regex match
    * @param regex
-   *                Regular Expression string for passing to
-   *                <code>new com.stevesoft.patt.Regex(regex)</code>
+   *          Regular Expression string for passing to
+   *          <code>new jalview.jsdevt.Regex(regex)</code>
    * @param repeat
-   *                true means the regex will be applied multiple times along
-   *                the description string of each sequence
+   *          true means the regex will be applied multiple times along the
+   *          description string of each sequence
    * @return total number of sequences that matched the regex
    */
   public int getScoresFromDescription(SequenceI[] seqs,
@@ -87,7 +93,7 @@ public class ParseProperties
           boolean repeat)
   {
     int count = 0;
-    Regex pattern = new Regex(regex);
+    RegExpInterface pattern = RegExp.newRegex(regex);
     if (pattern.numSubs() > ScoreNames.length)
     {
       // Check that we have enough labels and descriptions for any parsed
@@ -99,7 +105,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);
@@ -114,7 +122,9 @@ public class ParseProperties
     {
       String descr = seqs[i].getDescription();
       if (descr == null)
+      {
         continue;
+      }
       int pos = 0;
       boolean added = false;
       int reps = 0;
@@ -123,7 +133,7 @@ public class ParseProperties
         pos = pattern.matchedTo();
         for (int cols = 0; cols < pattern.numSubs(); cols++)
         {
-          String sstring = pattern.stringMatched(cols + 1);
+          String sstring = pattern.stringMatchedI(cols + 1);
           double score = Double.NaN;
           try
           {
@@ -138,7 +148,8 @@ public class ParseProperties
                   + ((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);
@@ -153,29 +164,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.");
-  }
 }