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