Merge remote-tracking branch 'origin/Tcoffee_JAL-1065' into develop
[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 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(double[] scores, double min, double max)
52   {
53     super();
54
55     this.scores = scores;
56     this.min = min;
57     this.max = max;
58
59     // Make colours in constructor
60     // Why wasn't this done earlier?
61     int i, iSize = scores.length;
62     colors = new Color[scores.length];
63     for (i = 0; i < iSize; i++)
64     {
65       float red = (float) (scores[i] - (float) min) / (float) (max - min);
66
67       if (red > 1.0f)
68       {
69         red = 1.0f;
70       }
71
72       if (red < 0.0f)
73       {
74         red = 0.0f;
75       }
76       colors[i] = makeColour(red);
77     }
78   }
79
80   /**
81    * DOCUMENT ME!
82    * 
83    * @param s
84    *          DOCUMENT ME!
85    * @param j
86    *          DOCUMENT ME!
87    * 
88    * @return DOCUMENT ME!
89    */
90   @Override
91   public Color findColour(char c, int j, SequenceI seq)
92   {
93     if (threshold > 0)
94     {
95       if (!aboveThreshold(c, j))
96       {
97         return Color.white;
98       }
99     }
100
101     if (jalview.util.Comparison.isGap(c))
102     {
103       return Color.white;
104     }
105
106     Color currentColour = colors[ResidueProperties.aaIndex[c]];
107
108     if (conservationColouring)
109     {
110       currentColour = applyConservation(currentColour, j);
111     }
112
113     return currentColour;
114   }
115
116   /**
117    * DOCUMENT ME!
118    * 
119    * @param c
120    *          DOCUMENT ME!
121    * 
122    * @return DOCUMENT ME!
123    */
124   public Color makeColour(float c)
125   {
126     return new Color(c, (float) 0.0, (float) 1.0 - c);
127   }
128 }