From 42498abb930c08393b09fc7af2564b7f210ac294 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Wed, 7 Jun 2017 10:22:24 +0100 Subject: [PATCH] JAL-2386 ensure group conservation shading is applied from slider --- src/jalview/appletgui/SliderPanel.java | 62 ++++++++++++++----------- src/jalview/datamodel/SequenceGroup.java | 2 +- src/jalview/gui/SliderPanel.java | 31 +++++++++++-- test/jalview/datamodel/SequenceGroupTest.java | 2 +- 4 files changed, 64 insertions(+), 33 deletions(-) diff --git a/src/jalview/appletgui/SliderPanel.java b/src/jalview/appletgui/SliderPanel.java index 9154aa0..47a0669 100644 --- a/src/jalview/appletgui/SliderPanel.java +++ b/src/jalview/appletgui/SliderPanel.java @@ -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 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 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); } diff --git a/src/jalview/datamodel/SequenceGroup.java b/src/jalview/datamodel/SequenceGroup.java index 463b909..a8d0a36 100755 --- a/src/jalview/datamodel/SequenceGroup.java +++ b/src/jalview/datamodel/SequenceGroup.java @@ -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); diff --git a/src/jalview/gui/SliderPanel.java b/src/jalview/gui/SliderPanel.java index 0c4e03e..ec53e93 100755 --- a/src/jalview/gui/SliderPanel.java +++ b/src/jalview/gui/SliderPanel.java @@ -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 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 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()); } /** diff --git a/test/jalview/datamodel/SequenceGroupTest.java b/test/jalview/datamodel/SequenceGroupTest.java index f6d4028..80790ed 100644 --- a/test/jalview/datamodel/SequenceGroupTest.java +++ b/test/jalview/datamodel/SequenceGroupTest.java @@ -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()); -- 1.7.10.2