apply gpl development license
[jalview.git] / src / jalview / schemes / ScoreColourScheme.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
3  * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
4  * 
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  * 
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  * 
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
18  */
19 package jalview.schemes;
20
21 import java.awt.*;
22
23 /**
24  * DOCUMENT ME!
25  * 
26  * @author $author$
27  * @version $Revision$
28  */
29 public class ScoreColourScheme extends ResidueColourScheme
30 {
31   /** DOCUMENT ME!! */
32   public double min;
33
34   /** DOCUMENT ME!! */
35   public double max;
36
37   /** DOCUMENT ME!! */
38   public double[] scores;
39
40   /**
41    * Creates a new ScoreColourScheme object.
42    * 
43    * @param scores
44    *                DOCUMENT ME!
45    * @param min
46    *                DOCUMENT ME!
47    * @param max
48    *                DOCUMENT ME!
49    */
50   public ScoreColourScheme(double[] scores, double min, double max)
51   {
52     super();
53
54     this.scores = scores;
55     this.min = min;
56     this.max = max;
57
58     // Make colours in constructor
59     // Why wasn't this done earlier?
60     int i, iSize = scores.length;
61     colors = new Color[scores.length];
62     for (i = 0; i < iSize; i++)
63     {
64       float red = (float) (scores[i] - (float) min) / (float) (max - min);
65
66       if (red > 1.0f)
67       {
68         red = 1.0f;
69       }
70
71       if (red < 0.0f)
72       {
73         red = 0.0f;
74       }
75       colors[i] = makeColour(red);
76     }
77   }
78
79   /**
80    * DOCUMENT ME!
81    * 
82    * @param s
83    *                DOCUMENT ME!
84    * @param j
85    *                DOCUMENT ME!
86    * 
87    * @return DOCUMENT ME!
88    */
89   public Color findColour(char c, int j)
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 }