JAL-1807 - Bob's last(?) before leaving Dundee -- adds fast file loading
[jalviewjs.git] / src / jalview / schemes / ScoreColourScheme.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
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
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.schemes;
22
23 import jalview.datamodel.SequenceI;
24 import jalview.util.Comparison;
25
26 import java.awt.Color;
27
28 /**
29  * DOCUMENT ME!
30  * 
31  * @author $author$
32  * @version $Revision$
33  */
34 public class ScoreColourScheme extends ResidueColourScheme
35 {
36   /** DOCUMENT ME!! */
37   public double min;
38
39   /** DOCUMENT ME!! */
40   public double max;
41
42   /** DOCUMENT ME!! */
43   public double[] scores;
44
45   /**
46    * Creates a new ScoreColourScheme object.
47    * 
48    * @param scores
49    *          DOCUMENT ME!
50    * @param min
51    *          DOCUMENT ME!
52    * @param max
53    *          DOCUMENT ME!
54    */
55   public ScoreColourScheme(int symbolIndex[], double[] scores, double min,
56           double max)
57   {
58     super(symbolIndex);
59
60     this.scores = scores;
61     this.min = min;
62     this.max = max;
63
64     // Make colours in constructor
65     // Why wasn't this done earlier?
66     int i, iSize = scores.length;
67     colors = new Color[scores.length];
68     for (i = 0; i < iSize; i++)
69     {
70       float red = (float) (scores[i] - (float) min) / (float) (max - min);
71
72       if (red > 1.0f)
73       {
74         red = 1.0f;
75       }
76
77       if (red < 0.0f)
78       {
79         red = 0.0f;
80       }
81       colors[i] = makeColour(red);
82     }
83   }
84
85   /**
86    * DOCUMENT ME!
87    * 
88    * @param s
89    *          DOCUMENT ME!
90    * @param j
91    *          DOCUMENT ME!
92    * 
93    * @return DOCUMENT ME!
94    */
95   @Override
96   public Color findColourSeq(char c, int j, SequenceI seq)
97   {
98     if (threshold > 0)
99     {
100       if (!aboveThreshold(c, j))
101       {
102         return Color.white;
103       }
104     }
105
106     if (Comparison.isGap(c))
107     {
108       return Color.white;
109     }
110
111     Color currentColour = colors[ResidueProperties.aaIndex[c]];
112
113     if (conservationColouring)
114     {
115       currentColour = applyConservation(currentColour, j);
116     }
117
118     return currentColour;
119   }
120
121   /**
122    * DOCUMENT ME!
123    * 
124    * @param c
125    *          DOCUMENT ME!
126    * 
127    * @return DOCUMENT ME!
128    */
129   public Color makeColour(float c)
130   {
131     return new Color(c, (float) 0.0, (float) 1.0 - c);
132   }
133 }