2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.schemes;
23 import jalview.analysis.scoremodels.FeatureScoreModel;
24 import jalview.analysis.scoremodels.PIDScoreModel;
25 import jalview.api.analysis.ScoreModelI;
27 import java.awt.Color;
28 import java.util.ArrayList;
29 import java.util.Enumeration;
30 import java.util.HashMap;
31 import java.util.Hashtable;
32 import java.util.List;
34 import java.util.Vector;
36 public class ResidueProperties
38 public static Hashtable<String, ScoreModelI> scoreMatrices = new Hashtable();
40 // Stores residue codes/names and colours and other things
41 public static final int[] aaIndex; // aaHash version 2.1.1 and below
43 public static final int[] nucleotideIndex;
45 public static final int[] purinepyrimidineIndex;
47 public static final Map<String, Integer> aa3Hash = new HashMap<String, Integer>();
49 public static final Map<String, String> aa2Triplet = new HashMap<String, String>();
51 public static final Map<String, String> nucleotideName = new HashMap<String, String>();
53 // lookup from modified amino acid (e.g. MSE) to canonical form (e.g. MET)
54 public static final Map<String, String> modifications = new HashMap<String, String>();
58 aaIndex = new int[255];
59 for (int i = 0; i < 255; i++)
111 aaIndex['u'] = 22; // TODO: selenocystine triplet and codons needed. also
112 // extend subt. matrices
116 * maximum (gap) index for matrices involving protein alphabet
118 public final static int maxProteinIndex = 23;
121 * maximum (gap) index for matrices involving nucleotide alphabet
123 public final static int maxNucleotideIndex = 10;
127 nucleotideIndex = new int[255];
128 for (int i = 0; i < 255; i++)
130 nucleotideIndex[i] = 10; // non-nucleotide symbols are all non-gap gaps.
133 nucleotideIndex['A'] = 0;
134 nucleotideIndex['a'] = 0;
135 nucleotideIndex['C'] = 1;
136 nucleotideIndex['c'] = 1;
137 nucleotideIndex['G'] = 2;
138 nucleotideIndex['g'] = 2;
139 nucleotideIndex['T'] = 3;
140 nucleotideIndex['t'] = 3;
141 nucleotideIndex['U'] = 4;
142 nucleotideIndex['u'] = 4;
143 nucleotideIndex['I'] = 5;
144 nucleotideIndex['i'] = 5;
145 nucleotideIndex['X'] = 6;
146 nucleotideIndex['x'] = 6;
147 nucleotideIndex['R'] = 7;
148 nucleotideIndex['r'] = 7;
149 nucleotideIndex['Y'] = 8;
150 nucleotideIndex['y'] = 8;
151 nucleotideIndex['N'] = 9;
152 nucleotideIndex['n'] = 9;
154 nucleotideName.put("A", "Adenine");
155 nucleotideName.put("a", "Adenine");
156 nucleotideName.put("G", "Guanine");
157 nucleotideName.put("g", "Guanine");
158 nucleotideName.put("C", "Cytosine");
159 nucleotideName.put("c", "Cytosine");
160 nucleotideName.put("T", "Thymine");
161 nucleotideName.put("t", "Thymine");
162 nucleotideName.put("U", "Uracil");
163 nucleotideName.put("u", "Uracil");
164 nucleotideName.put("I", "Inosine");
165 nucleotideName.put("i", "Inosine");
166 nucleotideName.put("X", "Xanthine");
167 nucleotideName.put("x", "Xanthine");
168 nucleotideName.put("R", "Unknown Purine");
169 nucleotideName.put("r", "Unknown Purine");
170 nucleotideName.put("Y", "Unknown Pyrimidine");
171 nucleotideName.put("y", "Unknown Pyrimidine");
172 nucleotideName.put("N", "Unknown");
173 nucleotideName.put("n", "Unknown");
174 nucleotideName.put("W", "Weak nucleotide (A or T)");
175 nucleotideName.put("w", "Weak nucleotide (A or T)");
176 nucleotideName.put("S", "Strong nucleotide (G or C)");
177 nucleotideName.put("s", "Strong nucleotide (G or C)");
178 nucleotideName.put("M", "Amino (A or C)");
179 nucleotideName.put("m", "Amino (A or C)");
180 nucleotideName.put("K", "Keto (G or T)");
181 nucleotideName.put("k", "Keto (G or T)");
182 nucleotideName.put("B", "Not A (G or C or T)");
183 nucleotideName.put("b", "Not A (G or C or T)");
184 nucleotideName.put("H", "Not G (A or C or T)");
185 nucleotideName.put("h", "Not G (A or C or T)");
186 nucleotideName.put("D", "Not C (A or G or T)");
187 nucleotideName.put("d", "Not C (A or G or T)");
188 nucleotideName.put("V", "Not T (A or G or C");
189 nucleotideName.put("v", "Not T (A or G or C");
195 purinepyrimidineIndex = new int[255];
196 for (int i = 0; i < 255; i++)
198 purinepyrimidineIndex[i] = 3; // non-nucleotide symbols are all non-gap
202 purinepyrimidineIndex['A'] = 0;
203 purinepyrimidineIndex['a'] = 0;
204 purinepyrimidineIndex['C'] = 1;
205 purinepyrimidineIndex['c'] = 1;
206 purinepyrimidineIndex['G'] = 0;
207 purinepyrimidineIndex['g'] = 0;
208 purinepyrimidineIndex['T'] = 1;
209 purinepyrimidineIndex['t'] = 1;
210 purinepyrimidineIndex['U'] = 1;
211 purinepyrimidineIndex['u'] = 1;
212 purinepyrimidineIndex['I'] = 2;
213 purinepyrimidineIndex['i'] = 2;
214 purinepyrimidineIndex['X'] = 2;
215 purinepyrimidineIndex['x'] = 2;
216 purinepyrimidineIndex['R'] = 0;
217 purinepyrimidineIndex['r'] = 0;
218 purinepyrimidineIndex['Y'] = 1;
219 purinepyrimidineIndex['y'] = 1;
220 purinepyrimidineIndex['N'] = 2;
221 purinepyrimidineIndex['n'] = 2;
226 aa3Hash.put("ALA", new Integer(0));
227 aa3Hash.put("ARG", new Integer(1));
228 aa3Hash.put("ASN", new Integer(2));
229 aa3Hash.put("ASP", new Integer(3)); // D
230 aa3Hash.put("CYS", new Integer(4));
231 aa3Hash.put("GLN", new Integer(5)); // Q
232 aa3Hash.put("GLU", new Integer(6)); // E
233 aa3Hash.put("GLY", new Integer(7));
234 aa3Hash.put("HIS", new Integer(8));
235 aa3Hash.put("ILE", new Integer(9));
236 aa3Hash.put("LEU", new Integer(10));
237 aa3Hash.put("LYS", new Integer(11));
238 aa3Hash.put("MET", new Integer(12));
239 aa3Hash.put("PHE", new Integer(13));
240 aa3Hash.put("PRO", new Integer(14));
241 aa3Hash.put("SER", new Integer(15));
242 aa3Hash.put("THR", new Integer(16));
243 aa3Hash.put("TRP", new Integer(17));
244 aa3Hash.put("TYR", new Integer(18));
245 aa3Hash.put("VAL", new Integer(19));
246 // IUB Nomenclature for ambiguous peptides
247 aa3Hash.put("ASX", new Integer(20)); // "B";
248 aa3Hash.put("GLX", new Integer(21)); // X
249 aa3Hash.put("XAA", new Integer(22)); // X unknown
250 aa3Hash.put("-", new Integer(23));
251 aa3Hash.put("*", new Integer(23));
252 aa3Hash.put(".", new Integer(23));
253 aa3Hash.put(" ", new Integer(23));
254 aa3Hash.put("Gap", new Integer(23));
259 aa2Triplet.put("A", "ALA");
260 aa2Triplet.put("a", "ALA");
261 aa2Triplet.put("R", "ARG");
262 aa2Triplet.put("r", "ARG");
263 aa2Triplet.put("N", "ASN");
264 aa2Triplet.put("n", "ASN");
265 aa2Triplet.put("D", "ASP");
266 aa2Triplet.put("d", "ASP");
267 aa2Triplet.put("C", "CYS");
268 aa2Triplet.put("c", "CYS");
269 aa2Triplet.put("Q", "GLN");
270 aa2Triplet.put("q", "GLN");
271 aa2Triplet.put("E", "GLU");
272 aa2Triplet.put("e", "GLU");
273 aa2Triplet.put("G", "GLY");
274 aa2Triplet.put("g", "GLY");
275 aa2Triplet.put("H", "HIS");
276 aa2Triplet.put("h", "HIS");
277 aa2Triplet.put("I", "ILE");
278 aa2Triplet.put("i", "ILE");
279 aa2Triplet.put("L", "LEU");
280 aa2Triplet.put("l", "LEU");
281 aa2Triplet.put("K", "LYS");
282 aa2Triplet.put("k", "LYS");
283 aa2Triplet.put("M", "MET");
284 aa2Triplet.put("m", "MET");
285 aa2Triplet.put("F", "PHE");
286 aa2Triplet.put("f", "PHE");
287 aa2Triplet.put("P", "PRO");
288 aa2Triplet.put("p", "PRO");
289 aa2Triplet.put("S", "SER");
290 aa2Triplet.put("s", "SER");
291 aa2Triplet.put("T", "THR");
292 aa2Triplet.put("t", "THR");
293 aa2Triplet.put("W", "TRP");
294 aa2Triplet.put("w", "TRP");
295 aa2Triplet.put("Y", "TYR");
296 aa2Triplet.put("y", "TYR");
297 aa2Triplet.put("V", "VAL");
298 aa2Triplet.put("v", "VAL");
301 public static final String[] aa = { "A", "R", "N", "D", "C", "Q", "E",
302 "G", "H", "I", "L", "K", "M", "F", "P", "S", "T", "W", "Y", "V", "B",
303 "Z", "X", "_", "*", ".", " " };
305 public static final Color midBlue = new Color(100, 100, 255);
307 public static final Vector scaleColours = new Vector();
311 scaleColours.addElement(new Color(114, 0, 147));
312 scaleColours.addElement(new Color(156, 0, 98));
313 scaleColours.addElement(new Color(190, 0, 0));
314 scaleColours.addElement(Color.red);
315 scaleColours.addElement(new Color(255, 125, 0));
316 scaleColours.addElement(Color.orange);
317 scaleColours.addElement(new Color(255, 194, 85));
318 scaleColours.addElement(Color.yellow);
319 scaleColours.addElement(new Color(255, 255, 181));
320 scaleColours.addElement(Color.white);
323 public static final Color[] taylor = { new Color(204, 255, 0), // A
324 // Greenish-yellowy-yellow
325 new Color(0, 0, 255), // R Blueish-bluey-blue
326 new Color(204, 0, 255), // N Blueish-reddy-blue
327 new Color(255, 0, 0), // D Reddish-reddy-red
328 new Color(255, 255, 0), // C Yellowish-yellowy-yellow
329 new Color(255, 0, 204), // Q Reddish-bluey-red
330 new Color(255, 0, 102), // E Blueish-reddy-red
331 new Color(255, 153, 0), // G Yellowy-reddy-yellow
332 new Color(0, 102, 255), // H Greenish-bluey-blue
333 new Color(102, 255, 0), // I Greenish-yellowy-green
334 new Color(51, 255, 0), // L Yellowish-greeny-green
335 new Color(102, 0, 255), // K Reddish-bluey-blue
336 new Color(0, 255, 0), // M Greenish-greeny-green
337 new Color(0, 255, 102), // F Blueish-greeny-green
338 new Color(255, 204, 0), // P Reddish-yellowy-yellow
339 new Color(255, 51, 0), // S Yellowish-reddy-red
340 new Color(255, 102, 0), // T Reddish-yellowy-red
341 new Color(0, 204, 255), // W Blueish-greeny-green
342 new Color(0, 255, 204), // Y Greenish-bluey-green
343 new Color(153, 255, 0), // V Yellowish-greeny-yellow
352 public static final Color[] nucleotide = { new Color(100, 247, 63), // A
353 new Color(255, 179, 64), // C
354 new Color(235, 65, 60), // G
355 new Color(60, 136, 238), // T
356 new Color(60, 136, 238), // U
357 Color.white, // I (inosine)
358 Color.white, // X (xanthine)
365 // Added for PurinePyrimidineColourScheme
366 public static final Color[] purinepyrimidine = {
367 new Color(255, 131, 250), // A, G, R purines purplish/orchid
368 new Color(64, 224, 208), // C,U, T, Y pyrimidines turquoise
369 Color.white, // all other nucleotides
374 public static final Color[] zappo = { Color.pink, // A
382 midBlue,// Color.red, // H
403 // Dunno where I got these numbers from
404 public static final double[] hyd2 = { 0.62, // A
429 public static final double[] helix = { 1.42, 0.98, 0.67, 1.01, 0.70,
430 1.11, 1.51, 0.57, 1.00, 1.08, 1.21, 1.16, 1.45, 1.13, 0.57, 0.77,
431 0.83, 1.08, 0.69, 1.06, 0.84, 1.31, 1.00, 0.0 };
433 public static final double helixmin = 0.57;
435 public static final double helixmax = 1.51;
437 public static final double[] strand = { 0.83, 0.93, 0.89, 0.54, 1.19,
438 1.10, 0.37, 0.75, 0.87, 1.60, 1.30, 0.74, 1.05, 1.38, 0.55, 0.75,
439 1.19, 1.37, 1.47, 1.70, 0.72, 0.74, 1.0, 0.0 };
441 public static final double strandmin = 0.37;
443 public static final double strandmax = 1.7;
445 public static final double[] turn = { 0.66, 0.95, 1.56, 1.46, 1.19, 0.98,
446 0.74, 1.56, 0.95, 0.47, 0.59, 1.01, 0.60, 0.60, 1.52, 1.43, 0.96,
447 0.96, 1.14, 0.50, 1.51, 0.86, 1.00, 0, 0 };
449 public static final double turnmin = 0.47;
451 public static final double turnmax = 1.56;
453 public static final double[] buried = { 1.7, 0.1, 0.4, 0.4, 4.6, 0.3,
454 0.3, 1.8, 0.8, 3.1, 2.4, 0.05, 1.9, 2.2, 0.6, 0.8, 0.7, 1.6, 0.5,
455 2.9, 0.4, 0.3, 1.358, 0.00 };
457 public static final double buriedmin = 0.05;
459 public static final double buriedmax = 4.6;
461 // This is hydropathy index
462 // Kyte, J., and Doolittle, R.F., J. Mol. Biol.
463 // 1157, 105-132, 1982
464 public static final double[] hyd = { 1.8, -4.5, -3.5, -3.5, 2.5, -3.5,
465 -3.5, -0.4, -3.2, 4.5, 3.8, -3.9, 1.9, 2.8, -1.6, -0.8, -0.7, -0.9,
466 -1.3, 4.2, -3.5, -3.5, -0.49, 0.0 };
468 public static final double hydmax = 4.5;
470 public static final double hydmin = -3.9;
472 // public static final double hydmax = 1.38;
473 // public static final double hydmin = -2.53;
474 private static final int[][] BLOSUM62 = {
475 { 4, -1, -2, -2, 0, -1, -1, 0, -2, -1, -1, -1, -1, -2, -1, 1, 0, -3,
476 -2, 0, -2, -1, 0, -4 },
477 { -1, 5, 0, -2, -3, 1, 0, -2, 0, -3, -2, 2, -1, -3, -2, -1, -1, -3,
478 -2, -3, -1, 0, -1, -4 },
479 { -2, 0, 6, 1, -3, 0, 0, 0, 1, -3, -3, 0, -2, -3, -2, 1, 0, -4, -2,
481 { -2, -2, 1, 6, -3, 0, 2, -1, -1, -3, -4, -1, -3, -3, -1, 0, -1, -4,
482 -3, -3, 4, 1, -1, -4 },
483 { 0, 3, -3, -3, 9, -3, -4, -3, -3, -1, -1, -3, -1, -2, -3, -1, -1,
484 -2, -2, -1, -3, -3, -2, -4 },
485 { -1, 1, 0, 0, -3, 5, 2, -2, 0, -3, -2, 1, 0, -3, -1, 0, -1, -2, -1,
487 { -1, 0, 0, 2, -4, 2, 5, -2, 0, -3, -3, 1, -2, -3, -1, 0, -1, -3, -2,
489 { 0, -2, 0, -1, -3, -2, -2, 6, -2, -4, -4, -2, -3, -3, -2, 0, -2, -2,
490 -3, -3, -1, -2, -1, -4 },
491 { -2, 0, 1, -1, -3, 0, 0, -2, 8, -3, -3, -1, -2, -1, -2, -1, -2, -2,
492 2, -3, 0, 0, -1, -4 },
493 { -1, -3, -3, -3, -1, -3, -3, -4, -3, 4, 2, -3, 1, 0, -3, -2, -1, -3,
494 -1, 3, -3, -3, -1, -4 },
495 { -1, -2, -3, -4, -1, -2, -3, -4, -3, 2, 4, -2, 2, 0, -3, -2, -1, -2,
496 -1, 1, -4, -3, -1, -4 },
497 { -1, 2, 0, -1, -3, 1, 1, -2, -1, -3, -2, 5, -1, -3, -1, 0, -1, -3,
498 -2, -2, 0, 1, -1, -4 },
499 { -1, -1, -2, -3, -1, 0, -2, -3, -2, 1, 2, -1, 5, 0, -2, -1, -1, -1,
500 -1, 1, -3, -1, -1, -4 },
501 { -2, -3, -3, -3, -2, -3, -3, -3, -1, 0, 0, -3, 0, 6, -4, -2, -2, 1,
502 3, -1, -3, -3, -1, -4 },
503 { -1, -2, -2, -1, -3, -1, -1, -2, -2, -3, -3, -1, -2, -4, 7, -1, -1,
504 -4, -3, -2, -2, -1, -2, -4 },
505 { 1, -1, 1, 0, -1, 0, 0, 0, -1, -2, -2, 0, -1, -2, -1, 4, 1, -3, -2,
507 { 0, -1, 0, -1, -1, -1, -1, -2, -2, -1, -1, -1, -1, -2, -1, 1, 5, -2,
508 -2, 0, -1, -1, 0, -4 },
509 { -3, -3, -4, -4, -2, -2, -3, -2, -2, -3, -2, -3, -1, 1, -4, -3, -2,
510 11, 2, -3, -4, -3, -2, -4 },
511 { -2, -2, -2, -3, -2, -1, -2, -3, 2, -1, -1, -2, -1, 3, -3, -2, -2,
512 2, 7, -1, -3, -2, -1, -4 },
513 { 0, -3, -3, -3, -1, -2, -2, -3, -3, 3, 1, -2, 1, -1, -2, -2, 0, -3,
514 -1, 4, -3, -2, -1, -4 },
515 { -2, -1, 3, 4, -3, 0, 1, -1, 0, -3, -4, 0, -3, -3, -2, 0, -1, -4,
516 -3, -3, 4, 1, -1, -4 },
517 { -1, 0, 0, 1, -3, 3, 4, -2, 0, -3, -3, 1, -1, -3, -1, 0, -1, -3, -2,
519 { 0, -1, -1, -1, -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -2, 0, 0,
520 -2, -1, -1, -1, -1, -1, -4 },
521 { -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4,
522 -4, -4, -4, -4, -4, -4, 1 }, };
524 static final int[][] PAM250 = {
525 { 2, -2, 0, 0, -2, 0, 0, 1, -1, -1, -2, -1, -1, -3, 1, 1, 1, -6, -3,
527 { -2, 6, 0, -1, -4, 1, -1, -3, 2, -2, -3, 3, 0, -4, 0, 0, -1, 2, -4,
529 { 0, 0, 2, 2, -4, 1, 1, 0, 2, -2, -3, 1, -2, -3, 0, 1, 0, -4, -2, -2,
531 { 0, -1, 2, 4, -5, 2, 3, 1, 1, -2, -4, 0, -3, -6, -1, 0, 0, -7, -4,
533 { -2, -4, -4, -5, 12, -5, -5, -3, -3, -2, -6, -5, -5, -4, -3, 0, -2,
534 -8, 0, -2, -4, -5, -3, -8 },
535 { 0, 1, 1, 2, -5, 4, 2, -1, 3, -2, -2, 1, -1, -5, 0, -1, -1, -5, -4,
537 { 0, -1, 1, 3, -5, 2, 4, 0, 1, -2, -3, 0, -2, -5, -1, 0, 0, -7, -4,
539 { 1, -3, 0, 1, -3, -1, 0, 5, -2, -3, -4, -2, -3, -5, 0, 1, 0, -7, -5,
541 { -1, 2, 2, 1, -3, 3, 1, -2, 6, -2, -2, 0, -2, -2, 0, -1, -1, -3, 0,
543 { -1, -2, -2, -2, -2, -2, -2, -3, -2, 5, 2, -2, 2, 1, -2, -1, 0, -5,
544 -1, 4, -2, -2, -1, -8 },
545 { -2, -3, -3, -4, -6, -2, -3, -4, -2, 2, 6, -3, 4, 2, -3, -3, -2, -2,
546 -1, 2, -3, -3, -1, -8 },
547 { -1, 3, 1, 0, -5, 1, 0, -2, 0, -2, -3, 5, 0, -5, -1, 0, 0, -3, -4,
549 { -1, 0, -2, -3, -5, -1, -2, -3, -2, 2, 4, 0, 6, 0, -2, -2, -1, -4,
550 -2, 2, -2, -2, -1, -8 },
551 { -3, -4, -3, -6, -4, -5, -5, -5, -2, 1, 2, -5, 0, 9, -5, -3, -3, 0,
552 7, -1, -4, -5, -2, -8 },
553 { 1, 0, 0, -1, -3, 0, -1, 0, 0, -2, -3, -1, -2, -5, 6, 1, 0, -6, -5,
555 { 1, 0, 1, 0, 0, -1, 0, 1, -1, -1, -3, 0, -2, -3, 1, 2, 1, -2, -3,
557 { 1, -1, 0, 0, -2, -1, 0, 0, -1, 0, -2, 0, -1, -3, 0, 1, 3, -5, -3,
559 { -6, 2, -4, -7, -8, -5, -7, -7, -3, -5, -2, -3, -4, 0, -6, -2, -5,
560 17, 0, -6, -5, -6, -4, -8 },
561 { -3, -4, -2, -4, 0, -4, -4, -5, 0, -1, -1, -4, -2, 7, -5, -3, -3, 0,
562 10, -2, -3, -4, -2, -8 },
563 { 0, -2, -2, -2, -2, -2, -2, -1, -2, 4, 2, -2, 2, -1, -1, -1, 0, -6,
564 -2, 4, -2, -2, -1, -8 },
565 { 0, -1, 2, 3, -4, 1, 3, 0, 1, -2, -3, 1, -2, -4, -1, 0, 0, -5, -3,
567 { 0, 0, 1, 3, -5, 3, 3, 0, 2, -2, -3, 0, -2, -5, 0, 0, -1, -6, -4,
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 { -8, -8, -8, -8, -8, -8, -8, -8, -8, -8, -8, -8, -8, -8, -8, -8, -8,
572 -8, -8, -8, -8, -8, -8, 1 }, };
574 public static final Hashtable ssHash = new Hashtable(); // stores the number
579 ssHash.put("H", Color.magenta);
580 ssHash.put("E", Color.yellow);
581 ssHash.put("-", Color.white);
582 ssHash.put(".", Color.white);
583 ssHash.put("S", Color.cyan);
584 ssHash.put("T", Color.blue);
585 ssHash.put("G", Color.pink);
586 ssHash.put("I", Color.pink);
587 ssHash.put("B", Color.yellow);
591 * new Color(60, 136, 238), // U Color.white, // I Color.white, // X
592 * Color.white, // R Color.white, // Y Color.white, // N Color.white, // Gap
595 // JBPNote: patch matrix for T/U equivalence when working with DNA or RNA.
596 // Will equate sequences if working with mixed nucleotide sets.
597 // treats T and U identically. R and Y weak equivalence with AG and CTU.
598 // N matches any other base weakly
600 static final int[][] DNA = { { 10, -8, -8, -8, -8, 1, 1, 1, -8, 1, 1 }, // A
601 { -8, 10, -8, -8, -8, 1, 1, -8, 1, 1, 1 }, // C
602 { -8, -8, 10, -8, -8, 1, 1, 1, -8, 1, 1 }, // G
603 { -8, -8, -8, 10, 10, 1, 1, -8, 1, 1, 1 }, // T
604 { -8, -8, -8, 10, 10, 1, 1, -8, 1, 1, 1 }, // U
605 { 1, 1, 1, 1, 1, 10, 0, 0, 0, 1, 1 }, // I
606 { 1, 1, 1, 1, 1, 0, 10, 0, 0, 1, 1 }, // X
607 { 1, -8, 1, -8, -8, 0, 0, 10, -8, 1, 1 }, // R
608 { -8, 1, -8, 1, 1, 0, 0, -8, 10, 1, 1 }, // Y
609 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 10, 1 }, // N
610 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, // -
613 * register matrices in list
617 scoreMatrices.put("BLOSUM62", new ScoreMatrix("BLOSUM62", BLOSUM62, 0));
618 scoreMatrices.put("PAM250", new ScoreMatrix("PAM250", PAM250, 0));
619 scoreMatrices.put("DNA", new ScoreMatrix("DNA", DNA, 1));
623 public static final Color[] pidColours = { midBlue,
624 new Color(153, 153, 255),
626 new Color(204, 204, 255), };
628 public static final float[] pidThresholds = { 80, 60, 40, };
630 public static Map<String, List<String>> codonHash = new HashMap<String, List<String>>();
632 private static List<String> Lys = new ArrayList<String>();
634 private static List<String> Asn = new ArrayList<String>();
636 private static List<String> Gln = new ArrayList<String>();
638 private static List<String> His = new ArrayList<String>();
640 private static List<String> Glu = new ArrayList<String>();
642 private static List<String> Asp = new ArrayList<String>();
644 private static List<String> Tyr = new ArrayList<String>();
646 private static List<String> Thr = new ArrayList<String>();
648 private static List<String> Pro = new ArrayList<String>();
650 private static List<String> Ala = new ArrayList<String>();
652 private static List<String> Ser = new ArrayList<String>();
654 private static List<String> Arg = new ArrayList<String>();
656 private static List<String> Gly = new ArrayList<String>();
658 private static List<String> Trp = new ArrayList<String>();
660 private static List<String> Cys = new ArrayList<String>();
662 private static List<String> Ile = new ArrayList<String>();
664 private static List<String> Met = new ArrayList<String>();
666 private static List<String> Leu = new ArrayList<String>();
668 private static List<String> Val = new ArrayList<String>();
670 private static List<String> Phe = new ArrayList<String>();
672 public static List<String> STOP = new ArrayList<String>();
674 public static String START = "ATG";
678 codonHash.put("K", Lys);
679 codonHash.put("N", Asn);
680 codonHash.put("Q", Gln);
681 codonHash.put("H", His);
682 codonHash.put("E", Glu);
683 codonHash.put("D", Asp);
684 codonHash.put("Y", Tyr);
685 codonHash.put("T", Thr);
686 codonHash.put("P", Pro);
687 codonHash.put("A", Ala);
688 codonHash.put("S", Ser);
689 codonHash.put("R", Arg);
690 codonHash.put("G", Gly);
691 codonHash.put("W", Trp);
692 codonHash.put("C", Cys);
693 codonHash.put("I", Ile);
694 codonHash.put("M", Met);
695 codonHash.put("L", Leu);
696 codonHash.put("V", Val);
697 codonHash.put("F", Phe);
698 codonHash.put("STOP", STOP);
702 * Nucleotide Ambiguity Codes
704 public static final Map<String, String[]> ambiguityCodes = new Hashtable<String, String[]>();
707 * Codon triplets with additional symbols for unambiguous codons that include
710 public static final Hashtable<String, String> codonHash2 = new Hashtable<String, String>();
713 * all ambiguity codes for a given base
715 public final static Hashtable<String, List<String>> _ambiguityCodes = new Hashtable<String, List<String>>();
720 * Ambiguity codes as per http://www.chem.qmul.ac.uk/iubmb/misc/naseq.html
722 ambiguityCodes.put("R", new String[] { "A", "G" });
723 ambiguityCodes.put("Y", new String[] { "T", "C" });
724 ambiguityCodes.put("W", new String[] { "A", "T" });
725 ambiguityCodes.put("S", new String[] { "G", "C" });
726 ambiguityCodes.put("M", new String[] { "A", "C" });
727 ambiguityCodes.put("K", new String[] { "G", "T" });
728 ambiguityCodes.put("H", new String[] { "A", "T", "C" });
729 ambiguityCodes.put("B", new String[] { "G", "T", "C" });
730 ambiguityCodes.put("V", new String[] { "G", "A", "C" });
731 ambiguityCodes.put("D", new String[] { "G", "A", "T" });
732 ambiguityCodes.put("N", new String[] { "G", "A", "T", "C" });
734 // Now build codon translation table
735 codonHash2.put("AAA", "K");
736 codonHash2.put("AAG", "K");
737 codonHash2.put("AAC", "N");
738 codonHash2.put("AAT", "N");
740 codonHash2.put("CAA", "Q");
741 codonHash2.put("CAG", "Q");
742 codonHash2.put("CAC", "H");
743 codonHash2.put("CAT", "H");
745 codonHash2.put("GAA", "E");
746 codonHash2.put("GAG", "E");
747 codonHash2.put("GAC", "D");
748 codonHash2.put("GAT", "D");
750 codonHash2.put("TAC", "Y");
751 codonHash2.put("TAT", "Y");
753 codonHash2.put("ACA", "T");
754 codonHash2.put("ACC", "T");
755 codonHash2.put("ACT", "T");
756 codonHash2.put("ACG", "T");
758 codonHash2.put("CCA", "P");
759 codonHash2.put("CCG", "P");
760 codonHash2.put("CCC", "P");
761 codonHash2.put("CCT", "P");
763 codonHash2.put("GCA", "A");
764 codonHash2.put("GCG", "A");
765 codonHash2.put("GCC", "A");
766 codonHash2.put("GCT", "A");
768 codonHash2.put("TCA", "S");
769 codonHash2.put("TCG", "S");
770 codonHash2.put("TCC", "S");
771 codonHash2.put("TCT", "S");
772 codonHash2.put("AGC", "S");
773 codonHash2.put("AGT", "S");
775 codonHash2.put("AGA", "R");
776 codonHash2.put("AGG", "R");
777 codonHash2.put("CGA", "R");
778 codonHash2.put("CGG", "R");
779 codonHash2.put("CGC", "R");
780 codonHash2.put("CGT", "R");
782 codonHash2.put("GGA", "G");
783 codonHash2.put("GGG", "G");
784 codonHash2.put("GGC", "G");
785 codonHash2.put("GGT", "G");
787 codonHash2.put("TGA", "*");
788 codonHash2.put("TAA", "*");
789 codonHash2.put("TAG", "*");
791 codonHash2.put("TGG", "W");
793 codonHash2.put("TGC", "C");
794 codonHash2.put("TGT", "C");
796 codonHash2.put("ATA", "I");
797 codonHash2.put("ATC", "I");
798 codonHash2.put("ATT", "I");
800 codonHash2.put("ATG", "M");
802 codonHash2.put("CTA", "L");
803 codonHash2.put("CTG", "L");
804 codonHash2.put("CTC", "L");
805 codonHash2.put("CTT", "L");
806 codonHash2.put("TTA", "L");
807 codonHash2.put("TTG", "L");
809 codonHash2.put("GTA", "V");
810 codonHash2.put("GTG", "V");
811 codonHash2.put("GTC", "V");
812 codonHash2.put("GTT", "V");
814 codonHash2.put("TTC", "F");
815 codonHash2.put("TTT", "F");
817 buildAmbiguityCodonSet();
821 * programmatic generation of codons including ambiguity codes
823 public static void buildAmbiguityCodonSet()
825 if (_ambiguityCodes.size() > 0)
828 .println("Ignoring multiple calls to buildAmbiguityCodonSet");
831 // Invert the ambiguity code set
832 for (Map.Entry<String, String[]> acode : ambiguityCodes.entrySet())
834 for (String r : acode.getValue())
836 List<String> codesfor = _ambiguityCodes.get(r);
837 if (codesfor == null)
839 _ambiguityCodes.put(r, codesfor = new ArrayList<String>());
841 if (!codesfor.contains(acode.getKey()))
843 codesfor.add(acode.getKey());
848 .println("Inconsistency in the IUBMB ambiguity code nomenclature table: collision for "
849 + acode.getKey() + " in residue " + r);
853 // and programmatically add in the ambiguity codes that yield the same amino
855 String[] unambcodons = codonHash2.keySet().toArray(
856 new String[codonHash2.size()]);
857 for (String codon : unambcodons)
859 String residue = codonHash2.get(codon);
860 String acodon[][] = new String[codon.length()][];
861 for (int i = 0, iSize = codon.length(); i < iSize; i++)
863 String _ac = "" + codon.charAt(i);
864 List<String> acodes = _ambiguityCodes.get(_ac);
867 acodon[i] = acodes.toArray(new String[acodes.size()]);
871 acodon[i] = new String[] {};
874 // enumerate all combinations and test for veracity of translation
875 int tpos[] = new int[codon.length()], cpos[] = new int[codon.length()];
876 for (int i = 0; i < tpos.length; i++)
880 tpos[acodon.length - 1] = 0;
882 while (tpos[0] < acodon[0].length)
884 // make all codons for this combination
885 char allres[][] = new char[tpos.length][];
888 for (ipos = 0; ipos < tpos.length; ipos++)
890 if (acodon[ipos].length == 0 || tpos[ipos] < 0)
892 _acodon += codon.charAt(ipos);
893 allres[ipos] = new char[] { codon.charAt(ipos) };
897 _acodon += acodon[ipos][tpos[ipos]];
898 String[] altbase = ambiguityCodes.get(acodon[ipos][tpos[ipos]]);
899 allres[ipos] = new char[altbase.length];
901 for (String ab : altbase)
903 allres[ipos][j++] = ab.charAt(0);
907 // test all codons for this combination
908 for (ipos = 0; ipos < cpos.length; ipos++)
912 boolean valid = true;
916 for (j = 0; j < cpos.length; j++)
918 _codon += allres[j][cpos[j]];
920 String tr = codonHash2.get(_codon);
921 if (valid = (tr != null && tr.equals(residue)))
923 // advance to next combination
924 ipos = acodon.length - 1;
925 while (++cpos[ipos] >= allres[ipos].length && ipos > 0)
931 } while (valid && cpos[0] < allres[0].length);
934 // Add this to the set of codons we will translate
935 // System.out.println("Adding ambiguity codon: " + _acodon + " for "
937 codonHash2.put(_acodon, residue);
941 // System.err.println("Rejecting ambiguity codon: " + _acodon
942 // + " for " + residue);
945 ipos = acodon.length - 1;
946 while (++tpos[ipos] >= acodon[ipos].length && ipos > 0)
1041 // Stores residue codes/names and colours and other things
1042 public static Hashtable propHash = new Hashtable();
1044 public static Hashtable hydrophobic = new Hashtable();
1046 public static Hashtable polar = new Hashtable();
1048 public static Hashtable small = new Hashtable();
1050 public static Hashtable positive = new Hashtable();
1052 public static Hashtable negative = new Hashtable();
1054 public static Hashtable charged = new Hashtable();
1056 public static Hashtable aromatic = new Hashtable();
1058 public static Hashtable aliphatic = new Hashtable();
1060 public static Hashtable tiny = new Hashtable();
1062 public static Hashtable proline = new Hashtable();
1066 hydrophobic.put("I", new Integer(1));
1067 hydrophobic.put("L", new Integer(1));
1068 hydrophobic.put("V", new Integer(1));
1069 hydrophobic.put("C", new Integer(1));
1070 hydrophobic.put("A", new Integer(1));
1071 hydrophobic.put("G", new Integer(1));
1072 hydrophobic.put("M", new Integer(1));
1073 hydrophobic.put("F", new Integer(1));
1074 hydrophobic.put("Y", new Integer(1));
1075 hydrophobic.put("W", new Integer(1));
1076 hydrophobic.put("H", new Integer(1));
1077 hydrophobic.put("K", new Integer(1));
1078 hydrophobic.put("X", new Integer(1));
1079 hydrophobic.put("-", new Integer(1));
1080 hydrophobic.put("*", new Integer(1));
1081 hydrophobic.put("R", new Integer(0));
1082 hydrophobic.put("E", new Integer(0));
1083 hydrophobic.put("Q", new Integer(0));
1084 hydrophobic.put("D", new Integer(0));
1085 hydrophobic.put("N", new Integer(0));
1086 hydrophobic.put("S", new Integer(0));
1087 hydrophobic.put("T", new Integer(0));
1088 hydrophobic.put("P", new Integer(0));
1093 polar.put("Y", new Integer(1));
1094 polar.put("W", new Integer(1));
1095 polar.put("H", new Integer(1));
1096 polar.put("K", new Integer(1));
1097 polar.put("R", new Integer(1));
1098 polar.put("E", new Integer(1));
1099 polar.put("Q", new Integer(1));
1100 polar.put("D", new Integer(1));
1101 polar.put("N", new Integer(1));
1102 polar.put("S", new Integer(1));
1103 polar.put("T", new Integer(1));
1104 polar.put("X", new Integer(1));
1105 polar.put("-", new Integer(1));
1106 polar.put("*", new Integer(1));
1107 polar.put("I", new Integer(0));
1108 polar.put("L", new Integer(0));
1109 polar.put("V", new Integer(0));
1110 polar.put("C", new Integer(0));
1111 polar.put("A", new Integer(0));
1112 polar.put("G", new Integer(0));
1113 polar.put("M", new Integer(0));
1114 polar.put("F", new Integer(0));
1115 polar.put("P", new Integer(0));
1120 small.put("I", new Integer(0));
1121 small.put("L", new Integer(0));
1122 small.put("V", new Integer(1));
1123 small.put("C", new Integer(1));
1124 small.put("A", new Integer(1));
1125 small.put("G", new Integer(1));
1126 small.put("M", new Integer(0));
1127 small.put("F", new Integer(0));
1128 small.put("Y", new Integer(0));
1129 small.put("W", new Integer(0));
1130 small.put("H", new Integer(0));
1131 small.put("K", new Integer(0));
1132 small.put("R", new Integer(0));
1133 small.put("E", new Integer(0));
1134 small.put("Q", new Integer(0));
1135 small.put("D", new Integer(1));
1136 small.put("N", new Integer(1));
1137 small.put("S", new Integer(1));
1138 small.put("T", new Integer(1));
1139 small.put("P", new Integer(1));
1140 small.put("-", new Integer(1));
1141 small.put("*", new Integer(1));
1146 positive.put("I", new Integer(0));
1147 positive.put("L", new Integer(0));
1148 positive.put("V", new Integer(0));
1149 positive.put("C", new Integer(0));
1150 positive.put("A", new Integer(0));
1151 positive.put("G", new Integer(0));
1152 positive.put("M", new Integer(0));
1153 positive.put("F", new Integer(0));
1154 positive.put("Y", new Integer(0));
1155 positive.put("W", new Integer(0));
1156 positive.put("H", new Integer(1));
1157 positive.put("K", new Integer(1));
1158 positive.put("R", new Integer(1));
1159 positive.put("E", new Integer(0));
1160 positive.put("Q", new Integer(0));
1161 positive.put("D", new Integer(0));
1162 positive.put("N", new Integer(0));
1163 positive.put("S", new Integer(0));
1164 positive.put("T", new Integer(0));
1165 positive.put("P", new Integer(0));
1166 positive.put("-", new Integer(1));
1167 positive.put("*", new Integer(1));
1172 negative.put("I", new Integer(0));
1173 negative.put("L", new Integer(0));
1174 negative.put("V", new Integer(0));
1175 negative.put("C", new Integer(0));
1176 negative.put("A", new Integer(0));
1177 negative.put("G", new Integer(0));
1178 negative.put("M", new Integer(0));
1179 negative.put("F", new Integer(0));
1180 negative.put("Y", new Integer(0));
1181 negative.put("W", new Integer(0));
1182 negative.put("H", new Integer(0));
1183 negative.put("K", new Integer(0));
1184 negative.put("R", new Integer(0));
1185 negative.put("E", new Integer(1));
1186 negative.put("Q", new Integer(0));
1187 negative.put("D", new Integer(1));
1188 negative.put("N", new Integer(0));
1189 negative.put("S", new Integer(0));
1190 negative.put("T", new Integer(0));
1191 negative.put("P", new Integer(0));
1192 negative.put("-", new Integer(1));
1193 negative.put("*", new Integer(1));
1198 charged.put("I", new Integer(0));
1199 charged.put("L", new Integer(0));
1200 charged.put("V", new Integer(0));
1201 charged.put("C", new Integer(0));
1202 charged.put("A", new Integer(0));
1203 charged.put("G", new Integer(0));
1204 charged.put("M", new Integer(0));
1205 charged.put("F", new Integer(0));
1206 charged.put("Y", new Integer(0));
1207 charged.put("W", new Integer(0));
1208 charged.put("H", new Integer(1));
1209 charged.put("K", new Integer(1));
1210 charged.put("R", new Integer(1));
1211 charged.put("E", new Integer(1));
1212 charged.put("Q", new Integer(0));
1213 charged.put("D", new Integer(1));
1214 charged.put("N", new Integer(0)); // Asparagine is polar but not charged.
1215 // Alternative would be charged and
1216 // negative (in basic form)?
1217 charged.put("S", new Integer(0));
1218 charged.put("T", new Integer(0));
1219 charged.put("P", new Integer(0));
1220 charged.put("-", new Integer(1));
1221 charged.put("*", new Integer(1));
1226 aromatic.put("I", new Integer(0));
1227 aromatic.put("L", new Integer(0));
1228 aromatic.put("V", new Integer(0));
1229 aromatic.put("C", new Integer(0));
1230 aromatic.put("A", new Integer(0));
1231 aromatic.put("G", new Integer(0));
1232 aromatic.put("M", new Integer(0));
1233 aromatic.put("F", new Integer(1));
1234 aromatic.put("Y", new Integer(1));
1235 aromatic.put("W", new Integer(1));
1236 aromatic.put("H", new Integer(1));
1237 aromatic.put("K", new Integer(0));
1238 aromatic.put("R", new Integer(0));
1239 aromatic.put("E", new Integer(0));
1240 aromatic.put("Q", new Integer(0));
1241 aromatic.put("D", new Integer(0));
1242 aromatic.put("N", new Integer(0));
1243 aromatic.put("S", new Integer(0));
1244 aromatic.put("T", new Integer(0));
1245 aromatic.put("P", new Integer(0));
1246 aromatic.put("-", new Integer(1));
1247 aromatic.put("*", new Integer(1));
1252 aliphatic.put("I", new Integer(1));
1253 aliphatic.put("L", new Integer(1));
1254 aliphatic.put("V", new Integer(1));
1255 aliphatic.put("C", new Integer(0));
1256 aliphatic.put("A", new Integer(0));
1257 aliphatic.put("G", new Integer(0));
1258 aliphatic.put("M", new Integer(0));
1259 aliphatic.put("F", new Integer(0));
1260 aliphatic.put("Y", new Integer(0));
1261 aliphatic.put("W", new Integer(0));
1262 aliphatic.put("H", new Integer(0));
1263 aliphatic.put("K", new Integer(0));
1264 aliphatic.put("R", new Integer(0));
1265 aliphatic.put("E", new Integer(0));
1266 aliphatic.put("Q", new Integer(0));
1267 aliphatic.put("D", new Integer(0));
1268 aliphatic.put("N", new Integer(0));
1269 aliphatic.put("S", new Integer(0));
1270 aliphatic.put("T", new Integer(0));
1271 aliphatic.put("P", new Integer(0));
1272 aliphatic.put("-", new Integer(1));
1273 aliphatic.put("*", new Integer(1));
1278 tiny.put("I", new Integer(0));
1279 tiny.put("L", new Integer(0));
1280 tiny.put("V", new Integer(0));
1281 tiny.put("C", new Integer(0));
1282 tiny.put("A", new Integer(1));
1283 tiny.put("G", new Integer(1));
1284 tiny.put("M", new Integer(0));
1285 tiny.put("F", new Integer(0));
1286 tiny.put("Y", new Integer(0));
1287 tiny.put("W", new Integer(0));
1288 tiny.put("H", new Integer(0));
1289 tiny.put("K", new Integer(0));
1290 tiny.put("R", new Integer(0));
1291 tiny.put("E", new Integer(0));
1292 tiny.put("Q", new Integer(0));
1293 tiny.put("D", new Integer(0));
1294 tiny.put("N", new Integer(0));
1295 tiny.put("S", new Integer(1));
1296 tiny.put("T", new Integer(0));
1297 tiny.put("P", new Integer(0));
1298 tiny.put("-", new Integer(1));
1299 tiny.put("*", new Integer(1));
1304 proline.put("I", new Integer(0));
1305 proline.put("L", new Integer(0));
1306 proline.put("V", new Integer(0));
1307 proline.put("C", new Integer(0));
1308 proline.put("A", new Integer(0));
1309 proline.put("G", new Integer(0));
1310 proline.put("M", new Integer(0));
1311 proline.put("F", new Integer(0));
1312 proline.put("Y", new Integer(0));
1313 proline.put("W", new Integer(0));
1314 proline.put("H", new Integer(0));
1315 proline.put("K", new Integer(0));
1316 proline.put("R", new Integer(0));
1317 proline.put("E", new Integer(0));
1318 proline.put("Q", new Integer(0));
1319 proline.put("D", new Integer(0));
1320 proline.put("N", new Integer(0));
1321 proline.put("S", new Integer(0));
1322 proline.put("T", new Integer(0));
1323 proline.put("P", new Integer(1));
1324 proline.put("-", new Integer(1));
1325 proline.put("*", new Integer(1));
1330 propHash.put("hydrophobic", hydrophobic);
1331 propHash.put("small", small);
1332 propHash.put("positive", positive);
1333 propHash.put("negative", negative);
1334 propHash.put("charged", charged);
1335 propHash.put("aromatic", aromatic);
1336 propHash.put("aliphatic", aliphatic);
1337 propHash.put("tiny", tiny);
1338 propHash.put("proline", proline);
1339 propHash.put("polar", polar);
1343 int[][] propMatrixF = new int[maxProteinIndex][maxProteinIndex], propMatrixPos = new int[maxProteinIndex][maxProteinIndex], propMatrixEpos = new int[maxProteinIndex][maxProteinIndex];
1344 for (int i = 0; i < maxProteinIndex; i++)
1346 int maxF = 0, maxP = 0, maxEP = 0;
1356 for (int j = i + 1; j < maxProteinIndex; j++)
1367 propMatrixF[i][j] = 0;
1368 propMatrixPos[i][j] = 0;
1369 propMatrixEpos[i][j] = 0;
1370 for (Enumeration<String> en = propHash.keys(); en.hasMoreElements();)
1372 String ph = en.nextElement();
1373 Map<String, Integer> pph = (Map<String, Integer>) propHash
1375 if (pph.get(ic) != null && pph.get(jc) != null)
1377 int icp = pph.get(ic).intValue(), jcp = pph.get(jc).intValue();
1378 // Still working on these definitions.
1379 propMatrixPos[i][j] += icp == jcp && icp > 0 ? 2 : 0;
1380 propMatrixPos[j][i] += icp == jcp && icp > 0 ? 2 : 0;
1381 propMatrixF[i][j] += icp == jcp ? 2 : 0;
1382 propMatrixF[j][i] += icp == jcp ? 2 : 0;
1383 propMatrixEpos[i][j] += icp == jcp ? (1 + icp * 2) : 0;
1384 propMatrixEpos[j][i] += icp == jcp ? (1 + icp * 2) : 0;
1387 if (maxF < propMatrixF[i][j])
1389 maxF = propMatrixF[i][j];
1391 if (maxP < propMatrixPos[i][j])
1393 maxP = propMatrixPos[i][j];
1395 if (maxEP < propMatrixEpos[i][j])
1397 maxEP = propMatrixEpos[i][j];
1400 propMatrixF[i][i] = maxF;
1401 propMatrixPos[i][i] = maxP;
1402 propMatrixEpos[i][i] = maxEP;
1404 // JAL-1512 comment out physicochemical score matrices for 2.8.1 release
1405 // scoreMatrices.put("Conservation Pos", new
1406 // ScoreMatrix("Conservation Pos",propMatrixPos,0));
1407 // scoreMatrices.put("Conservation Both", new
1408 // ScoreMatrix("Conservation Both",propMatrixF,0));
1409 // scoreMatrices.put("Conservation EnhPos", new
1410 // ScoreMatrix("Conservation EnhPos",propMatrixEpos,0));
1411 scoreMatrices.put("PID", new PIDScoreModel());
1412 scoreMatrices.put("Displayed Features", new FeatureScoreModel());
1415 private ResidueProperties()
1419 public static double getHydmax()
1424 public static double getHydmin()
1429 public static double[] getHyd()
1434 public static Map<String, Integer> getAA3Hash()
1439 public static int[][] getDNA()
1441 return ResidueProperties.DNA;
1444 public static int[][] getBLOSUM62()
1446 return ResidueProperties.BLOSUM62;
1449 public static int getPAM250(String A1, String A2)
1451 return getPAM250(A1.charAt(0), A2.charAt(0));
1454 public static int getBLOSUM62(char c1, char c2)
1460 int a = aaIndex[c1];
1461 int b = aaIndex[c2];
1463 pog = ResidueProperties.BLOSUM62[a][b];
1464 } catch (Exception e)
1466 // System.out.println("Unknown residue in " + A1 + " " + A2);
1472 public static Vector getCodons(String res)
1474 if (codonHash.containsKey(res))
1476 return (Vector) codonHash.get(res);
1482 public static String codonTranslate(String lccodon)
1486 return _codonTranslate(lccodon);
1488 String cdn = codonHash2.get(lccodon.toUpperCase());
1489 if ("*".equals(cdn))
1496 public static String _codonTranslate(String lccodon)
1498 String codon = lccodon.toUpperCase();
1499 // all base ambiguity codes yield an 'X' amino acid residue
1500 if (codon.indexOf('X') > -1 || codon.indexOf('N') > -1)
1504 for (String key : codonHash.keySet())
1506 if (codonHash.get(key).contains(codon))
1515 public static int[][] getDefaultPeptideMatrix()
1517 return ResidueProperties.getBLOSUM62();
1520 public static int[][] getDefaultDnaMatrix()
1522 return ResidueProperties.getDNA();
1526 * get a ScoreMatrix based on its string name
1529 * @return matrix in scoreMatrices with key pwtype or null
1531 public static ScoreMatrix getScoreMatrix(String pwtype)
1533 Object val = scoreMatrices.get(pwtype);
1534 if (val != null && val instanceof ScoreMatrix)
1536 return (ScoreMatrix) val;
1542 * get a ScoreModel based on its string name
1545 * @return scoremodel of type pwtype or null
1547 public static ScoreModelI getScoreModel(String pwtype)
1549 return scoreMatrices.get(pwtype);
1552 public static int getPAM250(char c, char d)
1557 int pog = ResidueProperties.PAM250[a][b];
1562 public static Hashtable toDssp3State;
1565 toDssp3State = new Hashtable();
1566 toDssp3State.put("H", "H");
1567 toDssp3State.put("E", "E");
1568 toDssp3State.put("C", " ");
1569 toDssp3State.put(" ", " ");
1570 toDssp3State.put("T", " ");
1571 toDssp3State.put("B", "E");
1572 toDssp3State.put("G", "H");
1573 toDssp3State.put("I", "H");
1574 toDssp3State.put("X", " ");
1578 * translate from other dssp secondary structure alphabets to 3-state
1581 * @return ssstring as a three-state secondary structure assignment.
1583 public static String getDssp3state(String ssstring)
1585 if (ssstring == null)
1589 StringBuffer ss = new StringBuffer();
1590 for (int i = 0; i < ssstring.length(); i++)
1592 String ssc = ssstring.substring(i, i + 1);
1593 if (toDssp3State.containsKey(ssc))
1595 ss.append((String) toDssp3State.get(ssc));
1602 return ss.toString();
1606 * Used by getRNASecStrucState
1609 public static Hashtable<String, String> toRNAssState;
1611 public static boolean RNAcloseParen[] = new boolean[255];
1614 toRNAssState = new Hashtable<String, String>();
1615 toRNAssState.put(")", "(");
1616 toRNAssState.put("(", "(");
1617 toRNAssState.put("]", "[");
1618 toRNAssState.put("[", "[");
1619 toRNAssState.put("{", "{");
1620 toRNAssState.put("}", "{");
1621 toRNAssState.put(">", ">");
1622 toRNAssState.put("<", ">");
1623 toRNAssState.put("A", "A");
1624 toRNAssState.put("a", "A");
1625 toRNAssState.put("B", "B");
1626 toRNAssState.put("b", "B");
1627 toRNAssState.put("C", "C");
1628 toRNAssState.put("c", "C");
1629 toRNAssState.put("D", "D");
1630 toRNAssState.put("d", "D");
1631 toRNAssState.put("E", "E");
1632 toRNAssState.put("e", "E");
1633 toRNAssState.put("F", "F");
1634 toRNAssState.put("f", "F");
1635 toRNAssState.put("G", "G");
1636 toRNAssState.put("g", "G");
1637 toRNAssState.put("H", "H");
1638 toRNAssState.put("h", "H");
1639 toRNAssState.put("I", "I");
1640 toRNAssState.put("i", "I");
1641 toRNAssState.put("J", "J");
1642 toRNAssState.put("j", "J");
1643 toRNAssState.put("K", "K");
1644 toRNAssState.put("k", "K");
1645 toRNAssState.put("L", "L");
1646 toRNAssState.put("l", "L");
1647 toRNAssState.put("M", "M");
1648 toRNAssState.put("m", "M");
1649 toRNAssState.put("N", "N");
1650 toRNAssState.put("n", "N");
1651 toRNAssState.put("O", "O");
1652 toRNAssState.put("o", "O");
1653 toRNAssState.put("P", "P");
1654 toRNAssState.put("p", "P");
1655 toRNAssState.put("Q", "Q");
1656 toRNAssState.put("q", "Q");
1657 toRNAssState.put("R", "R");
1658 toRNAssState.put("r", "R");
1659 toRNAssState.put("S", "S");
1660 toRNAssState.put("s", "S");
1661 toRNAssState.put("T", "T");
1662 toRNAssState.put("t", "T");
1663 toRNAssState.put("U", "U");
1664 toRNAssState.put("u", "U");
1665 toRNAssState.put("V", "V");
1666 toRNAssState.put("v", "V");
1667 toRNAssState.put("W", "W");
1668 toRNAssState.put("w", "W");
1669 toRNAssState.put("X", "X");
1670 toRNAssState.put("x", "X");
1671 toRNAssState.put("Y", "Y");
1672 toRNAssState.put("y", "Y");
1673 toRNAssState.put("Z", "Z");
1674 toRNAssState.put("z", "Z");
1675 for (int p = 0; p < RNAcloseParen.length; p++)
1677 RNAcloseParen[p] = false;
1679 for (String k : toRNAssState.keySet())
1681 RNAcloseParen[k.charAt(0)] = k.charAt(0) != toRNAssState.get(k)
1688 modifications.put("MSE", "MET"); // Selenomethionine
1689 // the rest tbc; from
1690 // http://sourceforge.net/p/jmol/mailman/message/12833570/
1691 // modifications.put("CSE", "CYS"); // Selenocysteine
1692 // modifications.put("PTR", "TYR"); // Phosphotyrosine
1693 // modifications.put("SEP", "SER"); // Phosphoserine
1694 // modifications.put("HYP", "PRO"); // 4-hydroxyproline
1695 // modifications.put("5HP", "GLU"); // Pyroglutamic acid; 5-hydroxyproline
1696 // modifications.put("PCA", "GLU"); // Pyroglutamic acid
1697 // modifications.put("LYZ", "LYS"); // 5-hydroxylysine
1700 public static String getCanonicalAminoAcid(String aa)
1702 String canonical = modifications.get(aa);
1703 return canonical == null ? aa : canonical;
1707 * translate to RNA secondary structure representation
1710 * @return ssstring as a RNA-state secondary structure assignment.
1712 public static String getRNASecStrucState(String ssstring)
1714 if (ssstring == null)
1718 StringBuffer ss = new StringBuffer();
1719 for (int i = 0; i < ssstring.length(); i++)
1721 String ssc = ssstring.substring(i, i + 1);
1722 if (toRNAssState.containsKey(ssc))
1724 // valid ss character - so return it
1725 ss.append(ssc); // (String) toRNAssState.get(ssc));
1732 return ss.toString();
1735 public static boolean isCloseParenRNA(char dc)
1737 return RNAcloseParen[dc];
1740 // main method generates perl representation of residue property hash
1742 public static void main(String[] args)
1744 Hashtable aa = new Hashtable();
1745 System.out.println("my %aa = {");
1746 // invert property hashes
1747 Enumeration prop = propHash.keys();
1748 while (prop.hasMoreElements())
1750 String pname = (String) prop.nextElement();
1751 Hashtable phash = (Hashtable) propHash.get(pname);
1752 Enumeration res = phash.keys();
1753 while (res.hasMoreElements())
1755 String rname = (String) res.nextElement();
1756 Vector aprops = (Vector) aa.get(rname);
1759 aprops = new Vector();
1760 aa.put(rname, aprops);
1762 Integer hasprop = (Integer) phash.get(rname);
1763 if (hasprop.intValue() == 1)
1765 aprops.addElement(pname);
1769 Enumeration res = aa.keys();
1770 while (res.hasMoreElements())
1772 String rname = (String) res.nextElement();
1774 System.out.print("'" + rname + "' => [");
1775 Enumeration props = ((Vector) aa.get(rname)).elements();
1776 while (props.hasMoreElements())
1778 System.out.print("'" + (String) props.nextElement() + "'");
1779 if (props.hasMoreElements())
1781 System.out.println(", ");
1784 System.out.println("]" + (res.hasMoreElements() ? "," : ""));
1786 System.out.println("};");
1792 * Returns a list of residue characters for the specified inputs
1795 * @param includeAmbiguous
1798 public static List<String> getResidues(boolean nucleotide,
1799 boolean includeAmbiguous)
1801 List<String> result = new ArrayList<String>();
1804 for (String nuc : nucleotideName.keySet())
1806 int val = nucleotideIndex[nuc.charAt(0)];
1807 if ((!includeAmbiguous && val > 4) || (val >= maxNucleotideIndex))
1811 nuc = nuc.toUpperCase();
1812 if (!result.contains(nuc))
1823 for (String res : aa3Hash.keySet())
1825 int index = aa3Hash.get(res).intValue();
1826 if ((!includeAmbiguous && index >= 20) || index >= maxProteinIndex)
1830 res = res.toUpperCase();
1831 if (!result.contains(res))
1842 * Returns the single letter code for a three letter code, or '0' if not known
1844 * @param threeLetterCode
1845 * not case sensitive
1848 public static char getSingleCharacterCode(String threeLetterCode)
1850 if (threeLetterCode == null)
1854 Integer index = ResidueProperties.aa3Hash.get(threeLetterCode
1856 return index == null ? '0' : aa[index].charAt(0);