From 6b3a4a1b636be96f2bc46a8a454dd6ce3d280021 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Thu, 26 Sep 2019 16:55:26 +0100 Subject: [PATCH] JAL-3442 colour caching for Overview resize --- src/jalview/datamodel/Alignment.java | 9 +++++++ src/jalview/datamodel/AlignmentI.java | 6 +++++ src/jalview/datamodel/Sequence.java | 28 +++++++++++++++++++++ src/jalview/datamodel/SequenceI.java | 22 ++++++++++++++++ src/jalview/gui/AlignFrame.java | 1 + src/jalview/gui/AlignmentPanel.java | 2 +- src/jalview/renderer/OverviewResColourFinder.java | 7 ++++++ test/jalview/renderer/OverviewRendererTest.java | 2 ++ 8 files changed, 76 insertions(+), 1 deletion(-) diff --git a/src/jalview/datamodel/Alignment.java b/src/jalview/datamodel/Alignment.java index 7b97d49..599d3a9 100755 --- a/src/jalview/datamodel/Alignment.java +++ b/src/jalview/datamodel/Alignment.java @@ -2034,4 +2034,13 @@ public class Alignment implements AlignmentI } } + @Override + public void resetColors() + { + for (int i = getHeight(); --i >= 0;) + { + sequences.get(i).resetColors(); + } + } + } diff --git a/src/jalview/datamodel/AlignmentI.java b/src/jalview/datamodel/AlignmentI.java index 93a2456..e8e0812 100755 --- a/src/jalview/datamodel/AlignmentI.java +++ b/src/jalview/datamodel/AlignmentI.java @@ -621,7 +621,13 @@ public interface AlignmentI extends AnnotatedCollectionI * @return new HiddenColumns for new alignment view, with insertions into * profileseq marked as hidden. */ + public HiddenColumns propagateInsertions(SequenceI profileseq, AlignmentView input); + /** + * Removes all colors assigned to sequences, forcing them to be be + * recalculated + */ + void resetColors(); } diff --git a/src/jalview/datamodel/Sequence.java b/src/jalview/datamodel/Sequence.java index 6c0e528..04638d3 100755 --- a/src/jalview/datamodel/Sequence.java +++ b/src/jalview/datamodel/Sequence.java @@ -118,6 +118,11 @@ public class Sequence extends ASequence implements SequenceI */ private int changeCount; + /* + * cached rgb colours for each position of the aligned sequence (column) + */ + private int[] argb; + /** * Creates a new Sequence object. * @@ -2017,6 +2022,7 @@ public class Sequence extends ASequence implements SequenceI @Override public void sequenceChanged() { + resetColors(); changeCount++; } @@ -2139,4 +2145,26 @@ public class Sequence extends ASequence implements SequenceI return getFeatures().hasFeatures(type); } + @Override + public int getColor(int i) + { + return argb == null ? 0 : argb[i]; + } + + @Override + public int setColor(int i, int rgb) + { + if (argb == null) + { + argb = new int[this.sequence.length]; + } + return (argb[i] = rgb); + } + + @Override + public void resetColors() + { + argb = null; + } + } diff --git a/src/jalview/datamodel/SequenceI.java b/src/jalview/datamodel/SequenceI.java index 851ef79..7c9c418 100755 --- a/src/jalview/datamodel/SequenceI.java +++ b/src/jalview/datamodel/SequenceI.java @@ -606,5 +606,27 @@ public interface SequenceI extends ASequenceI */ public boolean hasFeatures(String type); + /** + * Returns the rgb value of the colour at position i, or 0 if not known + * + * @param i + * @return + */ + public int getColor(int i); + + /** + * Sets the rgb value of the colour at position i + * + * @param i + * @param rgb + * @return + */ + public int setColor(int i, int rgb); + + /** + * Clears any cached colours + */ + public void resetColors(); + } diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 0b84e9b..204b8c6 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -4526,6 +4526,7 @@ public class AlignFrame extends GAlignFrame // abstracted if (enableIfNecessary) { + alignPanel.getAlignment().resetColors(); viewport.setShowSequenceFeatures(true); showSeqFeatures.setSelected(true); } diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index 2f5d83b..22bb89f 100644 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -834,6 +834,7 @@ public class AlignmentPanel extends GAlignmentPanel implements av.isShowAutocalculatedAbove()); sorter.sort(getAlignment().getAlignmentAnnotation(), av.getSortAnnotationsBy()); + getAlignment().resetColors(); repaint(); if (updateStructures) @@ -842,7 +843,6 @@ public class AlignmentPanel extends GAlignmentPanel implements } if (updateOverview) { - if (overviewPanel != null) { overviewPanel.updateOverviewImage(); diff --git a/src/jalview/renderer/OverviewResColourFinder.java b/src/jalview/renderer/OverviewResColourFinder.java index 7207dea..740b56c 100644 --- a/src/jalview/renderer/OverviewResColourFinder.java +++ b/src/jalview/renderer/OverviewResColourFinder.java @@ -124,12 +124,19 @@ public class OverviewResColourFinder extends ResidueColourFinder SequenceGroup[] allGroups, final SequenceI seq, int i, FeatureColourFinder finder) { + int c = seq.getColor(i); + if (c != 0) + { + return c; + } + int col = getResidueBoxColourInt(showBoxes, shader, allGroups, seq, i); // if there's a FeatureColourFinder we might override the residue colour // here with feature colouring col = finder == null || finder.noFeaturesDisplayed() ? col : finder.findFeatureColourInt(col, seq, i); + seq.setColor(i, col); return col; } diff --git a/test/jalview/renderer/OverviewRendererTest.java b/test/jalview/renderer/OverviewRendererTest.java index 0a77b65..159c814 100644 --- a/test/jalview/renderer/OverviewRendererTest.java +++ b/test/jalview/renderer/OverviewRendererTest.java @@ -82,11 +82,13 @@ public class OverviewRendererTest fr.findAllFeatures(true); av.setShowSequenceFeatures(true); fr.setColour("Pfam", new FeatureColour(Color.yellow)); + seq1.resetColors(); assertEquals(or.getColumnColourFromSequence(null, seq1, 0), Color.yellow.getRGB()); // don't show sequence features av.setShowSequenceFeatures(false); + seq1.resetColors(); assertEquals(or.getColumnColourFromSequence(null, seq1, 0), Color.magenta.getRGB()); } -- 1.7.10.2