last version stay many bugs ..
[jalview.git] / src / jalview / schemes / ResidueProperties.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 java.util.*;
21
22 import java.awt.*;
23
24 public class ResidueProperties
25 {
26   public static Hashtable scoreMatrices = new Hashtable();
27
28   // Stores residue codes/names and colours and other things
29   public static final int[] aaIndex; // aaHash version 2.1.1 and below
30
31   public static final int[] nucleotideIndex;
32
33   public static final int[] purinepyrimidineIndex;
34
35   public static final Hashtable aa3Hash = new Hashtable();
36
37   public static final Hashtable aa2Triplet = new Hashtable();
38
39   public static final Hashtable nucleotideName = new Hashtable();
40
41   static
42   {
43     aaIndex = new int[255];
44     for (int i = 0; i < 255; i++)
45     {
46       aaIndex[i] = 23;
47     }
48
49     aaIndex['A'] = 0;
50     aaIndex['R'] = 1;
51     aaIndex['N'] = 2;
52     aaIndex['D'] = 3;
53     aaIndex['C'] = 4;
54     aaIndex['Q'] = 5;
55     aaIndex['E'] = 6;
56     aaIndex['G'] = 7;
57     aaIndex['H'] = 8;
58     aaIndex['I'] = 9;
59     aaIndex['L'] = 10;
60     aaIndex['K'] = 11;
61     aaIndex['M'] = 12;
62     aaIndex['F'] = 13;
63     aaIndex['P'] = 14;
64     aaIndex['S'] = 15;
65     aaIndex['T'] = 16;
66     aaIndex['W'] = 17;
67     aaIndex['Y'] = 18;
68     aaIndex['V'] = 19;
69     aaIndex['B'] = 20;
70     aaIndex['Z'] = 21;
71     aaIndex['X'] = 22;
72     aaIndex['U'] = 22;
73     aaIndex['a'] = 0;
74     aaIndex['r'] = 1;
75     aaIndex['n'] = 2;
76     aaIndex['d'] = 3;
77     aaIndex['c'] = 4;
78     aaIndex['q'] = 5;
79     aaIndex['e'] = 6;
80     aaIndex['g'] = 7;
81     aaIndex['h'] = 8;
82     aaIndex['i'] = 9;
83     aaIndex['l'] = 10;
84     aaIndex['k'] = 11;
85     aaIndex['m'] = 12;
86     aaIndex['f'] = 13;
87     aaIndex['p'] = 14;
88     aaIndex['s'] = 15;
89     aaIndex['t'] = 16;
90     aaIndex['w'] = 17;
91     aaIndex['y'] = 18;
92     aaIndex['v'] = 19;
93     aaIndex['b'] = 20;
94     aaIndex['z'] = 21;
95     aaIndex['x'] = 22;
96     aaIndex['u'] = 22; // TODO: selenocystine triplet and codons needed. also
97     // extend subt. matrices
98   }
99
100   /**
101    * maximum (gap) index for matrices involving protein alphabet 
102    */
103   public final static int maxProteinIndex=23;
104   /**
105    * maximum (gap) index for matrices involving nucleotide alphabet 
106    */
107   public final static int maxNucleotideIndex=10;
108   
109   static
110   {
111     nucleotideIndex = new int[255];
112     for (int i = 0; i < 255; i++)
113     {
114       nucleotideIndex[i] = 10; // non-nucleotide symbols are all non-gap gaps.
115     }
116
117     nucleotideIndex['A'] = 0;
118     nucleotideIndex['a'] = 0;
119     nucleotideIndex['C'] = 1;
120     nucleotideIndex['c'] = 1;
121     nucleotideIndex['G'] = 2;
122     nucleotideIndex['g'] = 2;
123     nucleotideIndex['T'] = 3;
124     nucleotideIndex['t'] = 3;
125     nucleotideIndex['U'] = 4;
126     nucleotideIndex['u'] = 4;
127     nucleotideIndex['I'] = 5;
128     nucleotideIndex['i'] = 5;
129     nucleotideIndex['X'] = 6;
130     nucleotideIndex['x'] = 6;
131     nucleotideIndex['R'] = 7;
132     nucleotideIndex['r'] = 7;
133     nucleotideIndex['Y'] = 8;
134     nucleotideIndex['y'] = 8;
135     nucleotideIndex['N'] = 9;
136     nucleotideIndex['n'] = 9;
137
138     nucleotideName.put("A", "Adenine");
139     nucleotideName.put("a", "Adenine");
140     nucleotideName.put("G", "Guanine");
141     nucleotideName.put("g", "Guanine");
142     nucleotideName.put("C", "Cytosine");
143     nucleotideName.put("c", "Cytosine");
144     nucleotideName.put("T", "Thymine");
145     nucleotideName.put("t", "Thymine");
146     nucleotideName.put("U", "Uracil");
147     nucleotideName.put("u", "Uracil");
148     nucleotideName.put("I", "Inosine");
149     nucleotideName.put("i", "Inosine");
150     nucleotideName.put("X", "Xanthine");
151     nucleotideName.put("x", "Xanthine");
152     nucleotideName.put("R", "Unknown Purine");
153     nucleotideName.put("r", "Unknown Purine");
154     nucleotideName.put("Y", "Unknown Pyrimidine");
155     nucleotideName.put("y", "Unknown Pyrimidine");
156     nucleotideName.put("N", "Unknown");
157     nucleotideName.put("n", "Unknown");
158     nucleotideName.put("W", "Weak nucleotide (A or T)");
159     nucleotideName.put("w", "Weak nucleotide (A or T)");
160     nucleotideName.put("S", "Strong nucleotide (G or C)");
161     nucleotideName.put("s", "Strong nucleotide (G or C)");
162     nucleotideName.put("M", "Amino (A or C)");
163     nucleotideName.put("m", "Amino (A or C)");
164     nucleotideName.put("K", "Keto (G or T)");
165     nucleotideName.put("k", "Keto (G or T)");
166     nucleotideName.put("B", "Not A (G or C or T)");
167     nucleotideName.put("b", "Not A (G or C or T)");
168     nucleotideName.put("H", "Not G (A or C or T)");
169     nucleotideName.put("h", "Not G (A or C or T)");
170     nucleotideName.put("D", "Not C (A or G or T)");
171     nucleotideName.put("d", "Not C (A or G or T)");
172     nucleotideName.put("V", "Not T (A or G or C");
173     nucleotideName.put("v", "Not T (A or G or C");
174
175   }
176
177   static
178   {
179     purinepyrimidineIndex = new int[255];
180     for (int i = 0; i < 255; i++)
181     {
182       purinepyrimidineIndex[i] = 3; // non-nucleotide symbols are all non-gap
183       // gaps.
184     }
185
186     purinepyrimidineIndex['A'] = 0;
187     purinepyrimidineIndex['a'] = 0;
188     purinepyrimidineIndex['C'] = 1;
189     purinepyrimidineIndex['c'] = 1;
190     purinepyrimidineIndex['G'] = 0;
191     purinepyrimidineIndex['g'] = 0;
192     purinepyrimidineIndex['T'] = 1;
193     purinepyrimidineIndex['t'] = 1;
194     purinepyrimidineIndex['U'] = 1;
195     purinepyrimidineIndex['u'] = 1;
196     purinepyrimidineIndex['I'] = 2;
197     purinepyrimidineIndex['i'] = 2;
198     purinepyrimidineIndex['X'] = 2;
199     purinepyrimidineIndex['x'] = 2;
200     purinepyrimidineIndex['R'] = 0;
201     purinepyrimidineIndex['r'] = 0;
202     purinepyrimidineIndex['Y'] = 1;
203     purinepyrimidineIndex['y'] = 1;
204     purinepyrimidineIndex['N'] = 2;
205     purinepyrimidineIndex['n'] = 2;
206   }
207
208   static
209   {
210     aa3Hash.put("ALA", new Integer(0));
211     aa3Hash.put("ARG", new Integer(1));
212     aa3Hash.put("ASN", new Integer(2));
213     aa3Hash.put("ASP", new Integer(3)); // D
214     aa3Hash.put("CYS", new Integer(4));
215     aa3Hash.put("GLN", new Integer(5)); // Q
216     aa3Hash.put("GLU", new Integer(6)); // E
217     aa3Hash.put("GLY", new Integer(7));
218     aa3Hash.put("HIS", new Integer(8));
219     aa3Hash.put("ILE", new Integer(9));
220     aa3Hash.put("LEU", new Integer(10));
221     aa3Hash.put("LYS", new Integer(11));
222     aa3Hash.put("MET", new Integer(12));
223     aa3Hash.put("PHE", new Integer(13));
224     aa3Hash.put("PRO", new Integer(14));
225     aa3Hash.put("SER", new Integer(15));
226     aa3Hash.put("THR", new Integer(16));
227     aa3Hash.put("TRP", new Integer(17));
228     aa3Hash.put("TYR", new Integer(18));
229     aa3Hash.put("VAL", new Integer(19));
230     // IUB Nomenclature for ambiguous peptides
231     aa3Hash.put("ASX", new Integer(20)); // "B";
232     aa3Hash.put("GLX", new Integer(21)); // X
233     aa3Hash.put("XAA", new Integer(22)); // X unknown
234     aa3Hash.put("-", new Integer(23));
235     aa3Hash.put("*", new Integer(23));
236     aa3Hash.put(".", new Integer(23));
237     aa3Hash.put(" ", new Integer(23));
238     aa3Hash.put("Gap", new Integer(23));
239   }
240
241   static
242   {
243     aa2Triplet.put("A", "ALA");
244     aa2Triplet.put("a", "ALA");
245     aa2Triplet.put("R", "ARG");
246     aa2Triplet.put("r", "ARG");
247     aa2Triplet.put("N", "ASN");
248     aa2Triplet.put("n", "ASN");
249     aa2Triplet.put("D", "ASP");
250     aa2Triplet.put("d", "ASP");
251     aa2Triplet.put("C", "CYS");
252     aa2Triplet.put("c", "CYS");
253     aa2Triplet.put("Q", "GLN");
254     aa2Triplet.put("q", "GLN");
255     aa2Triplet.put("E", "GLU");
256     aa2Triplet.put("e", "GLU");
257     aa2Triplet.put("G", "GLY");
258     aa2Triplet.put("g", "GLY");
259     aa2Triplet.put("H", "HIS");
260     aa2Triplet.put("h", "HIS");
261     aa2Triplet.put("I", "ILE");
262     aa2Triplet.put("i", "ILE");
263     aa2Triplet.put("L", "LEU");
264     aa2Triplet.put("l", "LEU");
265     aa2Triplet.put("K", "LYS");
266     aa2Triplet.put("k", "LYS");
267     aa2Triplet.put("M", "MET");
268     aa2Triplet.put("m", "MET");
269     aa2Triplet.put("F", "PHE");
270     aa2Triplet.put("f", "PHE");
271     aa2Triplet.put("P", "PRO");
272     aa2Triplet.put("p", "PRO");
273     aa2Triplet.put("S", "SER");
274     aa2Triplet.put("s", "SER");
275     aa2Triplet.put("T", "THR");
276     aa2Triplet.put("t", "THR");
277     aa2Triplet.put("W", "TRP");
278     aa2Triplet.put("w", "TRP");
279     aa2Triplet.put("Y", "TYR");
280     aa2Triplet.put("y", "TYR");
281     aa2Triplet.put("V", "VAL");
282     aa2Triplet.put("v", "VAL");
283   }
284
285   public static final String[] aa =
286   { "A", "R", "N", "D", "C", "Q", "E", "G", "H", "I", "L", "K", "M", "F",
287       "P", "S", "T", "W", "Y", "V", "B", "Z", "X", "_", "*", ".", " " };
288
289   public static final Color midBlue = new Color(100, 100, 255);
290
291   public static final Vector scaleColours = new Vector();
292
293   static
294   {
295     scaleColours.addElement(new Color(114, 0, 147));
296     scaleColours.addElement(new Color(156, 0, 98));
297     scaleColours.addElement(new Color(190, 0, 0));
298     scaleColours.addElement(Color.red);
299     scaleColours.addElement(new Color(255, 125, 0));
300     scaleColours.addElement(Color.orange);
301     scaleColours.addElement(new Color(255, 194, 85));
302     scaleColours.addElement(Color.yellow);
303     scaleColours.addElement(new Color(255, 255, 181));
304     scaleColours.addElement(Color.white);
305   }
306
307   public static final Color[] taylor =
308   { new Color(204, 255, 0), // A Greenish-yellowy-yellow
309       new Color(0, 0, 255), // R Blueish-bluey-blue
310       new Color(204, 0, 255), // N Blueish-reddy-blue
311       new Color(255, 0, 0), // D Reddish-reddy-red
312       new Color(255, 255, 0), // C Yellowish-yellowy-yellow
313       new Color(255, 0, 204), // Q Reddish-bluey-red
314       new Color(255, 0, 102), // E Blueish-reddy-red
315       new Color(255, 153, 0), // G Yellowy-reddy-yellow
316       new Color(0, 102, 255), // H Greenish-bluey-blue
317       new Color(102, 255, 0), // I Greenish-yellowy-green
318       new Color(51, 255, 0), // L Yellowish-greeny-green
319       new Color(102, 0, 255), // K Reddish-bluey-blue
320       new Color(0, 255, 0), // M Greenish-greeny-green
321       new Color(0, 255, 102), // F Blueish-greeny-green
322       new Color(255, 204, 0), // P Reddish-yellowy-yellow
323       new Color(255, 51, 0), // S Yellowish-reddy-red
324       new Color(255, 102, 0), // T Reddish-yellowy-red
325       new Color(0, 204, 255), // W Blueish-greeny-green
326       new Color(0, 255, 204), // Y Greenish-bluey-green
327       new Color(153, 255, 0), // V Yellowish-greeny-yellow
328       Color.white, // B
329       Color.white, // Z
330       Color.white, // X
331       Color.white, // -
332       Color.white, // *
333       Color.white // .
334   };
335
336   public static final Color[] nucleotide =
337   { new Color(100, 247, 63), // A
338       new Color(255, 179, 64), // C
339       new Color(235, 65, 60), // G
340       new Color(60, 136, 238), // T
341       new Color(60, 136, 238), // U
342       Color.white, // I (inosine)
343       Color.white, // X (xanthine)
344       Color.white, // R
345       Color.white, // Y
346       Color.white, // N
347       Color.white, // Gap
348   };
349
350   // Added for PurinePyrimidineColourScheme
351   public static final Color[] purinepyrimidine =
352   { new Color(255, 131, 250), // A, G, R purines purplish/orchid
353       new Color(64, 224, 208), // C,U, T, Y pyrimidines turquoise
354       Color.white, // all other nucleotides
355       Color.white // Gap
356   };
357
358   // Zappo
359   public static final Color[] zappo =
360   { Color.pink, // A
361       midBlue, // R
362       Color.green, // N
363       Color.red, // D
364       Color.yellow, // C
365       Color.green, // Q
366       Color.red, // E
367       Color.magenta, // G
368       midBlue,// Color.red, // H
369       Color.pink, // I
370       Color.pink, // L
371       midBlue, // K
372       Color.pink, // M
373       Color.orange, // F
374       Color.magenta, // P
375       Color.green, // S
376       Color.green, // T
377       Color.orange, // W
378       Color.orange, // Y
379       Color.pink, // V
380       Color.white, // B
381       Color.white, // Z
382       Color.white, // X
383       Color.white, // -
384       Color.white, // *
385       Color.white, // .
386       Color.white // ' '
387   };
388
389   // Dunno where I got these numbers from
390   public static final double[] hyd2 =
391   { 0.62, // A
392       0.29, // R
393       -0.90, // N
394       -0.74, // D
395       1.19, // C
396       0.48, // Q
397       -0.40, // E
398       1.38, // G
399       -1.50, // H
400       1.06, // I
401       0.64, // L
402       -0.78, // K
403       0.12, // M
404       -0.85, // F
405       -2.53, // P
406       -0.18, // S
407       -0.05, // T
408       1.08, // W
409       0.81, // Y
410       0.0, // V
411       0.26, // B
412       0.0, // Z
413       0.0 // X
414   };
415
416   public static final double[] helix =
417   { 1.42, 0.98, 0.67, 1.01, 0.70, 1.11, 1.51, 0.57, 1.00, 1.08, 1.21, 1.16,
418       1.45, 1.13, 0.57, 0.77, 0.83, 1.08, 0.69, 1.06, 0.84, 1.31, 1.00, 0.0 };
419
420   public static final double helixmin = 0.57;
421
422   public static final double helixmax = 1.51;
423
424   public static final double[] strand =
425   { 0.83, 0.93, 0.89, 0.54, 1.19, 1.10, 0.37, 0.75, 0.87, 1.60, 1.30, 0.74,
426       1.05, 1.38, 0.55, 0.75, 1.19, 1.37, 1.47, 1.70, 0.72, 0.74, 1.0, 0.0 };
427
428   public static final double strandmin = 0.37;
429
430   public static final double strandmax = 1.7;
431
432   public static final double[] turn =
433   { 0.66, 0.95, 1.56, 1.46, 1.19, 0.98, 0.74, 1.56, 0.95, 0.47, 0.59, 1.01,
434       0.60, 0.60, 1.52, 1.43, 0.96, 0.96, 1.14, 0.50, 1.51, 0.86, 1.00, 0,
435       0 };
436
437   public static final double turnmin = 0.47;
438
439   public static final double turnmax = 1.56;
440
441   public static final double[] buried =
442   { 1.7, 0.1, 0.4, 0.4, 4.6, 0.3, 0.3, 1.8, 0.8, 3.1, 2.4, 0.05, 1.9, 2.2,
443       0.6, 0.8, 0.7, 1.6, 0.5, 2.9, 0.4, 0.3, 1.358, 0.00 };
444
445   public static final double buriedmin = 0.05;
446
447   public static final double buriedmax = 4.6;
448
449   // This is hydropathy index
450   // Kyte, J., and Doolittle, R.F., J. Mol. Biol.
451   // 1157, 105-132, 1982
452   public static final double[] hyd =
453   { 1.8, -4.5, -3.5, -3.5, 2.5, -3.5, -3.5, -0.4, -3.2, 4.5, 3.8, -3.9,
454       1.9, 2.8, -1.6, -0.8, -0.7, -0.9, -1.3, 4.2, -3.5, -3.5, -0.49, 0.0 };
455
456   public static final double hydmax = 4.5;
457
458   public static final double hydmin = -3.9;
459
460   // public static final double hydmax = 1.38;
461   // public static final double hydmin = -2.53;
462   private static final int[][] BLOSUM62 =
463   {
464       { 4, -1, -2, -2, 0, -1, -1, 0, -2, -1, -1, -1, -1, -2, -1, 1, 0, -3,
465           -2, 0, -2, -1, 0, -4 },
466       { -1, 5, 0, -2, -3, 1, 0, -2, 0, -3, -2, 2, -1, -3, -2, -1, -1, -3,
467           -2, -3, -1, 0, -1, -4 },
468       { -2, 0, 6, 1, -3, 0, 0, 0, 1, -3, -3, 0, -2, -3, -2, 1, 0, -4, -2,
469           -3, 3, 0, -1, -4 },
470       { -2, -2, 1, 6, -3, 0, 2, -1, -1, -3, -4, -1, -3, -3, -1, 0, -1, -4,
471           -3, -3, 4, 1, -1, -4 },
472       { 0, 3, -3, -3, 9, -3, -4, -3, -3, -1, -1, -3, -1, -2, -3, -1, -1,
473           -2, -2, -1, -3, -3, -2, -4 },
474       { -1, 1, 0, 0, -3, 5, 2, -2, 0, -3, -2, 1, 0, -3, -1, 0, -1, -2, -1,
475           -2, 0, 3, -1, -4 },
476       { -1, 0, 0, 2, -4, 2, 5, -2, 0, -3, -3, 1, -2, -3, -1, 0, -1, -3, -2,
477           -2, 1, 4, -1, -4 },
478       { 0, -2, 0, -1, -3, -2, -2, 6, -2, -4, -4, -2, -3, -3, -2, 0, -2, -2,
479           -3, -3, -1, -2, -1, -4 },
480       { -2, 0, 1, -1, -3, 0, 0, -2, 8, -3, -3, -1, -2, -1, -2, -1, -2, -2,
481           2, -3, 0, 0, -1, -4 },
482       { -1, -3, -3, -3, -1, -3, -3, -4, -3, 4, 2, -3, 1, 0, -3, -2, -1, -3,
483           -1, 3, -3, -3, -1, -4 },
484       { -1, -2, -3, -4, -1, -2, -3, -4, -3, 2, 4, -2, 2, 0, -3, -2, -1, -2,
485           -1, 1, -4, -3, -1, -4 },
486       { -1, 2, 0, -1, -3, 1, 1, -2, -1, -3, -2, 5, -1, -3, -1, 0, -1, -3,
487           -2, -2, 0, 1, -1, -4 },
488       { -1, -1, -2, -3, -1, 0, -2, -3, -2, 1, 2, -1, 5, 0, -2, -1, -1, -1,
489           -1, 1, -3, -1, -1, -4 },
490       { -2, -3, -3, -3, -2, -3, -3, -3, -1, 0, 0, -3, 0, 6, -4, -2, -2, 1,
491           3, -1, -3, -3, -1, -4 },
492       { -1, -2, -2, -1, -3, -1, -1, -2, -2, -3, -3, -1, -2, -4, 7, -1, -1,
493           -4, -3, -2, -2, -1, -2, -4 },
494       { 1, -1, 1, 0, -1, 0, 0, 0, -1, -2, -2, 0, -1, -2, -1, 4, 1, -3, -2,
495           -2, 0, 0, 0, -4 },
496       { 0, -1, 0, -1, -1, -1, -1, -2, -2, -1, -1, -1, -1, -2, -1, 1, 5, -2,
497           -2, 0, -1, -1, 0, -4 },
498       { -3, -3, -4, -4, -2, -2, -3, -2, -2, -3, -2, -3, -1, 1, -4, -3, -2,
499           11, 2, -3, -4, -3, -2, -4 },
500       { -2, -2, -2, -3, -2, -1, -2, -3, 2, -1, -1, -2, -1, 3, -3, -2, -2,
501           2, 7, -1, -3, -2, -1, -4 },
502       { 0, -3, -3, -3, -1, -2, -2, -3, -3, 3, 1, -2, 1, -1, -2, -2, 0, -3,
503           -1, 4, -3, -2, -1, -4 },
504       { -2, -1, 3, 4, -3, 0, 1, -1, 0, -3, -4, 0, -3, -3, -2, 0, -1, -4,
505           -3, -3, 4, 1, -1, -4 },
506       { -1, 0, 0, 1, -3, 3, 4, -2, 0, -3, -3, 1, -1, -3, -1, 0, -1, -3, -2,
507           -2, 1, 4, -1, -4 },
508       { 0, -1, -1, -1, -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -2, 0, 0,
509           -2, -1, -1, -1, -1, -1, -4 },
510       { -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4,
511           -4, -4, -4, -4, -4, -4, 1 }, };
512
513   static final int[][] PAM250 =
514   {
515       { 2, -2, 0, 0, -2, 0, 0, 1, -1, -1, -2, -1, -1, -3, 1, 1, 1, -6, -3,
516           0, 0, 0, 0, -8 },
517       { -2, 6, 0, -1, -4, 1, -1, -3, 2, -2, -3, 3, 0, -4, 0, 0, -1, 2, -4,
518           -2, -1, 0, -1, -8 },
519       { 0, 0, 2, 2, -4, 1, 1, 0, 2, -2, -3, 1, -2, -3, 0, 1, 0, -4, -2, -2,
520           2, 1, 0, -8 },
521       { 0, -1, 2, 4, -5, 2, 3, 1, 1, -2, -4, 0, -3, -6, -1, 0, 0, -7, -4,
522           -2, 3, 3, -1, -8 },
523       { -2, -4, -4, -5, 12, -5, -5, -3, -3, -2, -6, -5, -5, -4, -3, 0, -2,
524           -8, 0, -2, -4, -5, -3, -8 },
525       { 0, 1, 1, 2, -5, 4, 2, -1, 3, -2, -2, 1, -1, -5, 0, -1, -1, -5, -4,
526           -2, 1, 3, -1, -8 },
527       { 0, -1, 1, 3, -5, 2, 4, 0, 1, -2, -3, 0, -2, -5, -1, 0, 0, -7, -4,
528           -2, 3, 3, -1, -8 },
529       { 1, -3, 0, 1, -3, -1, 0, 5, -2, -3, -4, -2, -3, -5, 0, 1, 0, -7, -5,
530           -1, 0, 0, -1, -8 },
531       { -1, 2, 2, 1, -3, 3, 1, -2, 6, -2, -2, 0, -2, -2, 0, -1, -1, -3, 0,
532           -2, 1, 2, -1, -8 },
533       { -1, -2, -2, -2, -2, -2, -2, -3, -2, 5, 2, -2, 2, 1, -2, -1, 0, -5,
534           -1, 4, -2, -2, -1, -8 },
535       { -2, -3, -3, -4, -6, -2, -3, -4, -2, 2, 6, -3, 4, 2, -3, -3, -2, -2,
536           -1, 2, -3, -3, -1, -8 },
537       { -1, 3, 1, 0, -5, 1, 0, -2, 0, -2, -3, 5, 0, -5, -1, 0, 0, -3, -4,
538           -2, 1, 0, -1, -8 },
539       { -1, 0, -2, -3, -5, -1, -2, -3, -2, 2, 4, 0, 6, 0, -2, -2, -1, -4,
540           -2, 2, -2, -2, -1, -8 },
541       { -3, -4, -3, -6, -4, -5, -5, -5, -2, 1, 2, -5, 0, 9, -5, -3, -3, 0,
542           7, -1, -4, -5, -2, -8 },
543       { 1, 0, 0, -1, -3, 0, -1, 0, 0, -2, -3, -1, -2, -5, 6, 1, 0, -6, -5,
544           -1, -1, 0, -1, -8 },
545       { 1, 0, 1, 0, 0, -1, 0, 1, -1, -1, -3, 0, -2, -3, 1, 2, 1, -2, -3,
546           -1, 0, 0, 0, -8 },
547       { 1, -1, 0, 0, -2, -1, 0, 0, -1, 0, -2, 0, -1, -3, 0, 1, 3, -5, -3,
548           0, 0, -1, 0, -8 },
549       { -6, 2, -4, -7, -8, -5, -7, -7, -3, -5, -2, -3, -4, 0, -6, -2, -5,
550           17, 0, -6, -5, -6, -4, -8 },
551       { -3, -4, -2, -4, 0, -4, -4, -5, 0, -1, -1, -4, -2, 7, -5, -3, -3, 0,
552           10, -2, -3, -4, -2, -8 },
553       { 0, -2, -2, -2, -2, -2, -2, -1, -2, 4, 2, -2, 2, -1, -1, -1, 0, -6,
554           -2, 4, -2, -2, -1, -8 },
555       { 0, -1, 2, 3, -4, 1, 3, 0, 1, -2, -3, 1, -2, -4, -1, 0, 0, -5, -3,
556           -2, 3, 2, -1, -8 },
557       { 0, 0, 1, 3, -5, 3, 3, 0, 2, -2, -3, 0, -2, -5, 0, 0, -1, -6, -4,
558           -2, 2, 3, -1, -8 },
559       { 0, -1, 0, -1, -3, -1, -1, -1, -1, -1, -1, -1, -1, -2, -1, 0, 0, -4,
560           -2, -1, -1, -1, -1, -8 },
561       { -8, -8, -8, -8, -8, -8, -8, -8, -8, -8, -8, -8, -8, -8, -8, -8, -8,
562           -8, -8, -8, -8, -8, -8, 1 }, };
563
564   public static final Hashtable ssHash = new Hashtable(); // stores the number
565   // value of the aa
566
567   static
568   {
569     ssHash.put("H", Color.magenta);
570     ssHash.put("E", Color.yellow);
571     ssHash.put("-", Color.white);
572     ssHash.put(".", Color.white);
573     ssHash.put("S", Color.cyan);
574     ssHash.put("T", Color.blue);
575     ssHash.put("G", Color.pink);
576     ssHash.put("I", Color.pink);
577     ssHash.put("B", Color.yellow);
578   }
579
580   /*
581    * new Color(60, 136, 238), // U Color.white, // I Color.white, // X
582    * Color.white, // R Color.white, // Y Color.white, // N Color.white, // Gap
583    */
584
585   // JBPNote: patch matrix for T/U equivalence when working with DNA or RNA.
586   // Will equate sequences if working with mixed nucleotide sets.
587   // treats T and U identically. R and Y weak equivalence with AG and CTU.
588   // N matches any other base weakly
589   // 
590   static final int[][] DNA =
591   {
592       { 10, -8, -8, -8, -8, 1,  1, -8,  1,  1, 1 }, // C
593       { -8, 10, -8, -8, 10, 1,  1, -8,  1,  1, 1 }, // T
594       { -8, -8, 10, -8, -8, 1,  1,  1, -8,  1, 1 }, // A
595       { -8, -8, -8, 10, -8, 1,  1,  1, -8,  1, 1 }, // G
596       { -8, 10, -8, -8, 10, 1,  1, -8,  1,  1, 1 }, // U
597       {  1,  1,  1,  1,  1, 10, 0,  0,  0,  1, 1 }, // I
598       {  1,  1,  1,  1,  1, 0, 10,  0,  0,  1, 1 }, // X
599       { -8, -8,  1,  1, -8, 0,  0, 10,  0,  1, 1 }, // R
600       {  1,  1, -8, -8,  1, 0,  0,  0, 10,  1, 1 }, // Y
601       {  1,  1,  1,  1,  1, 1,  1,  1,  1, 10, 1 }, // N
602       {  1,  1,  1,  1,  1, 1,  1,  1,  1,  1, 1 }, // -
603   };
604 /**
605    * register matrices in list
606    */
607   static
608   {
609     scoreMatrices.put("BLOSUM62", new ScoreMatrix("BLOSUM62", BLOSUM62, 0));
610     scoreMatrices.put("PAM250", new ScoreMatrix("PAM250", PAM250, 0));
611     scoreMatrices.put("DNA", new ScoreMatrix("DNA", DNA, 1));
612     
613   }
614
615   public static final Color[] pidColours =
616   { midBlue, new Color(153, 153, 255),
617       // Color.lightGray,
618       new Color(204, 204, 255), };
619
620   public static final float[] pidThresholds =
621   { 80, 60, 40, };
622
623   public static Hashtable codonHash = new Hashtable();
624
625   public static Vector Lys = new Vector();
626
627   public static Vector Asn = new Vector();
628
629   public static Vector Gln = new Vector();
630
631   public static Vector His = new Vector();
632
633   public static Vector Glu = new Vector();
634
635   public static Vector Asp = new Vector();
636
637   public static Vector Tyr = new Vector();
638
639   public static Vector Thr = new Vector();
640
641   public static Vector Pro = new Vector();
642
643   public static Vector Ala = new Vector();
644
645   public static Vector Ser = new Vector();
646
647   public static Vector Arg = new Vector();
648
649   public static Vector Gly = new Vector();
650
651   public static Vector Trp = new Vector();
652
653   public static Vector Cys = new Vector();
654
655   public static Vector Ile = new Vector();
656
657   public static Vector Met = new Vector();
658
659   public static Vector Leu = new Vector();
660
661   public static Vector Val = new Vector();
662
663   public static Vector Phe = new Vector();
664
665   public static Vector STOP = new Vector();
666
667   static
668   {
669     codonHash.put("K", Lys);
670     codonHash.put("N", Asn);
671     codonHash.put("Q", Gln);
672     codonHash.put("H", His);
673     codonHash.put("E", Glu);
674     codonHash.put("D", Asp);
675     codonHash.put("Y", Tyr);
676     codonHash.put("T", Thr);
677     codonHash.put("P", Pro);
678     codonHash.put("A", Ala);
679     codonHash.put("S", Ser);
680     codonHash.put("R", Arg);
681     codonHash.put("G", Gly);
682     codonHash.put("W", Trp);
683     codonHash.put("C", Cys);
684     codonHash.put("I", Ile);
685     codonHash.put("M", Met);
686     codonHash.put("L", Leu);
687     codonHash.put("V", Val);
688     codonHash.put("F", Phe);
689     codonHash.put("STOP", STOP);
690   }
691
692   public static Hashtable codonHash2 = new Hashtable();
693
694   static
695   {
696     codonHash2.put("AAA", "K");
697     codonHash2.put("AAG", "K");
698     codonHash2.put("AAC", "N");
699     codonHash2.put("AAT", "N");
700
701     codonHash2.put("CAA", "E");
702     codonHash2.put("CAG", "E");
703     codonHash2.put("CAC", "H");
704     codonHash2.put("CAT", "H");
705
706     codonHash2.put("GAA", "Q");
707     codonHash2.put("GAG", "Q");
708     codonHash2.put("GAC", "D");
709     codonHash2.put("GAT", "D");
710
711     codonHash2.put("TAC", "Y");
712     codonHash2.put("TAT", "Y");
713
714     codonHash2.put("ACA", "T");
715     codonHash2.put("AAG", "T");
716     codonHash2.put("ACC", "T");
717     codonHash2.put("ACT", "T");
718
719     codonHash2.put("CCA", "P");
720     codonHash2.put("CCG", "P");
721     codonHash2.put("CCC", "P");
722     codonHash2.put("CCT", "P");
723
724     codonHash2.put("GCA", "A");
725     codonHash2.put("GCG", "A");
726     codonHash2.put("GCC", "A");
727     codonHash2.put("GCT", "A");
728
729     codonHash2.put("TCA", "S");
730     codonHash2.put("TCG", "S");
731     codonHash2.put("TCC", "S");
732     codonHash2.put("TCT", "S");
733     codonHash2.put("AGC", "S");
734     codonHash2.put("AGT", "S");
735
736     codonHash2.put("AGA", "R");
737     codonHash2.put("AGG", "R");
738     codonHash2.put("CGA", "R");
739     codonHash2.put("CGG", "R");
740     codonHash2.put("CGC", "R");
741     codonHash2.put("CGT", "R");
742
743     codonHash2.put("GGA", "G");
744     codonHash2.put("GGG", "G");
745     codonHash2.put("GGC", "G");
746     codonHash2.put("GGT", "G");
747
748     codonHash2.put("TGA", "*");
749     codonHash2.put("TAA", "*");
750     codonHash2.put("TAG", "*");
751
752     codonHash2.put("TGG", "W");
753
754     codonHash2.put("TGC", "C");
755     codonHash2.put("TGT", "C");
756
757     codonHash2.put("ATA", "I");
758     codonHash2.put("ATC", "I");
759     codonHash2.put("ATT", "I");
760
761     codonHash2.put("ATG", "M");
762
763     codonHash2.put("CTA", "L");
764     codonHash2.put("CTG", "L");
765     codonHash2.put("CTC", "L");
766     codonHash2.put("CTT", "L");
767     codonHash2.put("TTA", "L");
768     codonHash2.put("TTG", "L");
769
770     codonHash2.put("GTA", "V");
771     codonHash2.put("GTG", "V");
772     codonHash2.put("GTC", "V");
773     codonHash2.put("GTT", "V");
774
775     codonHash2.put("TTC", "F");
776     codonHash2.put("TTT", "F");
777   }
778
779   static
780   {
781     Lys.addElement("AAA");
782     Lys.addElement("AAG");
783     Asn.addElement("AAC");
784     Asn.addElement("AAT");
785
786     Gln.addElement("CAA");
787     Gln.addElement("CAG");
788     His.addElement("CAC");
789     His.addElement("CAT");
790
791     Glu.addElement("GAA");
792     Glu.addElement("GAG");
793     Asp.addElement("GAC");
794     Asp.addElement("GAT");
795
796     Tyr.addElement("TAC");
797     Tyr.addElement("TAT");
798
799     Thr.addElement("ACA");
800     Thr.addElement("ACG");
801     Thr.addElement("ACC");
802     Thr.addElement("ACT");
803
804     Pro.addElement("CCA");
805     Pro.addElement("CCG");
806     Pro.addElement("CCC");
807     Pro.addElement("CCT");
808
809     Ala.addElement("GCA");
810     Ala.addElement("GCG");
811     Ala.addElement("GCC");
812     Ala.addElement("GCT");
813
814     Ser.addElement("TCA");
815     Ser.addElement("TCG");
816     Ser.addElement("TCC");
817     Ser.addElement("TCT");
818     Ser.addElement("AGC");
819     Ser.addElement("AGT");
820
821     Arg.addElement("AGA");
822     Arg.addElement("AGG");
823     Arg.addElement("CGA");
824     Arg.addElement("CGG");
825     Arg.addElement("CGC");
826     Arg.addElement("CGT");
827
828     Gly.addElement("GGA");
829     Gly.addElement("GGG");
830     Gly.addElement("GGC");
831     Gly.addElement("GGT");
832
833     STOP.addElement("TGA");
834     STOP.addElement("TAA");
835     STOP.addElement("TAG");
836
837     Trp.addElement("TGG");
838
839     Cys.addElement("TGC");
840     Cys.addElement("TGT");
841
842     Ile.addElement("ATA");
843     Ile.addElement("ATC");
844     Ile.addElement("ATT");
845
846     Met.addElement("ATG");
847
848     Leu.addElement("CTA");
849     Leu.addElement("CTG");
850     Leu.addElement("CTC");
851     Leu.addElement("CTT");
852     Leu.addElement("TTA");
853     Leu.addElement("TTG");
854
855     Val.addElement("GTA");
856     Val.addElement("GTG");
857     Val.addElement("GTC");
858     Val.addElement("GTT");
859
860     Phe.addElement("TTC");
861     Phe.addElement("TTT");
862   }
863
864   // Stores residue codes/names and colours and other things
865   public static Hashtable propHash = new Hashtable();
866
867   public static Hashtable hydrophobic = new Hashtable();
868
869   public static Hashtable polar = new Hashtable();
870
871   public static Hashtable small = new Hashtable();
872
873   public static Hashtable positive = new Hashtable();
874
875   public static Hashtable negative = new Hashtable();
876
877   public static Hashtable charged = new Hashtable();
878
879   public static Hashtable aromatic = new Hashtable();
880
881   public static Hashtable aliphatic = new Hashtable();
882
883   public static Hashtable tiny = new Hashtable();
884
885   public static Hashtable proline = new Hashtable();
886
887   static
888   {
889     hydrophobic.put("I", new Integer(1));
890     hydrophobic.put("L", new Integer(1));
891     hydrophobic.put("V", new Integer(1));
892     hydrophobic.put("C", new Integer(1));
893     hydrophobic.put("A", new Integer(1));
894     hydrophobic.put("G", new Integer(1));
895     hydrophobic.put("M", new Integer(1));
896     hydrophobic.put("F", new Integer(1));
897     hydrophobic.put("Y", new Integer(1));
898     hydrophobic.put("W", new Integer(1));
899     hydrophobic.put("H", new Integer(1));
900     hydrophobic.put("K", new Integer(1));
901     hydrophobic.put("X", new Integer(1));
902     hydrophobic.put("-", new Integer(1));
903     hydrophobic.put("*", new Integer(1));
904     hydrophobic.put("R", new Integer(0));
905     hydrophobic.put("E", new Integer(0));
906     hydrophobic.put("Q", new Integer(0));
907     hydrophobic.put("D", new Integer(0));
908     hydrophobic.put("N", new Integer(0));
909     hydrophobic.put("S", new Integer(0));
910     hydrophobic.put("T", new Integer(0));
911     hydrophobic.put("P", new Integer(0));
912   }
913
914   static
915   {
916     polar.put("Y", new Integer(1));
917     polar.put("W", new Integer(1));
918     polar.put("H", new Integer(1));
919     polar.put("K", new Integer(1));
920     polar.put("R", new Integer(1));
921     polar.put("E", new Integer(1));
922     polar.put("Q", new Integer(1));
923     polar.put("D", new Integer(1));
924     polar.put("N", new Integer(1));
925     polar.put("S", new Integer(1));
926     polar.put("T", new Integer(1));
927     polar.put("X", new Integer(1));
928     polar.put("-", new Integer(1));
929     polar.put("*", new Integer(1));
930     polar.put("I", new Integer(0));
931     polar.put("L", new Integer(0));
932     polar.put("V", new Integer(0));
933     polar.put("C", new Integer(0));
934     polar.put("A", new Integer(0));
935     polar.put("G", new Integer(0));
936     polar.put("M", new Integer(0));
937     polar.put("F", new Integer(0));
938     polar.put("P", new Integer(0));
939   }
940
941   static
942   {
943     small.put("I", new Integer(0));
944     small.put("L", new Integer(0));
945     small.put("V", new Integer(1));
946     small.put("C", new Integer(1));
947     small.put("A", new Integer(1));
948     small.put("G", new Integer(1));
949     small.put("M", new Integer(0));
950     small.put("F", new Integer(0));
951     small.put("Y", new Integer(0));
952     small.put("W", new Integer(0));
953     small.put("H", new Integer(0));
954     small.put("K", new Integer(0));
955     small.put("R", new Integer(0));
956     small.put("E", new Integer(0));
957     small.put("Q", new Integer(0));
958     small.put("D", new Integer(1));
959     small.put("N", new Integer(1));
960     small.put("S", new Integer(1));
961     small.put("T", new Integer(1));
962     small.put("P", new Integer(1));
963     small.put("-", new Integer(1));
964     small.put("*", new Integer(1));
965   }
966
967   static
968   {
969     positive.put("I", new Integer(0));
970     positive.put("L", new Integer(0));
971     positive.put("V", new Integer(0));
972     positive.put("C", new Integer(0));
973     positive.put("A", new Integer(0));
974     positive.put("G", new Integer(0));
975     positive.put("M", new Integer(0));
976     positive.put("F", new Integer(0));
977     positive.put("Y", new Integer(0));
978     positive.put("W", new Integer(0));
979     positive.put("H", new Integer(1));
980     positive.put("K", new Integer(1));
981     positive.put("R", new Integer(1));
982     positive.put("E", new Integer(0));
983     positive.put("Q", new Integer(0));
984     positive.put("D", new Integer(0));
985     positive.put("N", new Integer(0));
986     positive.put("S", new Integer(0));
987     positive.put("T", new Integer(0));
988     positive.put("P", new Integer(0));
989     positive.put("-", new Integer(1));
990     positive.put("*", new Integer(1));
991   }
992
993   static
994   {
995     negative.put("I", new Integer(0));
996     negative.put("L", new Integer(0));
997     negative.put("V", new Integer(0));
998     negative.put("C", new Integer(0));
999     negative.put("A", new Integer(0));
1000     negative.put("G", new Integer(0));
1001     negative.put("M", new Integer(0));
1002     negative.put("F", new Integer(0));
1003     negative.put("Y", new Integer(0));
1004     negative.put("W", new Integer(0));
1005     negative.put("H", new Integer(0));
1006     negative.put("K", new Integer(0));
1007     negative.put("R", new Integer(0));
1008     negative.put("E", new Integer(1));
1009     negative.put("Q", new Integer(0));
1010     negative.put("D", new Integer(1));
1011     negative.put("N", new Integer(0));
1012     negative.put("S", new Integer(0));
1013     negative.put("T", new Integer(0));
1014     negative.put("P", new Integer(0));
1015     negative.put("-", new Integer(1));
1016     negative.put("*", new Integer(1));
1017   }
1018
1019   static
1020   {
1021     charged.put("I", new Integer(0));
1022     charged.put("L", new Integer(0));
1023     charged.put("V", new Integer(0));
1024     charged.put("C", new Integer(0));
1025     charged.put("A", new Integer(0));
1026     charged.put("G", new Integer(0));
1027     charged.put("M", new Integer(0));
1028     charged.put("F", new Integer(0));
1029     charged.put("Y", new Integer(0));
1030     charged.put("W", new Integer(0));
1031     charged.put("H", new Integer(1));
1032     charged.put("K", new Integer(1));
1033     charged.put("R", new Integer(1));
1034     charged.put("E", new Integer(1));
1035     charged.put("Q", new Integer(0));
1036     charged.put("D", new Integer(1));
1037     charged.put("N", new Integer(0)); // Asparagine is polar but not charged.
1038                                       // Alternative would be charged and
1039                                       // negative (in basic form)?
1040     charged.put("S", new Integer(0));
1041     charged.put("T", new Integer(0));
1042     charged.put("P", new Integer(0));
1043     charged.put("-", new Integer(1));
1044     charged.put("*", new Integer(1));
1045   }
1046
1047   static
1048   {
1049     aromatic.put("I", new Integer(0));
1050     aromatic.put("L", new Integer(0));
1051     aromatic.put("V", new Integer(0));
1052     aromatic.put("C", new Integer(0));
1053     aromatic.put("A", new Integer(0));
1054     aromatic.put("G", new Integer(0));
1055     aromatic.put("M", new Integer(0));
1056     aromatic.put("F", new Integer(1));
1057     aromatic.put("Y", new Integer(1));
1058     aromatic.put("W", new Integer(1));
1059     aromatic.put("H", new Integer(1));
1060     aromatic.put("K", new Integer(0));
1061     aromatic.put("R", new Integer(0));
1062     aromatic.put("E", new Integer(0));
1063     aromatic.put("Q", new Integer(0));
1064     aromatic.put("D", new Integer(0));
1065     aromatic.put("N", new Integer(0));
1066     aromatic.put("S", new Integer(0));
1067     aromatic.put("T", new Integer(0));
1068     aromatic.put("P", new Integer(0));
1069     aromatic.put("-", new Integer(1));
1070     aromatic.put("*", new Integer(1));
1071   }
1072
1073   static
1074   {
1075     aliphatic.put("I", new Integer(1));
1076     aliphatic.put("L", new Integer(1));
1077     aliphatic.put("V", new Integer(1));
1078     aliphatic.put("C", new Integer(0));
1079     aliphatic.put("A", new Integer(0));
1080     aliphatic.put("G", new Integer(0));
1081     aliphatic.put("M", new Integer(0));
1082     aliphatic.put("F", new Integer(0));
1083     aliphatic.put("Y", new Integer(0));
1084     aliphatic.put("W", new Integer(0));
1085     aliphatic.put("H", new Integer(0));
1086     aliphatic.put("K", new Integer(0));
1087     aliphatic.put("R", new Integer(0));
1088     aliphatic.put("E", new Integer(0));
1089     aliphatic.put("Q", new Integer(0));
1090     aliphatic.put("D", new Integer(0));
1091     aliphatic.put("N", new Integer(0));
1092     aliphatic.put("S", new Integer(0));
1093     aliphatic.put("T", new Integer(0));
1094     aliphatic.put("P", new Integer(0));
1095     aliphatic.put("-", new Integer(1));
1096     aliphatic.put("*", new Integer(1));
1097   }
1098
1099   static
1100   {
1101     tiny.put("I", new Integer(0));
1102     tiny.put("L", new Integer(0));
1103     tiny.put("V", new Integer(0));
1104     tiny.put("C", new Integer(0));
1105     tiny.put("A", new Integer(1));
1106     tiny.put("G", new Integer(1));
1107     tiny.put("M", new Integer(0));
1108     tiny.put("F", new Integer(0));
1109     tiny.put("Y", new Integer(0));
1110     tiny.put("W", new Integer(0));
1111     tiny.put("H", new Integer(0));
1112     tiny.put("K", new Integer(0));
1113     tiny.put("R", new Integer(0));
1114     tiny.put("E", new Integer(0));
1115     tiny.put("Q", new Integer(0));
1116     tiny.put("D", new Integer(0));
1117     tiny.put("N", new Integer(0));
1118     tiny.put("S", new Integer(1));
1119     tiny.put("T", new Integer(0));
1120     tiny.put("P", new Integer(0));
1121     tiny.put("-", new Integer(1));
1122     tiny.put("*", new Integer(1));
1123   }
1124
1125   static
1126   {
1127     proline.put("I", new Integer(0));
1128     proline.put("L", new Integer(0));
1129     proline.put("V", new Integer(0));
1130     proline.put("C", new Integer(0));
1131     proline.put("A", new Integer(0));
1132     proline.put("G", new Integer(0));
1133     proline.put("M", new Integer(0));
1134     proline.put("F", new Integer(0));
1135     proline.put("Y", new Integer(0));
1136     proline.put("W", new Integer(0));
1137     proline.put("H", new Integer(0));
1138     proline.put("K", new Integer(0));
1139     proline.put("R", new Integer(0));
1140     proline.put("E", new Integer(0));
1141     proline.put("Q", new Integer(0));
1142     proline.put("D", new Integer(0));
1143     proline.put("N", new Integer(0));
1144     proline.put("S", new Integer(0));
1145     proline.put("T", new Integer(0));
1146     proline.put("P", new Integer(1));
1147     proline.put("-", new Integer(1));
1148     proline.put("*", new Integer(1));
1149   }
1150
1151   static
1152   {
1153     propHash.put("hydrophobic", hydrophobic);
1154     propHash.put("small", small);
1155     propHash.put("positive", positive);
1156     propHash.put("negative", negative);
1157     propHash.put("charged", charged);
1158     propHash.put("aromatic", aromatic);
1159     propHash.put("aliphatic", aliphatic);
1160     propHash.put("tiny", tiny);
1161     propHash.put("proline", proline);
1162     propHash.put("polar", polar);
1163   }
1164
1165   private ResidueProperties()
1166   {
1167   }
1168
1169   public static double getHydmax()
1170   {
1171     return hydmax;
1172   }
1173
1174   public static double getHydmin()
1175   {
1176     return hydmin;
1177   }
1178
1179   public static double[] getHyd()
1180   {
1181     return hyd;
1182   }
1183
1184   public static Hashtable getAA3Hash()
1185   {
1186     return aa3Hash;
1187   }
1188
1189   public static int[][] getDNA()
1190   {
1191     return ResidueProperties.DNA;
1192   }
1193
1194   public static int[][] getBLOSUM62()
1195   {
1196     return ResidueProperties.BLOSUM62;
1197   }
1198
1199   public static int getPAM250(String A1, String A2)
1200   {
1201     return getPAM250(A1.charAt(0), A2.charAt(0));
1202   }
1203
1204   public static int getBLOSUM62(char c1, char c2)
1205   {
1206     int pog = 0;
1207
1208     try
1209     {
1210       int a = aaIndex[c1];
1211       int b = aaIndex[c2];
1212
1213       pog = ResidueProperties.BLOSUM62[a][b];
1214     } catch (Exception e)
1215     {
1216       // System.out.println("Unknown residue in " + A1 + " " + A2);
1217     }
1218
1219     return pog;
1220   }
1221
1222   public static Vector getCodons(String res)
1223   {
1224     if (codonHash.containsKey(res))
1225     {
1226       return (Vector) codonHash.get(res);
1227     }
1228
1229     return null;
1230   }
1231
1232   public static String codonTranslate(String lccodon)
1233   {
1234     String codon = lccodon.toUpperCase();
1235     // all base ambiguity codes yield an 'X' amino acid residue
1236     if (codon.indexOf('X') > -1 || codon.indexOf('N') > -1)
1237     {
1238       return "X";
1239     }
1240     Enumeration e = codonHash.keys();
1241
1242     while (e.hasMoreElements())
1243     {
1244       String key = (String) e.nextElement();
1245       Vector tmp = (Vector) codonHash.get(key);
1246
1247       if (tmp.contains(codon))
1248       {
1249         return key;
1250       }
1251     }
1252
1253     return null;
1254   }
1255
1256   public static int[][] getDefaultPeptideMatrix()
1257   {
1258     return ResidueProperties.getBLOSUM62();
1259   }
1260
1261   public static int[][] getDefaultDnaMatrix()
1262   {
1263     return ResidueProperties.getDNA();
1264   }
1265
1266   /**
1267    * get a ScoreMatrix based on its string name
1268    * 
1269    * @param pwtype
1270    * @return matrix in scoreMatrices with key pwtype or null
1271    */
1272   public static ScoreMatrix getScoreMatrix(String pwtype)
1273   {
1274     Object val = scoreMatrices.get(pwtype);
1275     if (val != null)
1276     {
1277       return (ScoreMatrix) val;
1278     }
1279     return null;
1280   }
1281
1282   public static int getPAM250(char c, char d)
1283   {
1284     int a = aaIndex[c];
1285     int b = aaIndex[d];
1286
1287     int pog = ResidueProperties.PAM250[a][b];
1288
1289     return pog;
1290   }
1291
1292   public static Hashtable toDssp3State;
1293   static
1294   {
1295     toDssp3State = new Hashtable();
1296     toDssp3State.put("H", "H");
1297     toDssp3State.put("E", "E");
1298     toDssp3State.put("C", " ");
1299     toDssp3State.put(" ", " ");
1300     toDssp3State.put("T", " ");
1301     toDssp3State.put("B", "E");
1302     toDssp3State.put("G", "H");
1303     toDssp3State.put("I", "H");
1304     toDssp3State.put("X", " ");
1305   }
1306
1307   /**
1308    * translate from other dssp secondary structure alphabets to 3-state
1309    * 
1310    * @param ssstring
1311    * @return ssstring as a three-state secondary structure assignment.
1312    */
1313   public static String getDssp3state(String ssstring)
1314   {
1315     if (ssstring == null)
1316     {
1317       return null;
1318     }
1319     StringBuffer ss = new StringBuffer();
1320     for (int i = 0; i < ssstring.length(); i++)
1321     {
1322       String ssc = ssstring.substring(i, i + 1);
1323       if (toDssp3State.containsKey(ssc))
1324       {
1325         ss.append((String) toDssp3State.get(ssc));
1326       }
1327       else
1328       {
1329         ss.append(" ");
1330       }
1331     }
1332     return ss.toString();
1333   }
1334
1335   /**
1336    * Used by getRNASecStrucState
1337    * 
1338    */
1339   public static Hashtable toRNAssState;
1340   static
1341   {
1342     toRNAssState = new Hashtable();
1343     toRNAssState.put(")", "(");
1344     toRNAssState.put("(", "(");
1345     toRNAssState.put("]", "[");
1346     toRNAssState.put("[", "[");
1347     toRNAssState.put("{", "{");
1348     toRNAssState.put("}", "{");
1349     toRNAssState.put(">", ">");
1350     toRNAssState.put("<", ">");
1351     toRNAssState.put("A", "A");
1352     toRNAssState.put("a", "A");
1353     toRNAssState.put("B", "B");
1354     toRNAssState.put("b", "B");
1355     toRNAssState.put("C", "C");
1356     toRNAssState.put("c", "C");
1357     toRNAssState.put("D", "D");
1358     toRNAssState.put("d", "D");
1359     toRNAssState.put("1", "1");
1360     toRNAssState.put("e", "1");
1361     toRNAssState.put("F", "F");
1362     toRNAssState.put("f", "F");
1363     toRNAssState.put("G", "G");
1364     toRNAssState.put("g", "G");
1365     toRNAssState.put("2", "2");
1366     toRNAssState.put("h", "2");
1367     toRNAssState.put("I", "I");
1368     toRNAssState.put("i", "I");
1369     toRNAssState.put("J", "J");
1370     toRNAssState.put("j", "J");
1371     toRNAssState.put("K", "K");
1372     toRNAssState.put("k", "K");
1373     toRNAssState.put("L", "L");
1374     toRNAssState.put("l", "L");
1375     toRNAssState.put("M", "M");
1376     toRNAssState.put("m", "M");
1377     toRNAssState.put("N", "N");
1378     toRNAssState.put("n", "N");
1379     toRNAssState.put("O", "O");
1380     toRNAssState.put("o", "O");
1381     toRNAssState.put("P", "P");
1382     toRNAssState.put("p", "P");
1383     toRNAssState.put("Q", "Q");
1384     toRNAssState.put("q", "Q");
1385     toRNAssState.put("R", "R");
1386     toRNAssState.put("r", "R");
1387     toRNAssState.put("S", "S");
1388     toRNAssState.put("s", "S");
1389     toRNAssState.put("T", "T");
1390     toRNAssState.put("t", "T");
1391     toRNAssState.put("U", "U");
1392     toRNAssState.put("u", "U");
1393     toRNAssState.put("V", "V");
1394     toRNAssState.put("v", "V");
1395     toRNAssState.put("W", "W");
1396     toRNAssState.put("w", "W");
1397     toRNAssState.put("X", "X");
1398     toRNAssState.put("x", "X");
1399     toRNAssState.put("Y", "Y");
1400     toRNAssState.put("y", "Y");
1401     toRNAssState.put("Z", "Z");
1402     toRNAssState.put("z", "Z");
1403     
1404   }
1405
1406   /**
1407    * translate to RNA secondary structure representation
1408    * 
1409    * @param ssstring
1410    * @return ssstring as a RNA-state secondary structure assignment.
1411    */
1412   public static String getRNASecStrucState(String ssstring)
1413   {
1414     if (ssstring == null)
1415     {
1416       return null;
1417     }
1418     StringBuffer ss = new StringBuffer();
1419     for (int i = 0; i < ssstring.length(); i++)
1420     {
1421       String ssc = ssstring.substring(i, i + 1);
1422       if (toRNAssState.containsKey(ssc))
1423       {
1424         ss.append((String) toRNAssState.get(ssc));
1425       }
1426       else
1427       {
1428         ss.append(" ");
1429       }
1430     }
1431     return ss.toString();
1432   }
1433
1434   // main method generates perl representation of residue property hash
1435   // / cut here
1436   public static void main(String[] args)
1437   {
1438     Hashtable aa = new Hashtable();
1439     System.out.println("my %aa = {");
1440     // invert property hashes
1441     Enumeration prop = propHash.keys();
1442     while (prop.hasMoreElements())
1443     {
1444       String pname = (String) prop.nextElement();
1445       Hashtable phash = (Hashtable) propHash.get(pname);
1446       Enumeration res = phash.keys();
1447       while (res.hasMoreElements())
1448       {
1449         String rname = (String) res.nextElement();
1450         Vector aprops = (Vector) aa.get(rname);
1451         if (aprops == null)
1452         {
1453           aprops = new Vector();
1454           aa.put(rname, aprops);
1455         }
1456         Integer hasprop = (Integer) phash.get(rname);
1457         if (hasprop.intValue() == 1)
1458         {
1459           aprops.addElement(pname);
1460         }
1461       }
1462     }
1463     Enumeration res = aa.keys();
1464     while (res.hasMoreElements())
1465     {
1466       String rname = (String) res.nextElement();
1467
1468       System.out.print("'" + rname + "' => [");
1469       Enumeration props = ((Vector) aa.get(rname)).elements();
1470       while (props.hasMoreElements())
1471       {
1472         System.out.print("'" + (String) props.nextElement() + "'");
1473         if (props.hasMoreElements())
1474         {
1475           System.out.println(", ");
1476         }
1477       }
1478       System.out.println("]" + (res.hasMoreElements() ? "," : ""));
1479     }
1480     System.out.println("};");
1481   }
1482   // to here
1483 }