JAL-2386 ensure group conservation shading is applied from slider
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Wed, 7 Jun 2017 09:22:24 +0000 (10:22 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Wed, 7 Jun 2017 09:22:24 +0000 (10:22 +0100)
src/jalview/appletgui/SliderPanel.java
src/jalview/datamodel/SequenceGroup.java
src/jalview/gui/SliderPanel.java
test/jalview/datamodel/SequenceGroupTest.java

index 9154aa0..47a0669 100644 (file)
@@ -20,6 +20,7 @@
  */
 package jalview.appletgui;
 
+import jalview.analysis.Conservation;
 import jalview.datamodel.SequenceGroup;
 import jalview.renderer.ResidueShaderI;
 import jalview.util.MessageManager;
@@ -44,7 +45,7 @@ import java.awt.event.MouseEvent;
 import java.awt.event.MouseListener;
 import java.awt.event.WindowAdapter;
 import java.awt.event.WindowEvent;
-import java.util.Iterator;
+import java.util.List;
 
 public class SliderPanel extends Panel implements ActionListener,
         AdjustmentListener, MouseListener
@@ -82,7 +83,8 @@ public class SliderPanel extends Panel implements ActionListener,
     conservationSlider.setTitle(MessageManager.formatMessage(
             "label.conservation_colour_increment",
             new String[] { source == null ? BACKGROUND : source }));
-    if (ap.av.getAlignment().getGroups() != null)
+    List<SequenceGroup> groups = ap.av.getAlignment().getGroups();
+    if (groups != null && !groups.isEmpty())
     {
       sp.setAllGroupsCheckEnabled(true);
     }
@@ -248,45 +250,53 @@ public class SliderPanel extends Panel implements ActionListener,
     {
       return;
     }
-
-    ResidueShaderI toChange = cs;
-    Iterator<SequenceGroup> allGroups = null;
-
-    if (allGroupsCheck.getState())
+    if (forConservation)
     {
-      allGroups = ap.av.getAlignment().getGroups().listIterator();
+      cs.setConservationApplied(true);
+      cs.setConservationInc(i);
+    }
+    else
+    {
+      cs.setThreshold(i, ap.av.isIgnoreGapsConsensus());
     }
 
-    while (toChange != null)
+    if (allGroupsCheck.getState())
     {
-      if (forConservation)
+      for (SequenceGroup group : ap.av.getAlignment().getGroups())
       {
-        toChange.setConservationInc(i);
-      }
-      else
-      {
-        toChange.setThreshold(i, ap.av.isIgnoreGapsConsensus());
-      }
-      if (allGroups != null && allGroups.hasNext())
-      {
-        while ((toChange = allGroups.next().cs) == null
-                && allGroups.hasNext())
+        ResidueShaderI groupColourScheme = group.getGroupColourScheme();
+        if (forConservation)
         {
-          ;
+          if (!groupColourScheme.conservationApplied())
+          {
+            /*
+             * first time the colour scheme has had Conservation shading applied
+             * - compute conservation
+             */
+            Conservation c = new Conservation("Group",
+                    group.getSequences(null), group.getStartRes(),
+                    group.getEndRes());
+            c.calculate();
+            c.verdict(false, ap.av.getConsPercGaps());
+            group.cs.setConservation(c);
+
+          }
+          groupColourScheme.setConservationApplied(true);
+          groupColourScheme.setConservationInc(i);
+        }
+        else
+        {
+          groupColourScheme.setThreshold(i, ap.av.isIgnoreGapsConsensus());
         }
-      }
-      else
-      {
-        toChange = null;
       }
     }
 
     ap.seqPanel.seqCanvas.repaint();
-
   }
 
   public void setAllGroupsCheckEnabled(boolean b)
   {
+    allGroupsCheck.setState(ap.av.getColourAppliesToAllGroups());
     allGroupsCheck.setEnabled(b);
   }
 
index 463b909..a8d0a36 100755 (executable)
@@ -188,7 +188,7 @@ public class SequenceGroup implements AnnotatedCollectionI
       colourText = seqsel.colourText;
       startRes = seqsel.startRes;
       endRes = seqsel.endRes;
-      cs = new ResidueShader(seqsel.getColourScheme());
+      cs = seqsel.cs;// new ResidueShader(seqsel.getColourScheme());
       if (seqsel.description != null)
       {
         description = new String(seqsel.description);
index 0c4e03e..ec53e93 100755 (executable)
@@ -20,6 +20,7 @@
  */
 package jalview.gui;
 
+import jalview.analysis.Conservation;
 import jalview.datamodel.SequenceGroup;
 import jalview.jbgui.GSliderPanel;
 import jalview.renderer.ResidueShaderI;
@@ -28,6 +29,7 @@ import jalview.util.MessageManager;
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
 import java.beans.PropertyVetoException;
+import java.util.List;
 
 import javax.swing.JInternalFrame;
 import javax.swing.JLayeredPane;
@@ -170,7 +172,8 @@ public class SliderPanel extends GSliderPanel
             "label.conservation_colour_increment",
             new String[] { source == null ? BACKGROUND : source }));
 
-    if (ap.av.getAlignment().getGroups() != null)
+    List<SequenceGroup> groups = ap.av.getAlignment().getGroups();
+    if (groups != null && !groups.isEmpty())
     {
       sliderPanel.setAllGroupsCheckEnabled(true);
     }
@@ -331,13 +334,14 @@ public class SliderPanel extends GSliderPanel
     {
       ap.av.setThreshold(percent);
     }
-    updateColourScheme(percent, cs);
+    updateColourScheme(percent, cs, null);
 
     if (allGroupsCheck.isSelected())
     {
-      for (SequenceGroup sg : ap.av.getAlignment().getGroups())
+      List<SequenceGroup> groups = ap.av.getAlignment().getGroups();
+      for (SequenceGroup sg : groups)
       {
-        updateColourScheme(percent, sg.getGroupColourScheme());
+        updateColourScheme(percent, sg.getGroupColourScheme(), sg);
       }
     }
 
@@ -350,8 +354,10 @@ public class SliderPanel extends GSliderPanel
    * 
    * @param percent
    * @param scheme
+   * @param sg
    */
-  protected void updateColourScheme(int percent, ResidueShaderI scheme)
+  protected void updateColourScheme(int percent, ResidueShaderI scheme,
+          SequenceGroup sg)
   {
     if (scheme == null)
     {
@@ -359,6 +365,20 @@ public class SliderPanel extends GSliderPanel
     }
     if (forConservation)
     {
+      if (!scheme.conservationApplied())
+      {
+        /*
+         * first time the colour scheme has had Conservation shading applied
+         * - compute conservation
+         */
+        Conservation c = new Conservation("Group", sg.getSequences(null),
+                sg.getStartRes(), sg.getEndRes());
+        c.calculate();
+        c.verdict(false, ap.av.getConsPercGaps());
+        sg.cs.setConservation(c);
+
+      }
+      scheme.setConservationApplied(true);
       scheme.setConservationInc(percent);
     }
     else
@@ -376,6 +396,7 @@ public class SliderPanel extends GSliderPanel
   public void setAllGroupsCheckEnabled(boolean b)
   {
     allGroupsCheck.setEnabled(b);
+    allGroupsCheck.setSelected(ap.av.getColourAppliesToAllGroups());
   }
 
   /**
index f6d4028..80790ed 100644 (file)
@@ -253,7 +253,7 @@ public class SequenceGroupTest
     SequenceGroup sg2 = new SequenceGroup(sg);
     assertEquals(sg2.getName(), sg.getName());
     assertEquals(sg2.getDescription(), sg.getDescription());
-    assertNotSame(sg2.getGroupColourScheme(), sg.getGroupColourScheme());
+    assertSame(sg2.getGroupColourScheme(), sg.getGroupColourScheme());
     assertSame(sg2.getColourScheme(), sg.getColourScheme());
     assertEquals(sg2.getDisplayBoxes(), sg.getDisplayBoxes());
     assertEquals(sg2.getDisplayText(), sg.getDisplayText());