Percentage precalculated in aafrequency
[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     /* Set when threshold colouring to either pid_gaps or pid_nogaps*/\r
38     protected String ignoreGaps = "pid_gaps";\r
39 \r
40     /** DOCUMENT ME!! */\r
41     public Hashtable [] consensus;\r
42 \r
43     /**\r
44      * Creates a new ResidueColourScheme object.\r
45      *\r
46      * @param colors DOCUMENT ME!\r
47      * @param threshold DOCUMENT ME!\r
48      */\r
49     public ResidueColourScheme(Color[] colors, int threshold)\r
50     {\r
51         this.colors = colors;\r
52         this.threshold = threshold;\r
53     }\r
54 \r
55     /**\r
56      * Creates a new ResidueColourScheme object.\r
57      */\r
58     public ResidueColourScheme()\r
59     {\r
60     }\r
61 \r
62     /**\r
63      * DOCUMENT ME!\r
64      *\r
65      * @param consensus DOCUMENT ME!\r
66      */\r
67     public void setConsensus(Vector vconsensus)\r
68     {\r
69        int i, iSize=vconsensus.size();\r
70        consensus = new Hashtable[iSize];\r
71        for(i=0; i<iSize; i++)\r
72         consensus[i] = (Hashtable)vconsensus.elementAt(i);\r
73     }\r
74 \r
75     /**\r
76      * DOCUMENT ME!\r
77      *\r
78      * @param aa DOCUMENT ME!\r
79      *\r
80      * @return DOCUMENT ME!\r
81      */\r
82     public Color findColour(String aa)\r
83     {\r
84         return colors[((Integer) (ResidueProperties.aaHash.get(aa))).intValue()];\r
85     }\r
86 \r
87     /**\r
88      * DOCUMENT ME!\r
89      *\r
90      * @param s DOCUMENT ME!\r
91      * @param j DOCUMENT ME!\r
92      *\r
93      * @return DOCUMENT ME!\r
94      */\r
95     public Color findColour(String s, int j)\r
96     {\r
97         if ((threshold == 0) || aboveThreshold(s, j))\r
98         {\r
99             return colors[((Integer) (ResidueProperties.aaHash.get(s))).intValue()];\r
100         }\r
101         else\r
102         {\r
103             return Color.white;\r
104         }\r
105     }\r
106 \r
107     /**\r
108      * DOCUMENT ME!\r
109      *\r
110      * @return DOCUMENT ME!\r
111      */\r
112     public int getThreshold()\r
113     {\r
114         return threshold;\r
115     }\r
116 \r
117     /**\r
118      * DOCUMENT ME!\r
119      *\r
120      * @param ct DOCUMENT ME!\r
121      */\r
122     public void setThreshold(int ct, boolean ignoreGaps)\r
123     {\r
124         threshold = ct;\r
125         if(ignoreGaps)\r
126           this.ignoreGaps = "pid_nogaps";\r
127         else\r
128           this.ignoreGaps = "pid_gaps";\r
129     }\r
130 \r
131     /**\r
132      * DOCUMENT ME!\r
133      *\r
134      * @param s DOCUMENT ME!\r
135      * @param j DOCUMENT ME!\r
136      *\r
137      * @return DOCUMENT ME!\r
138      */\r
139     public boolean aboveThreshold(String s, int j)\r
140     {\r
141       if(consensus==null)\r
142         System.out.println("its null");\r
143         if ((((Integer) consensus[j].get("maxCount")).intValue() != -1) &&\r
144                 consensus[j].contains(s))\r
145         {\r
146             float ratio =  ((Float)consensus[j].get(ignoreGaps)).floatValue();\r
147 \r
148             if (ratio >= threshold)\r
149             {\r
150                 return true;\r
151             }\r
152         }\r
153 \r
154         return false;\r
155     }\r
156 }\r