{\r
/**\r
* Methods for parsing free text properties on alignments and sequences.\r
+ * There are a number of ways we might want to do this:\r
+ * arbitrary regex. and an associated score name for the number that's extracted.\r
+ * Regex that provides both score and name.\r
+ * \r
+ * We may also want to :\r
+ * - modify description to remove parsed numbers (this behaviour is dangerous since exporting the alignment would lose the original form then)\r
+ * - \r
+ * \r
*/\r
/**\r
* The alignment being operated on\r
* initialise a new property parser\r
* @param al\r
*/\r
- ParseProperties(AlignmentI al) {\r
+ public ParseProperties(AlignmentI al) {\r
this.al = al;\r
}\r
\r
System.arraycopy(ScoreNames, 0, tnames, 0, ScoreNames.length);\r
String base = tnames[ScoreNames.length-1];\r
ScoreNames = tnames;\r
- String descrbase = ScoreDescriptions[ScoreNames.length-1];\r
+ String descrbase = ScoreDescriptions[onamelen-1];\r
if (descrbase == null)\r
descrbase = "Score parsed from ("+regex+")";\r
- tnames = new String[pattern.numSubs()];\r
+ tnames = new String[pattern.numSubs()+1];\r
System.arraycopy(ScoreDescriptions, 0, tnames, 0, ScoreDescriptions.length);\r
ScoreDescriptions = tnames;\r
for (int i=onamelen; i<ScoreNames.length; i++)\r
for (int i=0; i<seqs.length; i++)\r
{\r
String descr = seqs[i].getDescription();\r
+ if (descr==null)\r
+ continue;\r
if (pattern.search(descr))\r
{\r
boolean added=false;\r
for (int cols=0; cols<pattern.numSubs(); cols++)\r
{\r
- String sstring = pattern.stringMatched(cols);\r
+ String sstring = pattern.stringMatched(cols+1);\r
float score;\r
try {\r
score = new Float(sstring).floatValue();\r
//seqs[4].setDescription("5 mydescription5");\r
Alignment al = new Alignment(seqs);\r
ParseProperties pp = new ParseProperties(al);\r
- String regex = ".*([-0-9.+]+).*";\r
+ String regex = ".*([-0-9.+]+)";\r
System.out.println("Matched "+pp.getScoresFromDescription("my Score", "my Score Description",regex)+" for "+regex);\r
regex = ".*([-0-9.+]+).+([-0-9.+]+).*";\r
System.out.println("Matched "+pp.getScoresFromDescription("my Score", "my Score Description",regex)+" for "+regex);\r
- \r
+ System.out.println("Finished.");\r
}\r
}\r