JAL-1066 - T-Coffee color scheme + signature change on findColour method
[jalview.git] / src / jalview / schemes / ScoreColourScheme.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3  * Copyright (C) 2011 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
10  * 
11  * Jalview is distributed in the hope that it will be useful, but 
12  * WITHOUT ANY WARRANTY; without even the implied warranty 
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14  * PURPOSE.  See the GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 package jalview.schemes;
19
20 import java.awt.Color;
21
22 /**
23  * DOCUMENT ME!
24  * 
25  * @author $author$
26  * @version $Revision$
27  */
28 public class ScoreColourScheme extends ResidueColourScheme
29 {
30   /** DOCUMENT ME!! */
31   public double min;
32
33   /** DOCUMENT ME!! */
34   public double max;
35
36   /** DOCUMENT ME!! */
37   public double[] scores;
38
39   /**
40    * Creates a new ScoreColourScheme object.
41    * 
42    * @param scores
43    *          DOCUMENT ME!
44    * @param min
45    *          DOCUMENT ME!
46    * @param max
47    *          DOCUMENT ME!
48    */
49   public ScoreColourScheme(double[] scores, double min, double max)
50   {
51     super();
52
53     this.scores = scores;
54     this.min = min;
55     this.max = max;
56
57     // Make colours in constructor
58     // Why wasn't this done earlier?
59     int i, iSize = scores.length;
60     colors = new Color[scores.length];
61     for (i = 0; i < iSize; i++)
62     {
63       float red = (float) (scores[i] - (float) min) / (float) (max - min);
64
65       if (red > 1.0f)
66       {
67         red = 1.0f;
68       }
69
70       if (red < 0.0f)
71       {
72         red = 0.0f;
73       }
74       colors[i] = makeColour(red);
75     }
76   }
77
78   /**
79    * DOCUMENT ME!
80    * 
81    * @param s
82    *          DOCUMENT ME!
83    * @param j
84    *          DOCUMENT ME!
85    * 
86    * @return DOCUMENT ME!
87    */
88   @Override
89   public Color findColour(char c, int j, int sequenceIndex)
90   {
91     if (threshold > 0)
92     {
93       if (!aboveThreshold(c, j))
94       {
95         return Color.white;
96       }
97     }
98
99     if (jalview.util.Comparison.isGap(c))
100     {
101       return Color.white;
102     }
103
104     Color currentColour = colors[ResidueProperties.aaIndex[c]];
105
106     if (conservationColouring)
107     {
108       currentColour = applyConservation(currentColour, j);
109     }
110
111     return currentColour;
112   }
113
114   /**
115    * DOCUMENT ME!
116    * 
117    * @param c
118    *          DOCUMENT ME!
119    * 
120    * @return DOCUMENT ME!
121    */
122   public Color makeColour(float c)
123   {
124     return new Color(c, (float) 0.0, (float) 1.0 - c);
125   }
126 }