aa20121dc616bf9489ff9d5937ad8ca7050f62d7
[jalview.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.AnnotatedCollectionI;
24 import jalview.datamodel.SequenceCollectionI;
25 import jalview.datamodel.SequenceI;
26
27 import java.awt.Color;
28 import java.util.Map;
29
30 /**
31  * DOCUMENT ME!
32  * 
33  * @author $author$
34  * @version $Revision$
35  */
36 public class ScoreColourScheme extends ResidueColourScheme
37 {
38   /** DOCUMENT ME!! */
39   public double min;
40
41   /** DOCUMENT ME!! */
42   public double max;
43
44   /** DOCUMENT ME!! */
45   public double[] scores;
46
47   /**
48    * Creates a new ScoreColourScheme object.
49    * 
50    * @param scores
51    *          DOCUMENT ME!
52    * @param min
53    *          DOCUMENT ME!
54    * @param max
55    *          DOCUMENT ME!
56    */
57   public ScoreColourScheme(int symbolIndex[], double[] scores, double min,
58           double max)
59   {
60     super(symbolIndex);
61
62     this.scores = scores;
63     this.min = min;
64     this.max = max;
65
66     // Make colours in constructor
67     // Why wasn't this done earlier?
68     int i, iSize = scores.length;
69     colors = new Color[scores.length];
70     for (i = 0; i < iSize; i++)
71     {
72       float red = (float) (scores[i] - (float) min) / (float) (max - min);
73
74       if (red > 1.0f)
75       {
76         red = 1.0f;
77       }
78
79       if (red < 0.0f)
80       {
81         red = 0.0f;
82       }
83       colors[i] = makeColour(red);
84     }
85   }
86
87   /**
88    * DOCUMENT ME!
89    * 
90    * @param c
91    *          DOCUMENT ME!
92    * 
93    * @return DOCUMENT ME!
94    */
95   public Color makeColour(float c)
96   {
97     return new Color(c, (float) 0.0, (float) 1.0 - c);
98   }
99
100   @Override
101   public String getSchemeName()
102   {
103     return "Score";
104   }
105
106   /**
107    * Returns a new instance of this colour scheme with which the given data may
108    * be coloured
109    */
110   @Override
111   public ColourSchemeI getInstance(AnnotatedCollectionI coll,
112           Map<SequenceI, SequenceCollectionI> hrs)
113   {
114     return new ScoreColourScheme(symbolIndex, scores, min, max);
115   }
116 }