2fb63388d032f784d1bac87ca9f76b9f8a6b2d57
[jalview.git] / src / jalview / schemes / ScoreColourScheme.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3  * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, 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 jalview.datamodel.SequenceI;
21
22 import java.awt.Color;
23
24 /**
25  * DOCUMENT ME!
26  * 
27  * @author $author$
28  * @version $Revision$
29  */
30 public class ScoreColourScheme extends ResidueColourScheme
31 {
32   /** DOCUMENT ME!! */
33   public double min;
34
35   /** DOCUMENT ME!! */
36   public double max;
37
38   /** DOCUMENT ME!! */
39   public double[] scores;
40
41   /**
42    * Creates a new ScoreColourScheme object.
43    * 
44    * @param scores
45    *          DOCUMENT ME!
46    * @param min
47    *          DOCUMENT ME!
48    * @param max
49    *          DOCUMENT ME!
50    */
51   public ScoreColourScheme(int symbolIndex[], double[] scores, double min,
52           double max)
53   {
54     super(symbolIndex);
55
56     this.scores = scores;
57     this.min = min;
58     this.max = max;
59
60     // Make colours in constructor
61     // Why wasn't this done earlier?
62     int i, iSize = scores.length;
63     colors = new Color[scores.length];
64     for (i = 0; i < iSize; i++)
65     {
66       float red = (float) (scores[i] - (float) min) / (float) (max - min);
67
68       if (red > 1.0f)
69       {
70         red = 1.0f;
71       }
72
73       if (red < 0.0f)
74       {
75         red = 0.0f;
76       }
77       colors[i] = makeColour(red);
78     }
79   }
80
81   /**
82    * DOCUMENT ME!
83    * 
84    * @param s
85    *          DOCUMENT ME!
86    * @param j
87    *          DOCUMENT ME!
88    * 
89    * @return DOCUMENT ME!
90    */
91   @Override
92   public Color findColour(char c, int j, SequenceI seq)
93   {
94     if (threshold > 0)
95     {
96       if (!aboveThreshold(c, j))
97       {
98         return Color.white;
99       }
100     }
101
102     if (jalview.util.Comparison.isGap(c))
103     {
104       return Color.white;
105     }
106
107     Color currentColour = colors[ResidueProperties.aaIndex[c]];
108
109     if (conservationColouring)
110     {
111       currentColour = applyConservation(currentColour, j);
112     }
113
114     return currentColour;
115   }
116
117   /**
118    * DOCUMENT ME!
119    * 
120    * @param c
121    *          DOCUMENT ME!
122    * 
123    * @return DOCUMENT ME!
124    */
125   public Color makeColour(float c)
126   {
127     return new Color(c, (float) 0.0, (float) 1.0 - c);
128   }
129 }