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