From a3fb8ffb6b29504b24717bf1dafc45d8f04abc67 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Fri, 6 Jan 2017 15:21:58 +0000 Subject: [PATCH] JAL-2371 slight simplification of findColour overrides --- src/jalview/schemes/ClustalxColourScheme.java | 15 +++++---- src/jalview/schemes/NucleotideColourScheme.java | 15 --------- src/jalview/schemes/PIDColourScheme.java | 13 +++----- .../schemes/PurinePyrimidineColourScheme.java | 16 ---------- src/jalview/schemes/ResidueColourScheme.java | 33 +++++++++++++------- src/jalview/schemes/ScoreColourScheme.java | 22 ------------- src/jalview/schemes/UserColourScheme.java | 18 ----------- 7 files changed, 34 insertions(+), 98 deletions(-) diff --git a/src/jalview/schemes/ClustalxColourScheme.java b/src/jalview/schemes/ClustalxColourScheme.java index 49260a4..3c9f095 100755 --- a/src/jalview/schemes/ClustalxColourScheme.java +++ b/src/jalview/schemes/ClustalxColourScheme.java @@ -23,6 +23,7 @@ package jalview.schemes; import jalview.datamodel.AnnotatedCollectionI; import jalview.datamodel.SequenceCollectionI; import jalview.datamodel.SequenceI; +import jalview.util.Comparison; import java.awt.Color; import java.util.List; @@ -278,10 +279,8 @@ public class ClustalxColourScheme extends ResidueColourScheme @Override protected Color findColour(char c, int j, SequenceI seq) { - Color currentColour; - // TODO why the test for includeGaps here? - if (cons2.length <= j + if (cons2.length <= j || Comparison.isGap(c) /*|| (includeGaps && threshold != 0 && !aboveThreshold(c, j))*/) { return Color.white; @@ -289,11 +288,11 @@ public class ClustalxColourScheme extends ResidueColourScheme int i = ResidueProperties.aaIndex[c]; - currentColour = Color.white; + Color colour = Color.white; if (i > 19) { - return currentColour; + return colour; } for (int k = 0; k < residueColour[i].cons.length; k++) @@ -301,7 +300,7 @@ public class ClustalxColourScheme extends ResidueColourScheme if (residueColour[i].cons[k].isConserved(cons2, j, size, includeGaps)) { - currentColour = residueColour[i].c; + colour = residueColour[i].c; } } @@ -312,11 +311,11 @@ public class ClustalxColourScheme extends ResidueColourScheme */ if (conses[27].isConserved(cons2, j, size, includeGaps)) { - currentColour = ClustalColour.PINK.colour; + colour = ClustalColour.PINK.colour; } } - return currentColour; + return colour; } /** diff --git a/src/jalview/schemes/NucleotideColourScheme.java b/src/jalview/schemes/NucleotideColourScheme.java index d1e18ef..abae733 100755 --- a/src/jalview/schemes/NucleotideColourScheme.java +++ b/src/jalview/schemes/NucleotideColourScheme.java @@ -24,7 +24,6 @@ import jalview.datamodel.AnnotatedCollectionI; import jalview.datamodel.SequenceCollectionI; import jalview.datamodel.SequenceI; -import java.awt.Color; import java.util.Map; /** @@ -43,20 +42,6 @@ public class NucleotideColourScheme extends ResidueColourScheme super(ResidueProperties.nucleotideIndex, ResidueProperties.nucleotide); } - /** - * DOCUMENT ME! - * - * @param n - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - @Override - public Color findColour(char c) - { - return colors[ResidueProperties.nucleotideIndex[c]]; - } - @Override public boolean isNucleotideSpecific() { diff --git a/src/jalview/schemes/PIDColourScheme.java b/src/jalview/schemes/PIDColourScheme.java index a6301fa..6ca1393 100755 --- a/src/jalview/schemes/PIDColourScheme.java +++ b/src/jalview/schemes/PIDColourScheme.java @@ -57,7 +57,7 @@ public class PIDColourScheme extends ResidueColourScheme c -= ('a' - 'A'); } - if (consensusResidue == null) + if (consensusResidue == null || Comparison.isGap(c)) { return Color.white; } @@ -71,15 +71,12 @@ public class PIDColourScheme extends ResidueColourScheme String.valueOf(c)); if (matchesConsensus) { - if (!Comparison.isGap(c)) + for (int i = 0; i < thresholds.length; i++) { - for (int i = 0; i < thresholds.length; i++) + if (pid > thresholds[i]) { - if (pid > thresholds[i]) - { - colour = pidColours[i]; - break; - } + colour = pidColours[i]; + break; } } } diff --git a/src/jalview/schemes/PurinePyrimidineColourScheme.java b/src/jalview/schemes/PurinePyrimidineColourScheme.java index 47b80c2..1b36f30 100644 --- a/src/jalview/schemes/PurinePyrimidineColourScheme.java +++ b/src/jalview/schemes/PurinePyrimidineColourScheme.java @@ -24,7 +24,6 @@ import jalview.datamodel.AnnotatedCollectionI; import jalview.datamodel.SequenceCollectionI; import jalview.datamodel.SequenceI; -import java.awt.Color; import java.util.Map; /** @@ -43,21 +42,6 @@ public class PurinePyrimidineColourScheme extends ResidueColourScheme ResidueProperties.purinepyrimidine); } - /** - * Finds the corresponding color for the type of character inputed - * - * @param c - * Character in sequence - * - * @return Color from purinepyrimidineIndex in - * jalview.schemes.ResidueProperties - */ - @Override - public Color findColour(char c) - { - return colors[ResidueProperties.purinepyrimidineIndex[c]]; - } - @Override public boolean isNucleotideSpecific() { diff --git a/src/jalview/schemes/ResidueColourScheme.java b/src/jalview/schemes/ResidueColourScheme.java index fc8b1b1..892c3e8 100755 --- a/src/jalview/schemes/ResidueColourScheme.java +++ b/src/jalview/schemes/ResidueColourScheme.java @@ -24,6 +24,7 @@ import jalview.datamodel.AlignmentI; import jalview.datamodel.AnnotatedCollectionI; import jalview.datamodel.SequenceCollectionI; import jalview.datamodel.SequenceI; +import jalview.util.Comparison; import java.awt.Color; import java.util.Map; @@ -89,7 +90,16 @@ public abstract class ResidueColourScheme implements ColourSchemeI @Override public Color findColour(char c) { - return colors == null ? Color.white : colors[symbolIndex[c]]; + Color colour = Color.white; + + if (!Comparison.isGap(c) && colors != null && symbolIndex != null + && c < symbolIndex.length + && symbolIndex[c] < colors.length) + { + colour = colors[symbolIndex[c]]; + } + + return colour; } /** @@ -104,18 +114,19 @@ public abstract class ResidueColourScheme implements ColourSchemeI return findColour(c, j, seq); } + /** + * Default implementation looks up the residue colour in a fixed scheme, or + * returns White if not found. Override this method for a colour scheme that + * depends on the column position or sequence. + * + * @param c + * @param j + * @param seq + * @return + */ protected Color findColour(char c, int j, SequenceI seq) { - Color colour = Color.white; - - if (colors != null && symbolIndex != null && c < symbolIndex.length - && symbolIndex[c] < colors.length) - { - colour = colors[symbolIndex[c]]; - } - // colour = adjustColour(c, j, colour); - - return colour; + return findColour(c); } @Override diff --git a/src/jalview/schemes/ScoreColourScheme.java b/src/jalview/schemes/ScoreColourScheme.java index 6850d79..aa20121 100755 --- a/src/jalview/schemes/ScoreColourScheme.java +++ b/src/jalview/schemes/ScoreColourScheme.java @@ -23,7 +23,6 @@ package jalview.schemes; import jalview.datamodel.AnnotatedCollectionI; import jalview.datamodel.SequenceCollectionI; import jalview.datamodel.SequenceI; -import jalview.util.Comparison; import java.awt.Color; import java.util.Map; @@ -88,27 +87,6 @@ public class ScoreColourScheme extends ResidueColourScheme /** * DOCUMENT ME! * - * @param s - * DOCUMENT ME! - * @param j - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - @Override - public Color findColour(char c, int j, SequenceI seq) - { - if (Comparison.isGap(c)) - { - return Color.white; - } - - return colors[ResidueProperties.aaIndex[c]]; - } - - /** - * DOCUMENT ME! - * * @param c * DOCUMENT ME! * diff --git a/src/jalview/schemes/UserColourScheme.java b/src/jalview/schemes/UserColourScheme.java index d95652d..85bf54e 100755 --- a/src/jalview/schemes/UserColourScheme.java +++ b/src/jalview/schemes/UserColourScheme.java @@ -238,24 +238,6 @@ public class UserColourScheme extends ResidueColourScheme } - @Override - public Color findColour(char c, int j, SequenceI seq) - { - Color colour; - int index = ResidueProperties.aaIndex[c]; - - if (lowerCaseColours != null && 'a' <= c && c <= 'z') - { - colour = lowerCaseColours[index]; - } - else - { - colour = colors[index]; - } - - return colour; - } - public void setLowerCaseColours(Color[] lcolours) { lowerCaseColours = lcolours; -- 1.7.10.2