Formatting changes
[jalview.git] / src / jalview / schemes / ResidueColourScheme.java
1 /*\r
2 * Jalview - A Sequence Alignment Editor and Viewer\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
4 *\r
5 * This program is free software; you can redistribute it and/or\r
6 * modify it under the terms of the GNU General Public License\r
7 * as published by the Free Software Foundation; either version 2\r
8 * of the License, or (at your option) any later version.\r
9 *\r
10 * This program is distributed in the hope that it will be useful,\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 * GNU General Public License for more details.\r
14 *\r
15 * You should have received a copy of the GNU General Public License\r
16 * along with this program; if not, write to the Free Software\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
18 */\r
19 package jalview.schemes;\r
20 \r
21 import java.awt.*;\r
22 \r
23 import java.util.*;\r
24 \r
25 \r
26 /**\r
27  * DOCUMENT ME!\r
28  *\r
29  * @author $author$\r
30  * @version $Revision$\r
31  */\r
32 public class ResidueColourScheme implements ColourSchemeI\r
33 {\r
34     Color[] colors;\r
35     int threshold = 0;\r
36 \r
37     /** DOCUMENT ME!! */\r
38     public Vector consensus;\r
39 \r
40     /**\r
41      * Creates a new ResidueColourScheme object.\r
42      *\r
43      * @param colors DOCUMENT ME!\r
44      * @param threshold DOCUMENT ME!\r
45      */\r
46     public ResidueColourScheme(Color[] colors, int threshold)\r
47     {\r
48         this.colors = colors;\r
49         this.threshold = threshold;\r
50     }\r
51 \r
52     /**\r
53      * Creates a new ResidueColourScheme object.\r
54      */\r
55     public ResidueColourScheme()\r
56     {\r
57     }\r
58 \r
59     /**\r
60      * DOCUMENT ME!\r
61      *\r
62      * @param consensus DOCUMENT ME!\r
63      */\r
64     public void setConsensus(Vector consensus)\r
65     {\r
66         this.consensus = consensus;\r
67     }\r
68 \r
69     /**\r
70      * DOCUMENT ME!\r
71      *\r
72      * @param aa DOCUMENT ME!\r
73      *\r
74      * @return DOCUMENT ME!\r
75      */\r
76     public Color findColour(String aa)\r
77     {\r
78         return colors[((Integer) (ResidueProperties.aaHash.get(aa))).intValue()];\r
79     }\r
80 \r
81     /**\r
82      * DOCUMENT ME!\r
83      *\r
84      * @param s DOCUMENT ME!\r
85      * @param j DOCUMENT ME!\r
86      *\r
87      * @return DOCUMENT ME!\r
88      */\r
89     public Color findColour(String s, int j)\r
90     {\r
91         if ((threshold == 0) || aboveThreshold(s, j))\r
92         {\r
93             return colors[((Integer) (ResidueProperties.aaHash.get(s))).intValue()];\r
94         }\r
95         else\r
96         {\r
97             return Color.white;\r
98         }\r
99     }\r
100 \r
101     /**\r
102      * DOCUMENT ME!\r
103      *\r
104      * @return DOCUMENT ME!\r
105      */\r
106     public int getThreshold()\r
107     {\r
108         return threshold;\r
109     }\r
110 \r
111     /**\r
112      * DOCUMENT ME!\r
113      *\r
114      * @param ct DOCUMENT ME!\r
115      */\r
116     public void setThreshold(int ct)\r
117     {\r
118         threshold = ct;\r
119     }\r
120 \r
121     /**\r
122      * DOCUMENT ME!\r
123      *\r
124      * @param s DOCUMENT ME!\r
125      * @param j DOCUMENT ME!\r
126      *\r
127      * @return DOCUMENT ME!\r
128      */\r
129     public boolean aboveThreshold(String s, int j)\r
130     {\r
131         Hashtable hash = (Hashtable) consensus.elementAt(j);\r
132 \r
133         if ((((Integer) hash.get("maxCount")).intValue() != -1) &&\r
134                 hash.contains(s))\r
135         {\r
136             ////  resCount////////////////////                  ///////////////seq count////////////\r
137             double sc = (((Integer) hash.get(s)).intValue() * 100.0) / ((Integer) hash.get(\r
138                     "size")).intValue();\r
139 \r
140             if (sc >= threshold)\r
141             {\r
142                 return true;\r
143             }\r
144         }\r
145 \r
146         return false;\r
147     }\r
148 }\r