Merge branch 'features/JAL-2503_filteronquantitativeannotation' into develop
authorJim Procter <jprocter@issues.jalview.org>
Thu, 4 May 2017 08:53:10 +0000 (09:53 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Thu, 4 May 2017 08:53:10 +0000 (09:53 +0100)
src/jalview/appletgui/AnnotationColumnChooser.java
src/jalview/datamodel/AlignmentAnnotation.java
src/jalview/gui/AnnotationColumnChooser.java
test/jalview/datamodel/AlignmentAnnotationTests.java

index 77bb6bb..25ff293 100644 (file)
@@ -444,7 +444,7 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements
       // build filter params
       filterParams
               .setThresholdType(AnnotationFilterParameter.ThresholdType.NO_THRESHOLD);
-      if (getCurrentAnnotation().graph != AlignmentAnnotation.NO_GRAPH)
+      if (getCurrentAnnotation().isQuantitative())
       {
         filterParams
                 .setThresholdValue(getCurrentAnnotation().threshold.value);
@@ -598,7 +598,7 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements
   {
     String currentView = AnnotationColumnChooser.NO_GRAPH_VIEW;
     if (av.getAlignment().getAlignmentAnnotation()[getAnnotations()
-            .getSelectedIndex()].graph != AlignmentAnnotation.NO_GRAPH)
+            .getSelectedIndex()].isQuantitative())
     {
       currentView = AnnotationColumnChooser.GRAPH_VIEW;
     }
index 6117baf..543958e 100755 (executable)
@@ -1494,4 +1494,13 @@ public class AlignmentAnnotation
   {
     return counter++;
   }
+
+  /**
+   * 
+   * @return true for rows that have a range of values in their annotation set
+   */
+  public boolean isQuantitative()
+  {
+    return graphMin < graphMax;
+  }
 }
index d5bc7d1..73660ec 100644 (file)
@@ -21,7 +21,6 @@
 
 package jalview.gui;
 
-import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.ColumnSelection;
 import jalview.schemes.AnnotationColourGradient;
 import jalview.util.MessageManager;
@@ -328,7 +327,7 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements
       // build filter params
       filterParams
               .setThresholdType(AnnotationFilterParameter.ThresholdType.NO_THRESHOLD);
-      if (getCurrentAnnotation().graph != AlignmentAnnotation.NO_GRAPH)
+      if (getCurrentAnnotation().isQuantitative())
       {
         filterParams
                 .setThresholdValue(getCurrentAnnotation().threshold.value);
@@ -489,8 +488,9 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements
   public void selectedAnnotationChanged()
   {
     String currentView = AnnotationColumnChooser.NO_GRAPH_VIEW;
-    if (av.getAlignment().getAlignmentAnnotation()[annmap[getAnnotations()
-            .getSelectedIndex()]].graph != AlignmentAnnotation.NO_GRAPH)
+    if (av.getAlignment()
+            .getAlignmentAnnotation()[annmap[getAnnotations()
+            .getSelectedIndex()]].isQuantitative())
     {
       currentView = AnnotationColumnChooser.GRAPH_VIEW;
     }
index a2c6256..e47e9d6 100644 (file)
@@ -28,6 +28,7 @@ import jalview.gui.JvOptionPane;
 import jalview.io.AppletFormatAdapter;
 import jalview.io.FileFormat;
 
+import org.testng.Assert;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
@@ -293,4 +294,45 @@ public class AlignmentAnnotationTests
               ann.getDefaultRnaHelixSymbol(i));
     }
   }
+
+  public static Annotation newAnnotation(String ann)
+  {
+    float val = 0f;
+    try
+    {
+      val = Float.parseFloat(ann);
+    } catch (NumberFormatException q)
+    {
+    }
+    ;
+    return new Annotation(ann, ann, '\0', val);
+  }
+
+  @Test(groups = { "Functional" })
+  public void testIsQuantitative()
+  {
+    AlignmentAnnotation ann = null;
+
+    ann = new AlignmentAnnotation("an", "some an", null);
+    Assert.assertFalse(ann.isQuantitative(),
+            "Empty annotation set should not be quantitative.");
+
+    ann = new AlignmentAnnotation("an", "some an", new Annotation[] {
+        newAnnotation("4"), newAnnotation("1"), newAnnotation("1"),
+        newAnnotation("0.1"), newAnnotation("0.3") });
+    Assert.assertTrue(ann.isQuantitative(),
+            "All numbers annotation set should be quantitative.");
+
+    ann = new AlignmentAnnotation("an", "some an", new Annotation[] {
+        newAnnotation("E"), newAnnotation("E"), newAnnotation("E"),
+        newAnnotation("E"), newAnnotation("E") });
+    Assert.assertFalse(ann.isQuantitative(),
+            "All 'E' annotation set should not be quantitative.");
+
+    ann = new AlignmentAnnotation("an", "some an", new Annotation[] {
+        newAnnotation("E"), newAnnotation("1"), newAnnotation("2"),
+        newAnnotation("3"), newAnnotation("E") });
+    Assert.assertTrue(ann.isQuantitative(),
+            "Mixed 'E' annotation set should be quantitative.");
+  }
 }