update author list in license for (JAL-826)
[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, J Engelhardt, LM Lui, 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.*;
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   public Color findColour(char c, int j)
89   {
90     if (threshold > 0)
91     {
92       if (!aboveThreshold(c, j))
93       {
94         return Color.white;
95       }
96     }
97
98     if (jalview.util.Comparison.isGap(c))
99     {
100       return Color.white;
101     }
102
103     Color currentColour = colors[ResidueProperties.aaIndex[c]];
104
105     if (conservationColouring)
106     {
107       currentColour = applyConservation(currentColour, j);
108     }
109
110     return currentColour;
111   }
112
113   /**
114    * DOCUMENT ME!
115    * 
116    * @param c
117    *          DOCUMENT ME!
118    * 
119    * @return DOCUMENT ME!
120    */
121   public Color makeColour(float c)
122   {
123     return new Color(c, (float) 0.0, (float) 1.0 - c);
124   }
125 }