javadoc and bugfix
authorjprocter <Jim Procter>
Fri, 21 Dec 2007 15:05:33 +0000 (15:05 +0000)
committerjprocter <Jim Procter>
Fri, 21 Dec 2007 15:05:33 +0000 (15:05 +0000)
src/jalview/analysis/ParseProperties.java

index 43460d6..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,9 +77,11 @@ 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
@@ -100,10 +103,11 @@ public class ParseProperties
           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
@@ -120,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