trailing slash regexed out
[jalview.git] / src / jalview / analysis / ParseProperties.java
index c23cb3a..587e501 100644 (file)
@@ -30,14 +30,14 @@ public class ParseProperties
     this.al = al;\r
   }\r
 \r
-  public int getScoresFromDescription(String ScoreName, String ScoreDescriptions, String regex)\r
+  public int getScoresFromDescription(String ScoreName, String ScoreDescriptions, String regex, boolean repeat)\r
   {\r
-    return getScoresFromDescription(new String[] { ScoreName }, new String[] { ScoreDescriptions}, regex);\r
+    return getScoresFromDescription(new String[] { ScoreName }, new String[] { ScoreDescriptions}, regex, repeat);\r
   }\r
 \r
-  public int getScoresFromDescription(String[] ScoreNames, String[] ScoreDescriptions, String regex) \r
+  public int getScoresFromDescription(String[] ScoreNames, String[] ScoreDescriptions, String regex, boolean repeat) \r
   {\r
-    return getScoresFromDescription(al.getSequencesArray(), ScoreNames, ScoreDescriptions, regex);\r
+    return getScoresFromDescription(al.getSequencesArray(), ScoreNames, ScoreDescriptions, regex, repeat);\r
   }\r
   /**\r
    * Extract scores for sequences by applying regex to description string.\r
@@ -45,9 +45,10 @@ public class ParseProperties
    * @param ScoreNames labels for each numeric field in regex match\r
    * @param ScoreDescriptions description for each numeric field in regex match\r
    * @param regex Regular Expression string for passing to <code>new com.stevesoft.patt.Regex(regex)</code>\r
+   * @param repeat true means the regex will be applied multiple times along the description string of each sequence\r
    * @return total number of sequences that matched the regex\r
    */\r
-  public int getScoresFromDescription(SequenceI[] seqs, String[] ScoreNames, String[] ScoreDescriptions, String regex) \r
+  public int getScoresFromDescription(SequenceI[] seqs, String[] ScoreNames, String[] ScoreDescriptions, String regex, boolean repeat) \r
   {\r
     int count=0;\r
     Regex pattern = new Regex(regex);\r
@@ -76,15 +77,17 @@ public class ParseProperties
       String descr = seqs[i].getDescription();\r
       if (descr==null)\r
         continue;\r
-      if (pattern.search(descr))\r
+      int pos=0;\r
+      boolean added=false;\r
+      while ((repeat || pos==0) && pattern.searchFrom(descr, pos))\r
       {\r
-        boolean added=false;\r
+        pos = pattern.matchedTo();\r
         for (int cols=0; cols<pattern.numSubs(); cols++)\r
         {\r
           String sstring = pattern.stringMatched(cols+1);\r
-          float score;\r
+          double score=Double.NaN;\r
           try {\r
-            score = new Float(sstring).floatValue();\r
+            score = new Double(sstring).doubleValue();\r
           }\r
           catch (Exception e)\r
           {\r
@@ -94,14 +97,17 @@ public class ParseProperties
           // add score to sequence annotation.\r
           AlignmentAnnotation an = new AlignmentAnnotation(ScoreNames[cols], ScoreDescriptions[cols], null);\r
           an.setScore(score);\r
+          System.out.println("Score: "+ScoreNames[cols]+"="+score); // DEBUG\r
+          an.setSequenceRef(seqs[i]);\r
           seqs[i].addAlignmentAnnotation(an);\r
           al.addAnnotation(an);\r
           added=true;\r
         }\r
-        if (added)\r
-          count++;\r
       }\r
-      \r
+      if (added)\r
+      {\r
+        count++;\r
+      }\r
     }\r
     return count; \r
   }\r
@@ -118,9 +124,9 @@ public class ParseProperties
     Alignment al = new Alignment(seqs);\r
     ParseProperties pp = new ParseProperties(al);\r
     String regex = ".*([-0-9.+]+)";\r
-    System.out.println("Matched "+pp.getScoresFromDescription("my Score", "my Score Description",regex)+" for "+regex);\r
+    System.out.println("Matched "+pp.getScoresFromDescription("my Score", "my Score Description",regex, true)+" for "+regex);\r
     regex = ".*([-0-9.+]+).+([-0-9.+]+).*";\r
-    System.out.println("Matched "+pp.getScoresFromDescription("my Score", "my Score Description",regex)+" for "+regex);\r
+    System.out.println("Matched "+pp.getScoresFromDescription("my Score", "my Score Description",regex, true)+" for "+regex);\r
     System.out.println("Finished.");\r
   }\r
 }\r