import java.awt.Color;
/**
- * DOCUMENT ME!
- *
- * @author $author$
- * @version $Revision$
+ * A graduated colour scheme based on residue buried index score
*/
public class BuriedColourScheme extends ScoreColourScheme
{
- /**
- * Creates a new BuriedColourScheme object.
- */
- public BuriedColourScheme()
- {
- super(ResidueProperties.aaIndex, ResidueProperties.buried);
- }
+ private static final Color minScoreColour = new Color(0, 255, 0);
+
+ private static final Color maxScoreColour = new Color(0, 0, 255);
/**
- * DOCUMENT ME!
- *
- * @param c
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
+ * Constructor
*/
- @Override
- public Color makeColour(float c)
+ public BuriedColourScheme()
{
- return new Color(0, (float) (1.0 - c), c);
+ super(JalviewColourScheme.Buried.toString(), ResidueProperties.aaIndex,
+ ResidueProperties.buried, minScoreColour, maxScoreColour);
}
@Override
return true;
}
- @Override
- public String getSchemeName()
- {
- return JalviewColourScheme.Buried.toString();
- }
-
/**
* Returns a new instance of this colour scheme with which the given data may
* be coloured
import java.util.LinkedHashMap;
import java.util.Map;
-public class ColourSchemes
+public final class ColourSchemes
{
/*
* singleton instance of this class
import java.awt.Color;
+/**
+ * A graduated colour scheme based on residue helix propensity score
+ */
public class HelixColourScheme extends ScoreColourScheme
{
- public HelixColourScheme()
- {
- super(ResidueProperties.aaIndex, ResidueProperties.helix);
- }
+ private static final Color minScoreColour = new Color(0, 255, 0);
- @Override
- public Color makeColour(float c)
+ private static final Color maxScoreColour = new Color(255, 0, 255);
+
+ public HelixColourScheme()
{
- return new Color(c, (float) 1.0 - c, c);
+ super(JalviewColourScheme.Helix.toString(), ResidueProperties.aaIndex,
+ ResidueProperties.helix, minScoreColour, maxScoreColour);
}
@Override
return true;
}
- @Override
- public String getSchemeName()
- {
- return JalviewColourScheme.Helix.toString();
- }
-
/**
* Returns a new instance of this colour scheme with which the given data may
* be coloured
import java.awt.Color;
/**
- * DOCUMENT ME!
+ * A hydrophobicity colour scheme based on
*
- * @author $author$
- * @version $Revision$
+ * <pre>
+ * Kyte, J., and Doolittle, R.F., J. Mol. Biol. 1157, 105-132, 1982
+ * </pre>
*/
public class HydrophobicColourScheme extends ScoreColourScheme
{
- /**
- * Creates a new HydrophobicColourScheme object.
- */
- public HydrophobicColourScheme()
- {
- super(ResidueProperties.aaIndex, ResidueProperties.hyd);
- }
+ private static final Color minScoreColour = new Color(0, 0, 255);
+
+ private static final Color maxScoreColour = new Color(255, 0, 0);
/**
- * DOCUMENT ME!
- *
- * @param c
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
+ * Constructor
*/
- @Override
- public Color makeColour(float c)
+ public HydrophobicColourScheme()
{
- return new Color(c, (float) 0.0, (float) 1.0 - c);
+ super(JalviewColourScheme.Hydrophobic.toString(),
+ ResidueProperties.aaIndex, ResidueProperties.hyd,
+ minScoreColour, maxScoreColour);
}
@Override
return true;
}
- @Override
- public String getSchemeName()
- {
- return JalviewColourScheme.Hydrophobic.toString();
- }
-
/**
* Returns a new instance of this colour scheme with which the given data may
* be coloured
*/
public class ScoreColourScheme extends ResidueColourScheme
{
- public double min;
+ String schemeName;
- public double max;
+ double min;
- public double[] scores;
+ double max;
+
+ Color minColour;
+
+ Color maxColour;
+
+ double[] scores;
/**
* Constructor
*
* @param symbolIndex
- * a lookup where the index is a character e.g. 'R' or 'r', and the
- * value is its position in the colour table lookup
+ * a lookup where the index is a char e.g. 'R' or 'r', and the value
+ * is its position in the colour table lookup
* @param scores
- * per residue, indices matching colors lookup
+ * per residue, with indices corresponding to those for colour lookup
*/
- public ScoreColourScheme(int symbolIndex[], double[] scores)
+ public ScoreColourScheme(String name, int[] symbolIndex, double[] scores,
+ Color minColour, Color maxColour)
{
super(symbolIndex);
+ this.schemeName = name;
+ this.minColour = minColour;
+ this.maxColour = maxColour;
+
setMinMax(scores);
this.scores = scores;
- // Make colours in constructor
- // Why wasn't this done earlier?
int iSize = scores.length;
colors = new Color[scores.length];
for (int i = 0; i < iSize; i++)
{
- /*
- * scale score between min and max to the range 0.0 - 1.0
- */
- float score = (float) (scores[i] - (float) min) / (float) (max - min);
-
- if (score > 1.0f)
- {
- score = 1.0f;
- }
-
- if (score < 0.0f)
- {
- score = 0.0f;
- }
- colors[i] = makeColour(score);
+ colors[i] = getScoreColour(scores[i]);
}
}
/**
+ * Computes a colour for a score by
+ * <ul>
+ * <li>first scaling the score linearly from 0 (minScore) to 1 (maxScore)</li>
+ * <li>then interpolating rgb values from minColour to maxColour</li>
+ * </ul>
+ * This method is used to make colours for residue scores, but may also be
+ * called to generate a colour for an intermediate score value (for example, a
+ * column average).
+ */
+ public Color getScoreColour(double rawScore)
+ {
+ float score = (float) (rawScore - (float) min) / (float) (max - min);
+ score = Math.max(score, 0f);
+ score = Math.min(score, 1f);
+
+ int r = minColour.getRed()
+ + Math.round((maxColour.getRed() - minColour.getRed()) * score);
+ int g = minColour.getGreen()
+ + Math.round(
+ (maxColour.getGreen() - minColour.getGreen()) * score);
+ int b = minColour.getBlue()
+ + Math.round(
+ (maxColour.getBlue() - minColour.getBlue()) * score);
+
+ Color c = new Color(r, g, b);
+ return c;
+ }
+
+ /**
* Inspects score values and saves the minimum and maximum
*
* @param vals
return super.findColour(c);
}
- /**
- * DOCUMENT ME!
- *
- * @param c
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public Color makeColour(float c)
- {
- return new Color(c, (float) 0.0, (float) 1.0 - c);
- }
-
@Override
public String getSchemeName()
{
- return "Score";
+ return schemeName;
}
/**
public ColourSchemeI getInstance(AlignViewportI view,
AnnotatedCollectionI coll)
{
- return new ScoreColourScheme(symbolIndex, scores);
+ return new ScoreColourScheme(schemeName, symbolIndex, scores, minColour,
+ maxColour);
}
}
import java.awt.Color;
/**
- * DOCUMENT ME!
- *
- * @author $author$
- * @version $Revision$
+ * A graduated colour scheme based on residue strand propensity
*/
public class StrandColourScheme extends ScoreColourScheme
{
- /**
- * Creates a new StrandColourScheme object.
- */
- public StrandColourScheme()
- {
- super(ResidueProperties.aaIndex, ResidueProperties.strand);
- }
+ private static final Color minScoreColour = new Color(0, 0, 255);
+
+ private static final Color maxScoreColour = new Color(255, 255, 0);
/**
- * DOCUMENT ME!
- *
- * @param c
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
+ * Constructor
*/
- @Override
- public Color makeColour(float c)
+ public StrandColourScheme()
{
- return new Color(c, c, (float) 1.0 - c);
+ super(JalviewColourScheme.Strand.toString(), ResidueProperties.aaIndex,
+ ResidueProperties.strand, minScoreColour, maxScoreColour);
}
@Override
return true;
}
- @Override
- public String getSchemeName()
- {
- return JalviewColourScheme.Strand.toString();
- }
-
/**
* Returns a new instance of this colour scheme with which the given data may
* be coloured
import java.awt.Color;
/**
- * DOCUMENT ME!
- *
- * @author $author$
- * @version $Revision$
+ * A graduated colour scheme based on residue turn propensity
*/
public class TurnColourScheme extends ScoreColourScheme
{
- /**
- * Creates a new TurnColourScheme object.
- */
- public TurnColourScheme()
- {
- super(ResidueProperties.aaIndex, ResidueProperties.turn);
- }
+ private static final Color minScoreColour = new Color(0, 255, 255);
+
+ private static final Color maxScoreColour = new Color(255, 0, 0);
/**
- * DOCUMENT ME!
- *
- * @param c
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
+ * Constructor
*/
- @Override
- public Color makeColour(float c)
+ public TurnColourScheme()
{
- return new Color(c, 1 - c, 1 - c);
+ super(JalviewColourScheme.Turn.toString(), ResidueProperties.aaIndex,
+ ResidueProperties.turn, minScoreColour, maxScoreColour);
}
@Override
return true;
}
- @Override
- public String getSchemeName()
- {
- return JalviewColourScheme.Turn.toString();
- }
-
/**
* Returns a new instance of this colour scheme with which the given data may
* be coloured
*/
assertTrue(new UserColourScheme().isApplicableTo(peptide));
assertTrue(new UserColourScheme().isApplicableTo(nucleotide));
- assertTrue(new ScoreColourScheme(new int[] {}, new double[] {})
+ assertTrue(
+ new ScoreColourScheme("george", new int[] {}, new double[] {},
+ null, null)
.isApplicableTo(peptide));
- assertTrue(new ScoreColourScheme(new int[] {}, new double[] {})
+ assertTrue(
+ new ScoreColourScheme("jane", new int[] {}, new double[] {},
+ null, null)
.isApplicableTo(nucleotide));
ResidueColourScheme rcs = new PIDColourScheme();
assertTrue(rcs.isApplicableTo(peptide));
assertEquals("RNA Interaction type",
new RNAInteractionColourScheme().getSchemeName());
assertEquals("User Defined", new UserColourScheme().getSchemeName());
- assertEquals("Score", new ScoreColourScheme(new int[] {},
- new double[] {}).getSchemeName());
+ assertEquals("Score", new ScoreColourScheme("Score", new int[] {},
+ new double[] {}, null, null).getSchemeName());
assertEquals("% Identity", new PIDColourScheme().getSchemeName());
assertEquals("Follower", new FollowerColourScheme().getSchemeName());
assertEquals("T-Coffee Scores",