From 95a46891288f4fc63d690cab4f56879678f54fb6 Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Mon, 22 Aug 2005 09:15:52 +0000 Subject: [PATCH] Conservation colour scheme is no more --- src/jalview/appletgui/APopupMenu.java | 22 +- src/jalview/appletgui/AlignFrame.java | 55 ++--- src/jalview/appletgui/AlignViewport.java | 5 +- src/jalview/appletgui/AlignmentPanel.java | 23 --- src/jalview/appletgui/SeqPanel.java | 30 ++- src/jalview/appletgui/SliderPanel.java | 10 +- src/jalview/appletgui/TreeCanvas.java | 8 +- src/jalview/datamodel/SequenceGroup.java | 20 +- src/jalview/gui/AlignFrame.java | 128 ++++-------- src/jalview/gui/AlignViewport.java | 7 +- src/jalview/gui/AlignmentPanel.java | 24 --- src/jalview/gui/Jalview2XML.java | 41 ++-- src/jalview/gui/PopupMenu.java | 24 +-- src/jalview/gui/SeqPanel.java | 42 ++-- src/jalview/gui/SliderPanel.java | 25 +-- src/jalview/gui/TreeCanvas.java | 9 +- src/jalview/schemes/Blosum62ColourScheme.java | 12 +- src/jalview/schemes/ClustalxColourScheme.java | 13 +- src/jalview/schemes/ColourSchemeI.java | 18 +- src/jalview/schemes/ColourSchemeProperty.java | 4 - src/jalview/schemes/ConservationColourScheme.java | 161 --------------- src/jalview/schemes/NucleotideColourScheme.java | 7 +- src/jalview/schemes/PIDColourScheme.java | 11 +- src/jalview/schemes/ResidueColourScheme.java | 228 ++++++++++++++++----- src/jalview/schemes/ScoreColourScheme.java | 41 ++-- 25 files changed, 400 insertions(+), 568 deletions(-) delete mode 100755 src/jalview/schemes/ConservationColourScheme.java diff --git a/src/jalview/appletgui/APopupMenu.java b/src/jalview/appletgui/APopupMenu.java index 0cfa537..abd76d6 100755 --- a/src/jalview/appletgui/APopupMenu.java +++ b/src/jalview/appletgui/APopupMenu.java @@ -385,23 +385,15 @@ public class APopupMenu ap.av.alignment.getWidth())); int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup().getName()); - if (sg.cs instanceof ResidueColourScheme) - { - ( (ResidueColourScheme) sg.cs).setThreshold(threshold, ap.av.getIgnoreGapsConsensus()); - } - else if (sg.cs instanceof ScoreColourScheme) - { - ( (ScoreColourScheme) sg.cs).setThreshold(threshold, ap.av.getIgnoreGapsConsensus()); - } + + sg.cs.setThreshold(threshold, ap.av.getIgnoreGapsConsensus()); SliderPanel.showPIDSlider(); } else // remove PIDColouring { - ResidueColourScheme rcs = (ResidueColourScheme) sg.cs; - rcs.setThreshold(0, ap.av.getIgnoreGapsConsensus()); - sg.cs = rcs; + sg.cs.setThreshold(0, ap.av.getIgnoreGapsConsensus()); } refresh(); @@ -454,17 +446,15 @@ public class APopupMenu c.calculate(); c.verdict(false, ap.av.ConsPercGaps); - ConservationColourScheme ccs = new ConservationColourScheme(c, sg.cs); - sg.cs = ccs; + sg.cs.setConservation(c); - SliderPanel.setConservationSlider(ap, ccs, sg.getName()); + SliderPanel.setConservationSlider(ap, sg.cs, sg.getName()); SliderPanel.showConservationSlider(); } else // remove ConservationColouring { - ConservationColourScheme ccs = (ConservationColourScheme) sg.cs; - sg.cs = ccs.cs; + sg.cs.setConservation(null); } refresh(); diff --git a/src/jalview/appletgui/AlignFrame.java b/src/jalview/appletgui/AlignFrame.java index f1ecd6a..6138257 100755 --- a/src/jalview/appletgui/AlignFrame.java +++ b/src/jalview/appletgui/AlignFrame.java @@ -491,7 +491,7 @@ public class AlignFrame sg.setEndRes(viewport.alignment.getWidth()); viewport.setSelectionGroup(sg); alignPanel.repaint(); - PaintRefresher.Refresh(null); + PaintRefresher.Refresh(null, viewport.alignment); } public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e) @@ -499,7 +499,7 @@ public class AlignFrame viewport.setSelectionGroup(null); viewport.getColumnSelection().clear(); viewport.setSelectionGroup(null); - PaintRefresher.Refresh(null); + PaintRefresher.Refresh(null, viewport.alignment); } public void invertSequenceMenuItem_actionPerformed(ActionEvent e) @@ -510,7 +510,7 @@ public class AlignFrame sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false); } - PaintRefresher.Refresh(null); + PaintRefresher.Refresh(null, viewport.alignment); } public void remove2LeftMenuItem_actionPerformed(ActionEvent e) @@ -808,21 +808,17 @@ public class AlignFrame { threshold = SliderPanel.setPIDSliderSource(alignPanel, cs, "Background"); - if (cs instanceof ResidueColourScheme) - { - ( (ResidueColourScheme) cs).setThreshold(threshold, viewport.getIgnoreGapsConsensus()); - } + cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus()); viewport.setGlobalColourScheme(cs); } - else if (cs instanceof ResidueColourScheme) + else { - ( (ResidueColourScheme) cs).setThreshold(0, viewport.getIgnoreGapsConsensus()); + cs.setThreshold(0, viewport.getIgnoreGapsConsensus()); } if (viewport.getConservationSelected()) { - ConservationColourScheme ccs = null; Alignment al = (Alignment) viewport.alignment; Conservation c = new Conservation("All", @@ -833,13 +829,13 @@ public class AlignFrame c.calculate(); c.verdict(false, viewport.ConsPercGaps); - ccs = new ConservationColourScheme(c, cs); + cs.setConservation(c); // MUST NOTIFY THE COLOURSCHEME OF CONSENSUS! - ccs.setConsensus(viewport.vconsensus); - viewport.setGlobalColourScheme(ccs); + cs.setConsensus(viewport.vconsensus); + viewport.setGlobalColourScheme(cs); - SliderPanel.setConservationSlider(alignPanel, ccs, "Background"); + SliderPanel.setConservationSlider(alignPanel, cs, "Background"); } else @@ -885,10 +881,7 @@ public class AlignFrame if (viewport.getAbovePIDThreshold()) { - if (sg.cs instanceof ResidueColourScheme) - { - ( (ResidueColourScheme) sg.cs).setThreshold(threshold, viewport.getIgnoreGapsConsensus()); - } + sg.cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus()); sg.cs.setConsensus(AAFrequency.calculate(sg.sequences, 0, sg.getWidth())); } @@ -901,11 +894,10 @@ public class AlignFrame viewport.alignment.getWidth() - 1); c.calculate(); c.verdict(false, viewport.ConsPercGaps); - ConservationColourScheme ccs = new ConservationColourScheme(c, sg.cs); // MUST NOTIFY THE COLOURSCHEME OF CONSENSUS! - ccs.setConsensus(AAFrequency.calculate(sg.sequences, 0, sg.getWidth())); - sg.cs = ccs; + cs.setConsensus(AAFrequency.calculate(sg.sequences, 0, sg.getWidth())); + sg.cs = cs; } else { @@ -959,15 +951,7 @@ public class AlignFrame viewport.setAbovePIDThreshold(false); abovePIDThreshold.setState(false); - ColourSchemeI cs = viewport.getGlobalColourScheme(); - if (cs instanceof ConservationColourScheme) - { - changeColour( ( (ConservationColourScheme) cs).cs); - } - else - { - changeColour(cs); - } + changeColour(viewport.getGlobalColourScheme()); modifyConservation_actionPerformed(null); } @@ -979,16 +963,7 @@ public class AlignFrame conservationMenuItem.setState(false); viewport.setConservationSelected(false); - ColourSchemeI cs = viewport.getGlobalColourScheme(); - - if (cs instanceof ConservationColourScheme) - { - changeColour( ( (ConservationColourScheme) cs).cs); - } - else - { - changeColour(cs); - } + changeColour(viewport.getGlobalColourScheme()); modifyPID_actionPerformed(null); } diff --git a/src/jalview/appletgui/AlignViewport.java b/src/jalview/appletgui/AlignViewport.java index e7cae44..e513829 100755 --- a/src/jalview/appletgui/AlignViewport.java +++ b/src/jalview/appletgui/AlignViewport.java @@ -653,10 +653,9 @@ public class AlignViewport { ignoreGapsInConsensusCalculation = b; updateConsensus(); - if (globalColourScheme!=null && globalColourScheme instanceof ResidueColourScheme) + if (globalColourScheme!=null) { - ( (ResidueColourScheme) globalColourScheme).setThreshold( - ( (ResidueColourScheme) globalColourScheme).getThreshold(), + globalColourScheme.setThreshold(globalColourScheme.getThreshold(), ignoreGapsInConsensusCalculation); } diff --git a/src/jalview/appletgui/AlignmentPanel.java b/src/jalview/appletgui/AlignmentPanel.java index 5e09da7..b46876a 100755 --- a/src/jalview/appletgui/AlignmentPanel.java +++ b/src/jalview/appletgui/AlignmentPanel.java @@ -288,29 +288,6 @@ public class AlignmentPanel } - public void setColourScheme() - { - ColourSchemeI cs = av.getGlobalColourScheme(); - - if (av.getConservationSelected()) - { - - Alignment al = (Alignment) av.getAlignment(); - Conservation c = new Conservation("All", - ResidueProperties.propHash, 3, - al.getSequences(), 0, - al.getWidth()); - - c.calculate(); - c.verdict(false, av.ConsPercGaps); - ConservationColourScheme ccs = new ConservationColourScheme(c, cs); - - av.setGlobalColourScheme(ccs); - - } - - repaint(); - } int hextent = 0; int vextent = 0; diff --git a/src/jalview/appletgui/SeqPanel.java b/src/jalview/appletgui/SeqPanel.java index 080dc22..ebde2cf 100755 --- a/src/jalview/appletgui/SeqPanel.java +++ b/src/jalview/appletgui/SeqPanel.java @@ -454,10 +454,9 @@ public class SeqPanel // Y O Y CLUSTALX ColourSchemeI cs = av.getGlobalColourScheme(); - if (cs instanceof ConservationColourScheme) + if (cs.conservationApplied()) { - ConservationColourScheme ccs = (ConservationColourScheme) cs; - if (ccs.cs instanceof ClustalxColourScheme) + if (cs instanceof ClustalxColourScheme) { jalview.analysis.Conservation c = new jalview.analysis.Conservation ("All", @@ -467,10 +466,9 @@ public class SeqPanel c.calculate(); c.verdict(false, av.ConsPercGaps); - ClustalxColourScheme cxs = (ClustalxColourScheme) ccs.cs; - cxs.resetClustalX(av.alignment.getSequences(), av.alignment.getWidth()); - ccs = new ConservationColourScheme(c, cxs); - av.setGlobalColourScheme(ccs); + ((ClustalxColourScheme)cs).resetClustalX(av.alignment.getSequences(), av.alignment.getWidth()); + cs.setConservation(c); + av.setGlobalColourScheme(cs); } } @@ -604,19 +602,19 @@ public class SeqPanel return; } - if (stretchGroup.cs instanceof ConservationColourScheme) - { - ConservationColourScheme ccs = (ConservationColourScheme) stretchGroup.cs; - stretchGroup.cs = ccs; - SliderPanel.setConservationSlider(ap, stretchGroup.cs, - stretchGroup.getName()); - } - else + if(stretchGroup.cs!=null) { + if (stretchGroup.cs.conservationApplied()) + { + SliderPanel.setConservationSlider(ap, stretchGroup.cs, + stretchGroup.getName()); + } + else + { SliderPanel.setPIDSliderSource(ap, stretchGroup.cs, stretchGroup.getName()); + } } - changeEndRes = false; changeStartRes = false; stretchGroup = null; diff --git a/src/jalview/appletgui/SliderPanel.java b/src/jalview/appletgui/SliderPanel.java index d2eeff3..3e23728 100755 --- a/src/jalview/appletgui/SliderPanel.java +++ b/src/jalview/appletgui/SliderPanel.java @@ -42,11 +42,10 @@ public class SliderPanel String source) { SliderPanel sp = null; - ConservationColourScheme ccs = (ConservationColourScheme) cs; if (conservationSlider == null) { - sp = new SliderPanel(ap, ccs.inc, true, cs); + sp = new SliderPanel(ap, cs.getConservationInc(), true, cs); conservationSlider = new Frame(); conservationSlider.add(sp); } @@ -217,14 +216,11 @@ public class SliderPanel if (forConservation) { - if (toChange instanceof ConservationColourScheme) - { - ( (ConservationColourScheme) toChange).inc = i; - } + toChange.setConservationInc(i); } else { - ( (ResidueColourScheme) toChange).setThreshold(i, ap.av.getIgnoreGapsConsensus()); + toChange.setThreshold(i, ap.av.getIgnoreGapsConsensus()); } groupIndex--; diff --git a/src/jalview/appletgui/TreeCanvas.java b/src/jalview/appletgui/TreeCanvas.java index 15c4bfa..a6bc5df 100755 --- a/src/jalview/appletgui/TreeCanvas.java +++ b/src/jalview/appletgui/TreeCanvas.java @@ -490,10 +490,8 @@ System.out.println("called here"); false, 0, av.alignment.getWidth()); - if (av.getGlobalColourScheme() instanceof ConservationColourScheme) + if (av.getGlobalColourScheme().conservationApplied()) { - ConservationColourScheme ccs = (ConservationColourScheme) av. - getGlobalColourScheme(); Conservation c = new Conservation("Group", ResidueProperties.propHash, 3, sg.sequences, sg.getStartRes(), @@ -501,9 +499,9 @@ System.out.println("called here"); c.calculate(); c.verdict(false, av.ConsPercGaps); - ccs = new ConservationColourScheme(c, ccs.cs); + cs.setConservation(c); - sg.cs = ccs; + sg.cs = cs; } diff --git a/src/jalview/datamodel/SequenceGroup.java b/src/jalview/datamodel/SequenceGroup.java index 054896b..6de42b9 100755 --- a/src/jalview/datamodel/SequenceGroup.java +++ b/src/jalview/datamodel/SequenceGroup.java @@ -235,29 +235,31 @@ public class SequenceGroup */ public void recalcConservation() { - if (cs != null) - { - cs.setConsensus(AAFrequency.calculate(sequences, 0, getWidth())); - } + if(cs == null) + return; + + cs.setConsensus(AAFrequency.calculate(sequences, 0, getWidth())); + if (cs instanceof ClustalxColourScheme) { ((ClustalxColourScheme) cs).resetClustalX(sequences, getWidth()); } - if (cs instanceof ConservationColourScheme) + + if (cs.conservationApplied()) { Conservation c = new Conservation(groupName, ResidueProperties.propHash, 3, sequences, 0, getWidth()); c.calculate(); c.verdict(false, 25); - ConservationColourScheme ccs = (ConservationColourScheme) cs; - ccs.conserve = c; - if (ccs.cs instanceof ClustalxColourScheme) + cs.setConservation(c); + + if (cs instanceof ClustalxColourScheme) { - ((ClustalxColourScheme) ccs.cs).resetClustalX(sequences, + ((ClustalxColourScheme) cs).resetClustalX(sequences, getWidth()); } } diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 88ff3e8..fc59062 100755 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -13,7 +13,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * along with this program; if not, write to the Free Softwarechang * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ package jalview.gui; @@ -1371,65 +1371,50 @@ public class AlignFrame { int threshold = 0; - if (viewport.getAbovePIDThreshold()) + if(cs!=null) { - threshold = SliderPanel.setPIDSliderSource(alignPanel, cs, - "Background"); - - if (cs instanceof ResidueColourScheme) + if (viewport.getAbovePIDThreshold()) { - ( (ResidueColourScheme) cs).setThreshold(threshold, - viewport. - getIgnoreGapsConsensus()); + threshold = SliderPanel.setPIDSliderSource(alignPanel, cs, + "Background"); + + cs.setThreshold(threshold, + viewport.getIgnoreGapsConsensus()); + + viewport.setGlobalColourScheme(cs); } - else if (cs instanceof ScoreColourScheme) + else { - ( (ScoreColourScheme) cs).setThreshold(threshold, - viewport.getIgnoreGapsConsensus()); + cs.setThreshold(0, viewport.getIgnoreGapsConsensus()); } - viewport.setGlobalColourScheme(cs); - } - else if (cs instanceof ResidueColourScheme) - { - ( (ResidueColourScheme) cs).setThreshold(0, - viewport.getIgnoreGapsConsensus()); - } - - - if (viewport.getConservationSelected()) - { - ConservationColourScheme ccs = null; - - Alignment al = (Alignment) viewport.alignment; - Conservation c = new Conservation("All", - ResidueProperties.propHash, 3, - al.getSequences(), 0, - al.getWidth() - 1); - - c.calculate(); - c.verdict(false, viewport.ConsPercGaps); + if (viewport.getConservationSelected()) + { - ccs = new ConservationColourScheme(c, cs); + Alignment al = (Alignment) viewport.alignment; + Conservation c = new Conservation("All", + ResidueProperties.propHash, 3, + al.getSequences(), 0, + al.getWidth() - 1); - ccs.setConsensus(viewport.vconsensus); + c.calculate(); + c.verdict(false, viewport.ConsPercGaps); - viewport.setGlobalColourScheme(ccs); + cs.setConservation(c); - ccs.inc = SliderPanel.setConservationSlider(alignPanel, ccs, - "Background"); - } - else - { - // MUST NOTIFY THE COLOURSCHEME OF CONSENSUS! - if (cs != null) + cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel, cs, + "Background")); + } + else { - cs.setConsensus(viewport.vconsensus); + cs.setConservation(null); } - viewport.setGlobalColourScheme(cs); + cs.setConsensus(viewport.vconsensus); } + viewport.setGlobalColourScheme(cs); + if (viewport.getColourAppliesToAllGroups()) { Vector groups = viewport.alignment.getGroups(); @@ -1441,8 +1426,10 @@ public class AlignFrame if (cs == null) { sg.cs = null; + continue; } - else if (cs instanceof ClustalxColourScheme) + + if (cs instanceof ClustalxColourScheme) { sg.cs = new ClustalxColourScheme(sg.sequences, sg.getWidth()); } @@ -1463,15 +1450,15 @@ public class AlignFrame if (viewport.getAbovePIDThreshold()) { - if (sg.cs instanceof ResidueColourScheme) - { - ( (ResidueColourScheme) sg.cs).setThreshold(threshold, + sg.cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus()); - } sg.cs.setConsensus(AAFrequency.calculate(sg.sequences, 0, sg.getWidth())); } + else + sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus()); + if (viewport.getConservationSelected()) { @@ -1481,21 +1468,10 @@ public class AlignFrame viewport.alignment.getWidth() - 1); c.calculate(); c.verdict(false, viewport.ConsPercGaps); - - ConservationColourScheme ccs = new ConservationColourScheme(c, - sg.cs); - - // MUST NOTIFY THE COLOURSCHEME OF CONSENSUS! - ccs.setConsensus(AAFrequency.calculate(sg.sequences, 0, - sg.getWidth())); - sg.cs = ccs; - } - else if (cs != null) - { - // MUST NOTIFY THE COLOURSCHEME OF CONSENSUS! - sg.cs.setConsensus(AAFrequency.calculate(sg.sequences, 0, - sg.getWidth())); + sg.cs.setConservation(c); } + else + sg.cs.setConservation(null); } } @@ -1514,7 +1490,7 @@ public class AlignFrame */ protected void modifyPID_actionPerformed(ActionEvent e) { - if (viewport.getAbovePIDThreshold()) + if (viewport.getAbovePIDThreshold() && viewport.globalColourScheme!=null) { SliderPanel.setPIDSliderSource(alignPanel, viewport.getGlobalColourScheme(), @@ -1530,7 +1506,7 @@ public class AlignFrame */ protected void modifyConservation_actionPerformed(ActionEvent e) { - if (viewport.getConservationSelected()) + if (viewport.getConservationSelected() && viewport.globalColourScheme!=null) { SliderPanel.setConservationSlider(alignPanel, viewport.globalColourScheme, @@ -1551,16 +1527,7 @@ public class AlignFrame viewport.setAbovePIDThreshold(false); abovePIDThreshold.setSelected(false); - ColourSchemeI cs = viewport.getGlobalColourScheme(); - - if (cs instanceof ConservationColourScheme) - { - changeColour( ( (ConservationColourScheme) cs).cs); - } - else - { - changeColour(cs); - } + changeColour(viewport.getGlobalColourScheme()); modifyConservation_actionPerformed(null); } @@ -1579,14 +1546,7 @@ public class AlignFrame ColourSchemeI cs = viewport.getGlobalColourScheme(); - if (cs instanceof ConservationColourScheme) - { - changeColour( ( (ConservationColourScheme) cs).cs); - } - else - { - changeColour(cs); - } + changeColour(viewport.getGlobalColourScheme()); modifyPID_actionPerformed(null); } diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index dd3f980..f951792 100755 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -1039,12 +1039,9 @@ public class AlignViewport { ignoreGapsInConsensusCalculation = b; updateConsensus(); - if(globalColourScheme!=null && globalColourScheme instanceof ResidueColourScheme) + if(globalColourScheme!=null) { - ((ResidueColourScheme) globalColourScheme).setThreshold( - ((ResidueColourScheme) globalColourScheme).getThreshold(), ignoreGapsInConsensusCalculation); - - + globalColourScheme.setThreshold(globalColourScheme.getThreshold(), ignoreGapsInConsensusCalculation); } } diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index 7aff9ab..12c1cbd 100755 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -295,30 +295,6 @@ public class AlignmentPanel extends GAlignmentPanel repaint(); } - /** - * DOCUMENT ME! - */ - public void setColourScheme() - { - ColourSchemeI cs = av.getGlobalColourScheme(); - - if (av.getConservationSelected()) - { - Alignment al = (Alignment) av.getAlignment(); - Conservation c = new Conservation("All", - ResidueProperties.propHash, 3, al.getSequences(), 0, - al.getWidth()); - - c.calculate(); - c.verdict(false, av.ConsPercGaps); - - ConservationColourScheme ccs = new ConservationColourScheme(c, cs); - - av.setGlobalColourScheme(ccs); - } - - repaint(); - } // return value is true if the scroll is valid public boolean scrollUp(boolean up) diff --git a/src/jalview/gui/Jalview2XML.java b/src/jalview/gui/Jalview2XML.java index 69ba482..a8fb28d 100755 --- a/src/jalview/gui/Jalview2XML.java +++ b/src/jalview/gui/Jalview2XML.java @@ -295,14 +295,13 @@ public class Jalview2XML groups[i].setEnd(sg.getEndRes()); groups[i].setName(sg.getName()); - if (sg.cs instanceof ConservationColourScheme) + if (sg.cs.conservationApplied()) { - ConservationColourScheme ccs = (ConservationColourScheme) sg.cs; - groups[i].setConsThreshold(ccs.inc); + groups[i].setConsThreshold(sg.cs.getConservationInc()); - if (ccs.cs instanceof jalview.schemes.UserColourScheme) + if (sg.cs instanceof jalview.schemes.UserColourScheme) { - groups[i].setColour(SetUserColourScheme(ccs.cs, userColours, + groups[i].setColour(SetUserColourScheme(sg.cs, userColours, jms)); } else @@ -322,12 +321,8 @@ public class Jalview2XML sg.cs)); } - if (sg.cs instanceof ResidueColourScheme) - { - groups[i].setPidThreshold(((ResidueColourScheme) sg.cs).getThreshold()); - } - + groups[i].setPidThreshold( sg.cs.getThreshold() ); groups[i].setOutlineColour(sg.getOutlineColour().getRGB()); groups[i].setDisplayBoxes(sg.getDisplayBoxes()); @@ -368,17 +363,16 @@ public class Jalview2XML ColourSchemeI cs = av.getGlobalColourScheme(); - if (cs instanceof ConservationColourScheme) + if (cs.conservationApplied()) { - ConservationColourScheme ccs = (ConservationColourScheme)cs; - view.setConsThreshold(ccs.inc); - if(ccs.cs instanceof jalview.schemes.UserColourScheme) - view.setBgColour(SetUserColourScheme(ccs.cs, userColours, jms)); + view.setConsThreshold(cs.getConservationInc()); + if(cs instanceof jalview.schemes.UserColourScheme) + view.setBgColour(SetUserColourScheme(cs, userColours, jms)); } if (cs instanceof ResidueColourScheme) { - view.setPidThreshold(((ResidueColourScheme) cs).getThreshold()); + view.setPidThreshold( cs.getThreshold() ); } view.setConservationSelected(av.getConservationSelected()); @@ -638,10 +632,7 @@ public class Jalview2XML groups[i].getColour()); } - if (cs instanceof ResidueColourScheme) - { - ((ResidueColourScheme) cs).setThreshold(groups[i].getPidThreshold(), true); - } + cs.setThreshold(groups[i].getPidThreshold(), true); } Vector seqs = new Vector(); @@ -668,8 +659,7 @@ public class Jalview2XML sg.getWidth() - 1); c.calculate(); c.verdict(false, 25); - cs = new ConservationColourScheme(c, cs); - sg.cs = cs; + sg.cs.setConservation(c); } al.addGroup(sg); @@ -734,10 +724,7 @@ public class Jalview2XML cs = ColourSchemeProperty.getColour(al, view.getBgColour()); } - if (cs instanceof ResidueColourScheme) - { - ((ResidueColourScheme) cs).setThreshold(view.getPidThreshold(), true); - } + cs.setThreshold(view.getPidThreshold(), true); if(cs!=null) cs.setConsensus(af.viewport.vconsensus); @@ -749,7 +736,7 @@ public class Jalview2XML af.changeColour(af.viewport.getGlobalColourScheme()); if (view.getConservationSelected()) { - ( (ConservationColourScheme) af.viewport.getGlobalColourScheme()).inc = view.getConsThreshold(); + af.viewport.getGlobalColourScheme().setConservationInc(view.getConsThreshold()); } af.viewport.setColourAppliesToAllGroups(true); diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java index 40c51cb..137ca14 100755 --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -172,7 +172,7 @@ public class PopupMenu extends JPopupMenu noColourmenuItem.setSelected(true); } - if (sg.cs instanceof ConservationColourScheme) + if (sg.cs!=null && sg.cs.conservationApplied()) { conservationMenuItem.setSelected(true); } @@ -615,22 +615,13 @@ public class PopupMenu extends JPopupMenu int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup().getName()); - if (sg.cs instanceof ResidueColourScheme) - { - ((ResidueColourScheme) sg.cs).setThreshold(threshold, ap.av.getIgnoreGapsConsensus()); - } - else if (sg.cs instanceof ScoreColourScheme) - { - ((ScoreColourScheme) sg.cs).setThreshold(threshold, ap.av.getIgnoreGapsConsensus()); - } + sg.cs.setThreshold(threshold, ap.av.getIgnoreGapsConsensus()); SliderPanel.showPIDSlider(); } else // remove PIDColouring { - ResidueColourScheme rcs = (ResidueColourScheme) sg.cs; - rcs.setThreshold(0, ap.av.getIgnoreGapsConsensus()); - sg.cs = rcs; + sg.cs.setThreshold(0, ap.av.getIgnoreGapsConsensus()); } refresh(); @@ -715,17 +706,14 @@ public class PopupMenu extends JPopupMenu c.calculate(); c.verdict(false, ap.av.ConsPercGaps); - ConservationColourScheme ccs = new ConservationColourScheme(c, sg.cs); - - sg.cs = ccs; + sg.cs.setConservation(c); - SliderPanel.setConservationSlider(ap, ccs, sg.getName()); + SliderPanel.setConservationSlider(ap, sg.cs, sg.getName()); SliderPanel.showConservationSlider(); } else // remove ConservationColouring { - ConservationColourScheme ccs = (ConservationColourScheme) sg.cs; - sg.cs = ccs.cs; + sg.cs.setConservation(null); } refresh(); diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index db120e1..c98322e 100755 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -553,27 +553,26 @@ public class SeqPanel extends JPanel av.getSelectionGroup().recalcConservation(); } - if (cs instanceof ConservationColourScheme) + if (cs.conservationApplied()) { - ConservationColourScheme ccs = (ConservationColourScheme) cs; Conservation c = new Conservation("All", ResidueProperties.propHash, 3, av.alignment.getSequences(), 0, av.alignment.getWidth() - 1); c.calculate(); c.verdict(false, av.ConsPercGaps); - if (ccs.cs instanceof ClustalxColourScheme) + if (cs instanceof ClustalxColourScheme) { - ClustalxColourScheme cxs = (ClustalxColourScheme) ccs.cs; + ClustalxColourScheme cxs = (ClustalxColourScheme) cs; cxs.resetClustalX(av.alignment.getSequences(), av.alignment.getWidth()); - ccs = new ConservationColourScheme(c, cxs); - av.setGlobalColourScheme(ccs); + cs.setConservation(c); + av.setGlobalColourScheme(cs); } else { - ccs = new ConservationColourScheme(c, ccs.cs); - av.setGlobalColourScheme(ccs); + cs.setConservation(c); + av.setGlobalColourScheme(cs); } } @@ -707,25 +706,26 @@ public class SeqPanel extends JPanel return; } - if (stretchGroup.cs instanceof ClustalxColourScheme) + if(stretchGroup.cs!=null) { - ((ClustalxColourScheme) stretchGroup.cs).resetClustalX(stretchGroup.sequences, + if (stretchGroup.cs instanceof ClustalxColourScheme) + { + ( (ClustalxColourScheme) stretchGroup.cs).resetClustalX(stretchGroup. + sequences, stretchGroup.getWidth()); - } + } - if (stretchGroup.cs instanceof ConservationColourScheme) - { - ConservationColourScheme ccs = (ConservationColourScheme) stretchGroup.cs; - stretchGroup.cs = ccs; + if (stretchGroup.cs.conservationApplied()) + { SliderPanel.setConservationSlider(ap, stretchGroup.cs, - stretchGroup.getName()); - } - else - { + stretchGroup.getName()); + } + else + { SliderPanel.setPIDSliderSource(ap, stretchGroup.cs, - stretchGroup.getName()); + stretchGroup.getName()); + } } - changeEndRes = false; changeStartRes = false; stretchGroup = null; diff --git a/src/jalview/gui/SliderPanel.java b/src/jalview/gui/SliderPanel.java index a9020c3..5b177d4 100755 --- a/src/jalview/gui/SliderPanel.java +++ b/src/jalview/gui/SliderPanel.java @@ -102,11 +102,10 @@ public class SliderPanel extends GSliderPanel ColourSchemeI cs, String source) { SliderPanel sp = null; - ConservationColourScheme ccs = (ConservationColourScheme) cs; if (conservationSlider == null) { - sp = new SliderPanel(ap, ccs.inc, true, cs); + sp = new SliderPanel(ap, cs.getConservationInc(), true, cs); conservationSlider = new JInternalFrame(); conservationSlider.setContentPane(sp); conservationSlider.setLayer(JLayeredPane.PALETTE_LAYER); @@ -176,16 +175,7 @@ public class SliderPanel extends GSliderPanel { SliderPanel pid = null; - int threshold = 50; - - if (cs instanceof ResidueColourScheme) - { - threshold = (((ResidueColourScheme) cs).getThreshold()); - } - else if (cs instanceof ScoreColourScheme) - { - threshold = (((ScoreColourScheme) cs).getThreshold()); - } + int threshold = cs.getThreshold(); if (PIDSlider == null) { @@ -253,10 +243,12 @@ public class SliderPanel extends GSliderPanel public void valueChanged(int i) { if (cs == null) - { + {System.out.println("cs is null"); return; } + + ColourSchemeI toChange = null; Vector allGroups = null; int groupIndex = 0; @@ -271,6 +263,7 @@ public class SliderPanel extends GSliderPanel toChange = cs; } + while (groupIndex > -1) { if (allGroups != null) @@ -287,14 +280,14 @@ public class SliderPanel extends GSliderPanel if (forConservation) { - if (toChange instanceof ConservationColourScheme) + if (toChange.conservationApplied()) { - ((ConservationColourScheme) toChange).inc = i; + toChange.setConservationInc(i); } } else { - ((ResidueColourScheme) toChange).setThreshold(i, ap.av.getIgnoreGapsConsensus()); + toChange.setThreshold(i, ap.av.getIgnoreGapsConsensus()); } groupIndex--; diff --git a/src/jalview/gui/TreeCanvas.java b/src/jalview/gui/TreeCanvas.java index d05aee1..e923792 100755 --- a/src/jalview/gui/TreeCanvas.java +++ b/src/jalview/gui/TreeCanvas.java @@ -715,21 +715,18 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, if (sg.cs != null) { - ((ResidueColourScheme) sg.cs).setThreshold(25, av.getIgnoreGapsConsensus()); + sg.cs.setThreshold(25, av.getIgnoreGapsConsensus()); } - if (av.getGlobalColourScheme() instanceof ConservationColourScheme) + if (av.getGlobalColourScheme().conservationApplied()) { - ConservationColourScheme ccs = (ConservationColourScheme) av.getGlobalColourScheme(); Conservation c = new Conservation("Group", ResidueProperties.propHash, 3, sg.sequences, sg.getStartRes(), sg.getEndRes()); c.calculate(); c.verdict(false, av.ConsPercGaps); - ccs = new ConservationColourScheme(c, ccs.cs); - - sg.cs = ccs; + sg.cs.setConservation(c); } av.alignment.addGroup(sg); diff --git a/src/jalview/schemes/Blosum62ColourScheme.java b/src/jalview/schemes/Blosum62ColourScheme.java index 5e86263..6e91e0b 100755 --- a/src/jalview/schemes/Blosum62ColourScheme.java +++ b/src/jalview/schemes/Blosum62ColourScheme.java @@ -34,6 +34,7 @@ public class Blosum62ColourScheme char res = s.charAt(0); if ('a' <= res && res <= 'z' ) { + // TO UPPERCASE !!! s = String.valueOf( res -= ('a' - 'A') ); } @@ -49,7 +50,7 @@ public class Blosum62ColourScheme if (max.indexOf(s) > -1) { - return new Color(154, 154, 255); + currentColour = new Color(154, 154, 255); } else { @@ -66,17 +67,22 @@ public class Blosum62ColourScheme if (c > 0) { - return new Color(204, 204, 255); + currentColour = new Color(204, 204, 255); } else { - return Color.white; + currentColour = Color.white; } } + + if(conservationColouring) + applyConservation(j); } else { return Color.white; } + + return currentColour; } } diff --git a/src/jalview/schemes/ClustalxColourScheme.java b/src/jalview/schemes/ClustalxColourScheme.java index addf00f..353accf 100755 --- a/src/jalview/schemes/ClustalxColourScheme.java +++ b/src/jalview/schemes/ClustalxColourScheme.java @@ -255,18 +255,18 @@ public class ClustalxColourScheme int i = ( (Integer) ResidueProperties.aaHash.get(s)).intValue(); - Color c = Color.white; + currentColour = Color.white; if (i > 19) { - return c; + return currentColour; } for (int k = 0; k < ResidueColour[i].conses.length; k++) { if (ResidueColour[i].conses[k].isConserved(cons2, j, size)) { - c = ResidueColour[i].c; + currentColour = ResidueColour[i].c; } } @@ -274,11 +274,14 @@ public class ClustalxColourScheme { if (conses[27].isConserved(cons2, j, size)) { - c = (Color) colhash.get("PINK"); + currentColour = (Color) colhash.get("PINK"); } } - return c; + if(conservationColouring) + applyConservation(j); + + return currentColour; } } diff --git a/src/jalview/schemes/ColourSchemeI.java b/src/jalview/schemes/ColourSchemeI.java index 9cc74f1..8f0f3c5 100755 --- a/src/jalview/schemes/ColourSchemeI.java +++ b/src/jalview/schemes/ColourSchemeI.java @@ -18,8 +18,6 @@ */ package jalview.schemes; -import java.util.*; - import java.awt.*; public interface ColourSchemeI @@ -28,5 +26,19 @@ public interface ColourSchemeI public Color findColour(String s, int j); - public void setConsensus(Vector v); + public void setConsensus(java.util.Vector v); + + public void setConservation(jalview.analysis.Conservation c); + + public boolean conservationApplied(); + + public void setConservationInc(int i); + + public int getConservationInc(); + + public int getThreshold(); + + public void setThreshold(int ct, boolean ignoreGaps); + + } diff --git a/src/jalview/schemes/ColourSchemeProperty.java b/src/jalview/schemes/ColourSchemeProperty.java index 012c3a9..c8a1322 100755 --- a/src/jalview/schemes/ColourSchemeProperty.java +++ b/src/jalview/schemes/ColourSchemeProperty.java @@ -139,10 +139,6 @@ public class ColourSchemeProperty */ public static String getColourName(ColourSchemeI cs) { - if (cs instanceof ConservationColourScheme) - { - cs = ((ConservationColourScheme) cs).cs; - } int index = 12; diff --git a/src/jalview/schemes/ConservationColourScheme.java b/src/jalview/schemes/ConservationColourScheme.java deleted file mode 100755 index b47b01a..0000000 --- a/src/jalview/schemes/ConservationColourScheme.java +++ /dev/null @@ -1,161 +0,0 @@ -/* -* Jalview - A Sequence Alignment Editor and Viewer -* Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA -*/ -package jalview.schemes; - -import jalview.analysis.*; - -import java.awt.*; - -import java.util.Vector; - - -/** - * DOCUMENT ME! - * - * @author $author$ - * @version $Revision$ - */ -public class ConservationColourScheme extends ResidueColourScheme -{ - /** DOCUMENT ME!! */ - public Conservation conserve; - - /** DOCUMENT ME!! */ - public ColourSchemeI cs; - - /** DOCUMENT ME!! */ - public int inc = 30; - - /** - * Creates a new ConservationColourScheme object. - * - * @param cons DOCUMENT ME! - * @param oldcs DOCUMENT ME! - */ - public ConservationColourScheme(Conservation cons, ColourSchemeI oldcs) - { - super(); - conserve = cons; - cs = oldcs; - } - - /** - * DOCUMENT ME! - * - * @param consensus DOCUMENT ME! - */ - public void setConsensus(Vector consensus) - { - super.setConsensus(consensus); - - if (cs != null) - { - cs.setConsensus(consensus); - } - } - - /** - * DOCUMENT ME! - * - * @param s DOCUMENT ME! - * @param i DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public Color findColour(String s, int i) - { - Color c = Color.white; - - if (cs == null) - { - return c; - } - - char ch = conserve.getConsSequence().getSequence().charAt(i); - - if ((ch == '*') || (ch == '+')) - { - c = cs.findColour(s, i); - } - else - { - int tmp = 10; - int t = 0; - - if (!jalview.util.Comparison.isGap(ch)) - { - t = Integer.parseInt(ch + ""); - } - - c = cs.findColour(s, i); - - while (tmp >= t) - { - c = lighter(c, inc); - tmp--; - } - } - - return c; - } - - /** - * DOCUMENT ME! - * - * @param c DOCUMENT ME! - * @param inc DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public Color lighter(Color c, int inc) - { - int red = c.getRed(); - int blue = c.getBlue(); - int green = c.getGreen(); - - if (red < (255 - inc)) - { - red = red + inc; - } - else - { - red = 255; - } - - if (blue < (255 - inc)) - { - blue = blue + inc; - } - else - { - blue = 255; - } - - if (green < (255 - inc)) - { - green = green + inc; - } - else - { - green = 255; - } - - return new Color(red, green, blue); - } -} diff --git a/src/jalview/schemes/NucleotideColourScheme.java b/src/jalview/schemes/NucleotideColourScheme.java index 8785954..942e55b 100755 --- a/src/jalview/schemes/NucleotideColourScheme.java +++ b/src/jalview/schemes/NucleotideColourScheme.java @@ -64,7 +64,7 @@ public class NucleotideColourScheme extends ResidueColourScheme { try { - return colors[((Integer) (ResidueProperties.nucleotideHash.get(n))).intValue()]; + currentColour = colors[((Integer) (ResidueProperties.nucleotideHash.get(n))).intValue()]; } catch (Exception ex) { @@ -75,5 +75,10 @@ public class NucleotideColourScheme extends ResidueColourScheme { return Color.white; } + + if(conservationColouring) + applyConservation(j); + + return currentColour; } } diff --git a/src/jalview/schemes/PIDColourScheme.java b/src/jalview/schemes/PIDColourScheme.java index 3d1c18b..66f180b 100755 --- a/src/jalview/schemes/PIDColourScheme.java +++ b/src/jalview/schemes/PIDColourScheme.java @@ -49,9 +49,7 @@ public class PIDColourScheme return Color.white; } - - - Color c = Color.white; + currentColour = Color.white; double sc = 0; @@ -66,7 +64,7 @@ public class PIDColourScheme { if (sc > thresholds[i]) { - c = pidColours[i]; + currentColour = pidColours[i]; break; } @@ -74,6 +72,9 @@ public class PIDColourScheme } } - return c; + if(conservationColouring) + applyConservation(j); + + return currentColour; } } diff --git a/src/jalview/schemes/ResidueColourScheme.java b/src/jalview/schemes/ResidueColourScheme.java index 785d22d..c435f7d 100755 --- a/src/jalview/schemes/ResidueColourScheme.java +++ b/src/jalview/schemes/ResidueColourScheme.java @@ -18,6 +18,8 @@ */ package jalview.schemes; +import jalview.analysis.*; + import java.awt.*; import java.util.*; @@ -31,14 +33,31 @@ import java.util.*; */ public class ResidueColourScheme implements ColourSchemeI { + + boolean conservationColouring = false; + boolean consensusColouring = false; + Color[] colors; int threshold = 0; /* Set when threshold colouring to either pid_gaps or pid_nogaps*/ protected String ignoreGaps = "pid_gaps"; - /** DOCUMENT ME!! */ - public Hashtable [] consensus; + /** Consenus as a hashtable array */ + Hashtable [] consensus; + + /** Conservation string as a char array */ + char [] conservation; + + /** DOCUMENT ME!! */ + int inc = 30; + + /** + * The colour to be calculated, manipulated and returned + */ + Color currentColour = null; + + /** * Creates a new ResidueColourScheme object. @@ -46,9 +65,9 @@ public class ResidueColourScheme implements ColourSchemeI * @param colors DOCUMENT ME! * @param threshold DOCUMENT ME! */ - public ResidueColourScheme(Color[] colors, int threshold) + public ResidueColourScheme(Color[] colours, int threshold) { - this.colors = colors; + this.colors = colours; this.threshold = threshold; } @@ -60,56 +79,41 @@ public class ResidueColourScheme implements ColourSchemeI } /** - * DOCUMENT ME! - * - * @param consensus DOCUMENT ME! - */ - public void setConsensus(Vector vconsensus) - { - int i, iSize=vconsensus.size(); - consensus = new Hashtable[iSize]; - for(i=0; i= threshold) + if (((Float)consensus[j].get(ignoreGaps)).floatValue() >= threshold) { return true; } @@ -153,4 +155,128 @@ public class ResidueColourScheme implements ColourSchemeI return false; } + + + public boolean conservationApplied() + { + return conservationColouring; + } + + public void setConservationInc(int i) + { + inc = i; + } + + public int getConservationInc() + { + return inc; + } + + /** + * DOCUMENT ME! + * + * @param consensus DOCUMENT ME! + */ + public void setConsensus(Vector vconsensus) + { + int i, iSize=vconsensus.size(); + consensus = new Hashtable[iSize]; + for(i=0; i= t) + { + lighter(inc); + tmp--; + } + } + + } + + /** + * DOCUMENT ME! + * + * @param c DOCUMENT ME! + * @param inc DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + void lighter(int inc) + { + int red = currentColour.getRed(); + int blue = currentColour.getBlue(); + int green = currentColour.getGreen(); + + if (red < (255 - inc)) + { + red = red + inc; + } + else + { + red = 255; + } + + if (blue < (255 - inc)) + { + blue = blue + inc; + } + else + { + blue = 255; + } + + if (green < (255 - inc)) + { + green = green + inc; + } + else + { + green = 255; + } + + currentColour = new Color(red, green, blue); + } + + } diff --git a/src/jalview/schemes/ScoreColourScheme.java b/src/jalview/schemes/ScoreColourScheme.java index b69e536..c11e1ec 100755 --- a/src/jalview/schemes/ScoreColourScheme.java +++ b/src/jalview/schemes/ScoreColourScheme.java @@ -52,6 +52,26 @@ public class ScoreColourScheme extends ResidueColourScheme this.scores = scores; this.min = min; this.max = max; + + // Make colours in constructor + // Why wasn't this done earlier? + int i, iSize=scores.length; + colors = new Color[scores.length]; + for (i = 0; i < iSize; i++) + { + float red = (float) (scores[i] - (float) min) / (float) (max - min); + + if (red > 1.0f) + { + red = 1.0f; + } + + if (red < 0.0f) + { + red = 0.0f; + } + colors[i] = makeColour(red); + } } /** @@ -72,19 +92,6 @@ public class ScoreColourScheme extends ResidueColourScheme } } - float red = (float) (scores[((Integer) ResidueProperties.aaHash.get(s)).intValue()] - - (float) min) / (float) (max - min); - - if (red > 1.0f) - { - red = 1.0f; - } - - if (red < 0.0f) - { - red = 0.0f; - } - char c = s.charAt(0); if (jalview.util.Comparison.isGap((c))) @@ -92,8 +99,12 @@ public class ScoreColourScheme extends ResidueColourScheme return Color.white; } - // This isn';t great - pool of colours in here? - return makeColour(red); + currentColour = colors[((Integer) ResidueProperties.aaHash.get(s)).intValue()]; + + if(conservationColouring) + applyConservation(j); + + return currentColour; } /** -- 1.7.10.2