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