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