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