From 688e59f05f78f52d949f29cd5adc33503d98a147 Mon Sep 17 00:00:00 2001 From: Paolo Di Tommaso Date: Mon, 9 Apr 2012 21:27:05 +0200 Subject: [PATCH] JAL-1066 - T-Coffee color scheme + signature change on findColour method --- src/jalview/schemes/AnnotationColourGradient.java | 10 ++-- src/jalview/schemes/Blosum62ColourScheme.java | 7 ++- src/jalview/schemes/ClustalxColourScheme.java | 12 ++-- src/jalview/schemes/ColourSchemeI.java | 4 +- src/jalview/schemes/ColourSchemeProperty.java | 10 +++- src/jalview/schemes/NucleotideColourScheme.java | 6 +- src/jalview/schemes/PIDColourScheme.java | 10 ++-- src/jalview/schemes/ResidueColourScheme.java | 11 ++-- src/jalview/schemes/ScoreColourScheme.java | 5 +- src/jalview/schemes/TCoffeeColourScheme.java | 66 +++++++++++++++++++++ src/jalview/schemes/UserColourScheme.java | 8 +-- 11 files changed, 117 insertions(+), 32 deletions(-) create mode 100644 src/jalview/schemes/TCoffeeColourScheme.java diff --git a/src/jalview/schemes/AnnotationColourGradient.java b/src/jalview/schemes/AnnotationColourGradient.java index e265598..5d12cce 100755 --- a/src/jalview/schemes/AnnotationColourGradient.java +++ b/src/jalview/schemes/AnnotationColourGradient.java @@ -17,9 +17,10 @@ */ package jalview.schemes; -import java.awt.*; +import jalview.datamodel.AlignmentAnnotation; +import jalview.datamodel.GraphLine; -import jalview.datamodel.*; +import java.awt.Color; public class AnnotationColourGradient extends ResidueColourScheme { @@ -152,7 +153,8 @@ public class AnnotationColourGradient extends ResidueColourScheme * * @return DOCUMENT ME! */ - public Color findColour(char c, int j) + @Override + public Color findColour(char c, int j, int sequenceIndex) { Color currentColour = Color.white; @@ -202,7 +204,7 @@ public class AnnotationColourGradient extends ResidueColourScheme if (colourScheme != null) { - currentColour = colourScheme.findColour(c, j); + currentColour = colourScheme.findColour(c, j, sequenceIndex); } else if (range != 0) { diff --git a/src/jalview/schemes/Blosum62ColourScheme.java b/src/jalview/schemes/Blosum62ColourScheme.java index 3236b55..c511ded 100755 --- a/src/jalview/schemes/Blosum62ColourScheme.java +++ b/src/jalview/schemes/Blosum62ColourScheme.java @@ -17,9 +17,9 @@ */ package jalview.schemes; -import java.awt.*; +import jalview.analysis.AAFrequency; -import jalview.analysis.*; +import java.awt.Color; public class Blosum62ColourScheme extends ResidueColourScheme { @@ -28,7 +28,8 @@ public class Blosum62ColourScheme extends ResidueColourScheme super(); } - public Color findColour(char res, int j) + @Override + public Color findColour(char res, int j, int sequenceIndex) { if ('a' <= res && res <= 'z') { diff --git a/src/jalview/schemes/ClustalxColourScheme.java b/src/jalview/schemes/ClustalxColourScheme.java index 309bdc2..ad6d37f 100755 --- a/src/jalview/schemes/ClustalxColourScheme.java +++ b/src/jalview/schemes/ClustalxColourScheme.java @@ -17,11 +17,11 @@ */ package jalview.schemes; -import java.util.*; +import jalview.datamodel.SequenceI; -import java.awt.*; - -import jalview.datamodel.*; +import java.awt.Color; +import java.util.Hashtable; +import java.util.Vector; public class ClustalxColourScheme extends ResidueColourScheme // implements // IParameterizable @@ -251,12 +251,14 @@ public class ClustalxColourScheme extends ResidueColourScheme // implements ResidueColour[19] = colours[0]; // V } + @Override public Color findColour(char c) { return Color.pink; } - public Color findColour(char c, int j) + @Override + public Color findColour(char c, int j, int sequenceIndex) { Color currentColour; diff --git a/src/jalview/schemes/ColourSchemeI.java b/src/jalview/schemes/ColourSchemeI.java index fdda463..e8e5828 100755 --- a/src/jalview/schemes/ColourSchemeI.java +++ b/src/jalview/schemes/ColourSchemeI.java @@ -17,13 +17,13 @@ */ package jalview.schemes; -import java.awt.*; +import java.awt.Color; public interface ColourSchemeI { public Color findColour(char c); - public Color findColour(char c, int j); + public Color findColour(char c, int j, int sequenceIndex); public void setConsensus(java.util.Hashtable[] h); diff --git a/src/jalview/schemes/ColourSchemeProperty.java b/src/jalview/schemes/ColourSchemeProperty.java index 0f758e0..3738f61 100755 --- a/src/jalview/schemes/ColourSchemeProperty.java +++ b/src/jalview/schemes/ColourSchemeProperty.java @@ -17,7 +17,7 @@ */ package jalview.schemes; -import java.awt.*; +import java.awt.Color; /** * ColourSchemeProperty Binds names to hardwired colourschemes and tries to deal @@ -81,6 +81,9 @@ public class ColourSchemeProperty public static final int PURINEPYRIMIDINE = 13; public static final int COVARIATION = 14; + + public static final int TCOFFEE = 15; + /** * index of first colourscheme (includes 'None') @@ -145,6 +148,11 @@ public class ColourSchemeProperty { ret = NUCLEOTIDE; } + else if (name.equalsIgnoreCase("T-Coffee scores")) + { + ret = TCOFFEE; + } + else if (name.equalsIgnoreCase("User Defined")) { ret = USER_DEFINED; diff --git a/src/jalview/schemes/NucleotideColourScheme.java b/src/jalview/schemes/NucleotideColourScheme.java index 249d87d..df4d9a9 100755 --- a/src/jalview/schemes/NucleotideColourScheme.java +++ b/src/jalview/schemes/NucleotideColourScheme.java @@ -17,7 +17,7 @@ */ package jalview.schemes; -import java.awt.*; +import java.awt.Color; /** * DOCUMENT ME! @@ -43,6 +43,7 @@ public class NucleotideColourScheme extends ResidueColourScheme * * @return DOCUMENT ME! */ + @Override public Color findColour(char c) { // System.out.println("called"); log.debug @@ -59,7 +60,8 @@ public class NucleotideColourScheme extends ResidueColourScheme * * @return DOCUMENT ME! */ - public Color findColour(char c, int j) + @Override + public Color findColour(char c, int j, int sequenceIndex) { Color currentColour; if ((threshold == 0) || aboveThreshold(c, j)) diff --git a/src/jalview/schemes/PIDColourScheme.java b/src/jalview/schemes/PIDColourScheme.java index 23a2ee2..c4f7eb5 100755 --- a/src/jalview/schemes/PIDColourScheme.java +++ b/src/jalview/schemes/PIDColourScheme.java @@ -17,10 +17,10 @@ */ package jalview.schemes; -import java.awt.*; +import jalview.analysis.AAFrequency; +import jalview.datamodel.SequenceGroup; -import jalview.analysis.*; -import jalview.datamodel.*; +import java.awt.Color; public class PIDColourScheme extends ResidueColourScheme { @@ -36,7 +36,9 @@ public class PIDColourScheme extends ResidueColourScheme this.thresholds = ResidueProperties.pidThresholds; } - public Color findColour(char c, int j) + + @Override + public Color findColour(char c, int j, int sequenceIndex) { if ('a' <= c && c <= 'z') { diff --git a/src/jalview/schemes/ResidueColourScheme.java b/src/jalview/schemes/ResidueColourScheme.java index 5402d75..cc7f0d8 100755 --- a/src/jalview/schemes/ResidueColourScheme.java +++ b/src/jalview/schemes/ResidueColourScheme.java @@ -17,11 +17,11 @@ */ package jalview.schemes; -import java.util.*; +import jalview.analysis.AAFrequency; +import jalview.analysis.Conservation; -import java.awt.*; - -import jalview.analysis.*; +import java.awt.Color; +import java.util.Hashtable; /** * DOCUMENT ME! @@ -82,7 +82,8 @@ public class ResidueColourScheme implements ColourSchemeI : colors[ResidueProperties.aaIndex[c]]; } - public Color findColour(char c, int j) + @Override + public Color findColour(char c, int j, int sequenceIndex) { Color currentColour; diff --git a/src/jalview/schemes/ScoreColourScheme.java b/src/jalview/schemes/ScoreColourScheme.java index 37dd9e5..49aeeeb 100755 --- a/src/jalview/schemes/ScoreColourScheme.java +++ b/src/jalview/schemes/ScoreColourScheme.java @@ -17,7 +17,7 @@ */ package jalview.schemes; -import java.awt.*; +import java.awt.Color; /** * DOCUMENT ME! @@ -85,7 +85,8 @@ public class ScoreColourScheme extends ResidueColourScheme * * @return DOCUMENT ME! */ - public Color findColour(char c, int j) + @Override + public Color findColour(char c, int j, int sequenceIndex) { if (threshold > 0) { diff --git a/src/jalview/schemes/TCoffeeColourScheme.java b/src/jalview/schemes/TCoffeeColourScheme.java new file mode 100644 index 0000000..740c15e --- /dev/null +++ b/src/jalview/schemes/TCoffeeColourScheme.java @@ -0,0 +1,66 @@ +package jalview.schemes; + +import jalview.io.TCoffeeScoreFile; + +import java.awt.Color; + +/** + * Defines the color score for T-Coffee MSA + *

+ * See http://tcoffee.org + * + * + * @author Paolo Di Tommaso + * + */ +public class TCoffeeColourScheme extends ResidueColourScheme { + + static final Color[] colors = { + new Color( 102, 102, 255 ), // #6666FF + new Color( 0, 255, 0), // #00FF00 + new Color( 102, 255, 0), // #66FF00 + new Color( 204, 255, 0), // #CCFF00 + new Color( 255, 255, 0), // #FFFF00 + new Color( 255, 204, 0), // #FFCC00 + new Color( 255, 153, 0), // #FF9900 + new Color( 255, 102, 0), // #FF6600 + new Color( 255, 51, 0), // #FF3300 + new Color( 255, 34, 0) // #FF2000 + }; + + + byte[][] scoreMatrix = null; + + /** + * Initialize the color sheme based on the content of the T-Coffee score file + * + * @param scoreFile + */ + public TCoffeeColourScheme(TCoffeeScoreFile scoreFile) { + + scoreMatrix = scoreFile != null ? scoreFile.getScoresArray() : null; + + } + + @Override + public Color findColour(char c, int j, int sequenceIndex) { + + if( scoreMatrix == null ) { + return Color.white; + } + + if( sequenceIndex<0 || sequenceIndex >= scoreMatrix.length ) { + System.out.printf("Sequence index out of range for the T-Coffee color scheme. Index: %s\n", sequenceIndex); + return Color.white; + } + + byte[] seqScores = scoreMatrix[sequenceIndex]; + if( j < 0 || j>= seqScores.length ) { + System.out.printf("Residue index out of range for the T-Coffee color scheme. Sequence %s - residue: %s\n", sequenceIndex, j); + return Color.white; + } + + byte val = seqScores[j]; + return val >= 0 && val < colors.length ? colors[val] : Color.white; + } +} diff --git a/src/jalview/schemes/UserColourScheme.java b/src/jalview/schemes/UserColourScheme.java index b6602ea..0c1e688 100755 --- a/src/jalview/schemes/UserColourScheme.java +++ b/src/jalview/schemes/UserColourScheme.java @@ -17,9 +17,8 @@ */ package jalview.schemes; -import java.util.*; - -import java.awt.*; +import java.awt.Color; +import java.util.StringTokenizer; public class UserColourScheme extends ResidueColourScheme { @@ -201,7 +200,8 @@ public class UserColourScheme extends ResidueColourScheme } - public Color findColour(char c, int j) + @Override + public Color findColour(char c, int j, int sequenceIndex) { Color currentColour; int index = ResidueProperties.aaIndex[c]; -- 1.7.10.2