JAL-1270 added test for regex actually used; include sequence name in
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Fri, 15 May 2015 13:11:40 +0000 (14:11 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Fri, 15 May 2015 13:11:40 +0000 (14:11 +0100)
sysout of extracted scores

src/jalview/analysis/ParseProperties.java
test/jalview/analysis/ParsePropertiesTest.java

index 38d8371..3347800 100644 (file)
@@ -22,7 +22,9 @@ package jalview.analysis;
 
 import com.stevesoft.pat.Regex;
 
-import jalview.datamodel.*;
+import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.SequenceI;
 
 public class ParseProperties
 {
@@ -101,7 +103,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);
@@ -116,7 +120,9 @@ public class ParseProperties
     {
       String descr = seqs[i].getDescription();
       if (descr == null)
+      {
         continue;
+      }
       int pos = 0;
       boolean added = false;
       int reps = 0;
@@ -140,7 +146,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);
index a679a46..a01d255 100644 (file)
@@ -3,6 +3,8 @@ package jalview.analysis;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
 
+import java.util.List;
+
 import org.junit.Before;
 import org.junit.Test;
 
@@ -47,9 +49,6 @@ public class ParsePropertiesTest
   @Test
   public void testGetScoresFromDescription()
   {
-    // TODO - test the regex actually used by Jalview?
-    // \\W*([-+eE0-9.]+)
-    // see AlignFrame.extractScores_actionPerformed
     String regex = ".*([-0-9.+]+)";
     final int count = pp.getScoresFromDescription("my Score",
             "my Score Description", regex, true);
@@ -138,4 +137,57 @@ public class ParsePropertiesTest
     assertEquals("my Score Description (column 1)", anns[1].description);
     assertEquals("my Score_1", anns[1].label);
   }
+
+  /**
+   * Test with a regex that looks for numbers separated by words - as currently
+   * used in Jalview (May 2015)
+   * 
+   * @see AlignFrame.extractScores_actionPerformed
+   */
+  @Test
+  public void testGetScoresFromDescription_wordBoundaries()
+  {
+    String regex = "\\W*([-+eE0-9.]+)";
+    List<SequenceI> seqs = al.getSequences();
+    seqs.get(0).setDescription("Ferredoxin");
+    seqs.get(1).setDescription(" Ferredoxin-1, chloroplast precursor");
+    seqs.get(2).setDescription("GH28E30p");
+    seqs.get(3).setDescription("At1g10960/T19D16_12");
+    final int count = pp.getScoresFromDescription("description column",
+            "score in description column ", regex, true);
+    assertEquals(3, count);
+
+    /*
+     * No score parsable from seq1 description
+     */
+    AlignmentAnnotation[] anns = al.getSequenceAt(0).getAnnotation();
+    assertNull(anns);
+
+    /*
+     * Seq2 description has a '1' in it
+     */
+    anns = al.getSequenceAt(1).getAnnotation();
+    assertEquals(1, anns.length);
+    assertEquals(1d, anns[0].getScore(), 0.001d);
+
+    /*
+     * Seq3 description has '28E30' in it
+     * 
+     * Note: 1.8E308 or larger would result in 'Infinity'
+     */
+    anns = al.getSequenceAt(2).getAnnotation();
+    assertEquals(1, anns.length);
+    assertEquals(2.8E31d, anns[0].getScore(), 0.001d);
+
+    /*
+     * Seq4 description has several numbers in it
+     */
+    anns = al.getSequenceAt(3).getAnnotation();
+    assertEquals(5, anns.length);
+    assertEquals(1d, anns[0].getScore(), 0.001d);
+    assertEquals(10960d, anns[1].getScore(), 0.001d);
+    assertEquals(19d, anns[2].getScore(), 0.001d);
+    assertEquals(16d, anns[3].getScore(), 0.001d);
+    assertEquals(12d, anns[4].getScore(), 0.001d);
+  }
 }