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