From 279af6f3b1803de7a1e467b83a7205df18e70d48 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Thu, 1 May 2014 15:33:59 +0100 Subject: [PATCH] JAL-1492 JAL-1397 JAL-643 JAL-969 pull up global and group colourscheme logic and regularise interface --- src/jalview/appletgui/AlignFrame.java | 34 +++------------ src/jalview/datamodel/SequenceGroup.java | 20 ++++++++- src/jalview/gui/AlignFrame.java | 3 -- src/jalview/viewmodel/AlignmentViewport.java | 59 +++++++++++++------------- 4 files changed, 54 insertions(+), 62 deletions(-) diff --git a/src/jalview/appletgui/AlignFrame.java b/src/jalview/appletgui/AlignFrame.java index fbb61de..40999c6 100644 --- a/src/jalview/appletgui/AlignFrame.java +++ b/src/jalview/appletgui/AlignFrame.java @@ -2328,42 +2328,20 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, { if (viewport.getAbovePIDThreshold()) { - threshold = SliderPanel.setPIDSliderSource(alignPanel, cs, - "Background"); - - cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus()); - - viewport.setGlobalColourScheme(cs); - } - else - { - cs.setThreshold(0, viewport.getIgnoreGapsConsensus()); - } + viewport.setThreshold(SliderPanel.setPIDSliderSource(alignPanel, cs, + "Background")); + } if (viewport.getConservationSelected()) { - - Alignment al = (Alignment) viewport.getAlignment(); - Conservation c = new Conservation("All", - ResidueProperties.propHash, 3, al.getSequences(), 0, - al.getWidth() - 1); - - c.calculate(); - c.verdict(false, viewport.getConsPercGaps()); - - cs.setConservation(c); - - cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel, + cs.setConservationApplied(true); + viewport.setIncrement(SliderPanel.setConservationSlider(alignPanel, cs, "Background")); - } else { - cs.setConservation(null); + cs.setConservationApplied(false); } - - cs.setConsensus(viewport.getSequenceConsensusHash()); - } viewport.setGlobalColourScheme(cs); diff --git a/src/jalview/datamodel/SequenceGroup.java b/src/jalview/datamodel/SequenceGroup.java index 5d0841e..521bdbe 100755 --- a/src/jalview/datamodel/SequenceGroup.java +++ b/src/jalview/datamodel/SequenceGroup.java @@ -470,12 +470,28 @@ public class SequenceGroup implements AnnotatedCollectionI } /** - * Max Gaps Threshold for performing a conservation calculation TODO: make - * this a configurable property - or global to an alignment view + * Max Gaps Threshold (percent) for performing a conservation calculation */ private int consPercGaps = 25; /** + * @return Max Gaps Threshold for performing a conservation calculation + */ + public int getConsPercGaps() + { + return consPercGaps; + } + + /** + * set Max Gaps Threshold (percent) for performing a conservation calculation + * @param consPercGaps + */ + public void setConsPercGaps(int consPercGaps) + { + this.consPercGaps = consPercGaps; + } + + /** * calculate residue conservation for group - but only if necessary. */ public void recalcConservation() diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 353a139..d475c91 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -3235,10 +3235,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { threshold = SliderPanel.setPIDSliderSource(alignPanel, cs, "Background"); - cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus()); - - viewport.setGlobalColourScheme(cs); } else { diff --git a/src/jalview/viewmodel/AlignmentViewport.java b/src/jalview/viewmodel/AlignmentViewport.java index 7e383a9..44ecf76 100644 --- a/src/jalview/viewmodel/AlignmentViewport.java +++ b/src/jalview/viewmodel/AlignmentViewport.java @@ -212,6 +212,24 @@ public abstract class AlignmentViewport implements AlignViewportI // calculation till later or to do all calculations in thread. // via changecolour globalColourScheme = cs; + boolean recalc=false; + if (cs!=null) + { + cs.setConservationApplied(recalc = getConservationSelected()); + if (getAbovePIDThreshold() || cs instanceof PIDColourScheme || cs instanceof Blosum62ColourScheme) + { + recalc = true; + cs.setThreshold(threshold, ignoreGapsInConsensusCalculation); + } else { + cs.setThreshold(0, ignoreGapsInConsensusCalculation); + } + if (recalc) + { + cs.setConsensus(hconsensus); + cs.setConservation(hconservation); + } + cs.alignmentChanged(alignment, hiddenRepSequences); + } if (getColourAppliesToAllGroups()) { for (SequenceGroup sg : getAlignment().getGroups()) @@ -221,29 +239,13 @@ public abstract class AlignmentViewport implements AlignViewportI sg.cs = null; continue; } - if (cs instanceof ClustalxColourScheme) - { - sg.cs = new ClustalxColourScheme(sg, getHiddenRepSequences()); - } - else - { - try - { - sg.cs = cs.getClass().newInstance(); - } catch (Exception ex) - { - ex.printStackTrace(); - sg.cs = cs; - } - } - + sg.cs = cs.applyTo(sg, getHiddenRepSequences()); + sg.setConsPercGaps(ConsPercGaps); if (getAbovePIDThreshold() || cs instanceof PIDColourScheme || cs instanceof Blosum62ColourScheme) { sg.cs.setThreshold(threshold, getIgnoreGapsConsensus()); - sg.cs.setConsensus(AAFrequency.calculate( - sg.getSequences(getHiddenRepSequences()), 0, - sg.getWidth())); + recalc=true; } else { @@ -252,20 +254,19 @@ public abstract class AlignmentViewport implements AlignViewportI if (getConservationSelected()) { - Conservation c = new Conservation("Group", - ResidueProperties.propHash, 3, - sg.getSequences(getHiddenRepSequences()), 0, - getAlignment().getWidth() - 1); - c.calculate(); - c.verdict(false, getConsPercGaps()); - sg.cs.setConservation(c); + sg.cs.setConservationApplied(true); + recalc=true; } else { sg.cs.setConservation(null); - sg.cs.setThreshold(0, getIgnoreGapsConsensus()); + // sg.cs.setThreshold(0, getIgnoreGapsConsensus()); + } + if (recalc) { + sg.recalcConservation(); + } else { + sg.cs.alignmentChanged(sg, hiddenRepSequences); } - } } @@ -1306,7 +1307,7 @@ public abstract class AlignmentViewport implements AlignViewportI ColourSchemeI cs = globalColourScheme; if (cs != null) { - cs.alignmentChanged(alignment, null); + cs.alignmentChanged(alignment, hiddenRepSequences); cs.setConsensus(hconsensus); if (cs.conservationApplied()) -- 1.7.10.2