applied copyright 2008
[jalview.git] / src / jalview / schemes / ScoreColourScheme.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3  * Copyright (C) 2008 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
30     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 DOCUMENT ME!
45    * @param min DOCUMENT ME!
46    * @param max DOCUMENT ME!
47    */
48   public ScoreColourScheme(double[] scores, double min, double max)
49   {
50     super();
51
52     this.scores = scores;
53     this.min = min;
54     this.max = max;
55
56     // Make colours in constructor
57     // Why wasn't this done earlier?
58     int i, iSize = scores.length;
59     colors = new Color[scores.length];
60     for (i = 0; i < iSize; i++)
61     {
62       float red = (float) (scores[i] - (float) min) / (float) (max - min);
63
64       if (red > 1.0f)
65       {
66         red = 1.0f;
67       }
68
69       if (red < 0.0f)
70       {
71         red = 0.0f;
72       }
73       colors[i] = makeColour(red);
74     }
75   }
76
77   /**
78    * DOCUMENT ME!
79    *
80    * @param s DOCUMENT ME!
81    * @param j DOCUMENT ME!
82    *
83    * @return DOCUMENT ME!
84    */
85   public Color findColour(char c, int j)
86   {
87     if (threshold > 0)
88     {
89       if (!aboveThreshold(c, j))
90       {
91         return Color.white;
92       }
93     }
94
95     if (jalview.util.Comparison.isGap(c))
96     {
97       return Color.white;
98     }
99
100     Color currentColour = colors[ResidueProperties.aaIndex[c]];
101
102     if (conservationColouring)
103     {
104       currentColour = applyConservation(currentColour, j);
105     }
106
107     return currentColour;
108   }
109
110   /**
111    * DOCUMENT ME!
112    *
113    * @param c DOCUMENT ME!
114    *
115    * @return DOCUMENT ME!
116    */
117   public Color makeColour(float c)
118   {
119     return new Color(c, (float) 0.0, (float) 1.0 - c);
120   }
121 }