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
* @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
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
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
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