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