Sequence is char []
[jalview.git] / src / jalview / schemes / ResidueProperties.java
index 14479a7..1015073 100755 (executable)
@@ -1,6 +1,6 @@
 /*\r
  * Jalview - A Sequence Alignment Editor and Viewer\r
- * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+ * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
  *\r
  * This program is free software; you can redistribute it and/or\r
  * modify it under the terms of the GNU General Public License\r
@@ -25,85 +25,124 @@ import java.awt.*;
 public class ResidueProperties\r
 {\r
   //Stores residue codes/names and colours and other things\r
-  public static Hashtable aaHash = new Hashtable(); // stores the number value of the aa\r
-  public static Hashtable aa3Hash = new Hashtable();\r
-  public static Hashtable aa2Triplet = new Hashtable();\r
-  public static Hashtable nucleotideHash = new Hashtable();\r
+  public static final int [] aaIndex; // aaHash version 2.1.1 and below\r
+  public static final int [] nucleotideIndex;\r
+  public static final Hashtable aa3Hash = new Hashtable();\r
+  public static final Hashtable aa2Triplet = new Hashtable();\r
+  public static final Hashtable nucleotideName = new Hashtable();\r
 \r
-  static\r
-  {\r
-    aaHash.put("A", new Integer(0));\r
-    aaHash.put("R", new Integer(1));\r
-    aaHash.put("N", new Integer(2));\r
-    aaHash.put("D", new Integer(3));\r
-    aaHash.put("C", new Integer(4));\r
-    aaHash.put("Q", new Integer(5));\r
-    aaHash.put("E", new Integer(6));\r
-    aaHash.put("G", new Integer(7));\r
-    aaHash.put("H", new Integer(8));\r
-    aaHash.put("I", new Integer(9));\r
-    aaHash.put("L", new Integer(10));\r
-    aaHash.put("K", new Integer(11));\r
-    aaHash.put("M", new Integer(12));\r
-    aaHash.put("F", new Integer(13));\r
-    aaHash.put("P", new Integer(14));\r
-    aaHash.put("S", new Integer(15));\r
-    aaHash.put("T", new Integer(16));\r
-    aaHash.put("W", new Integer(17));\r
-    aaHash.put("Y", new Integer(18));\r
-    aaHash.put("V", new Integer(19));\r
-    aaHash.put("B", new Integer(20));\r
-    aaHash.put("Z", new Integer(21));\r
-    aaHash.put("X", new Integer(22));\r
-    aaHash.put("a", new Integer(0));\r
-    aaHash.put("r", new Integer(1));\r
-    aaHash.put("n", new Integer(2));\r
-    aaHash.put("d", new Integer(3));\r
-    aaHash.put("c", new Integer(4));\r
-    aaHash.put("q", new Integer(5));\r
-    aaHash.put("e", new Integer(6));\r
-    aaHash.put("g", new Integer(7));\r
-    aaHash.put("h", new Integer(8));\r
-    aaHash.put("i", new Integer(9));\r
-    aaHash.put("l", new Integer(10));\r
-    aaHash.put("k", new Integer(11));\r
-    aaHash.put("m", new Integer(12));\r
-    aaHash.put("f", new Integer(13));\r
-    aaHash.put("p", new Integer(14));\r
-    aaHash.put("s", new Integer(15));\r
-    aaHash.put("t", new Integer(16));\r
-    aaHash.put("w", new Integer(17));\r
-    aaHash.put("y", new Integer(18));\r
-    aaHash.put("v", new Integer(19));\r
-    aaHash.put("b", new Integer(20));\r
-    aaHash.put("z", new Integer(21));\r
-    aaHash.put("x", new Integer(22));\r
-    aaHash.put("-", new Integer(23));\r
-    aaHash.put("*", new Integer(23));\r
-    aaHash.put(".", new Integer(23));\r
-    aaHash.put(" ", new Integer(23));\r
-  }\r
 \r
   static\r
   {\r
-    nucleotideHash.put("A", new Integer(0));\r
-    nucleotideHash.put("C", new Integer(1));\r
-    nucleotideHash.put("G", new Integer(2));\r
-    nucleotideHash.put("T", new Integer(3));\r
-    nucleotideHash.put("U", new Integer(4));\r
+    aaIndex = new int[132];\r
+    for(int i=0; i<132; i++)\r
+      aaIndex[i] = -1;\r
+\r
+    aaIndex['A'] = 0;\r
+    aaIndex['R'] = 1;\r
+    aaIndex['N'] = 2;\r
+    aaIndex['D'] = 3;\r
+    aaIndex['C'] = 4;\r
+    aaIndex['Q'] = 5;\r
+    aaIndex['E'] = 6;\r
+    aaIndex['G'] = 7;\r
+    aaIndex['H'] = 8;\r
+    aaIndex['I'] = 9;\r
+    aaIndex['L'] = 10;\r
+    aaIndex['K'] = 11;\r
+    aaIndex['M'] = 12;\r
+    aaIndex['F'] = 13;\r
+    aaIndex['P'] = 14;\r
+    aaIndex['S'] = 15;\r
+    aaIndex['T'] = 16;\r
+    aaIndex['W'] = 17;\r
+    aaIndex['Y'] = 18;\r
+    aaIndex['V'] = 19;\r
+    aaIndex['B'] = 20;\r
+    aaIndex['Z'] = 21;\r
+    aaIndex['X'] = 22;\r
+    aaIndex['U'] = 22;\r
+    aaIndex['a'] = 0;\r
+    aaIndex['r'] = 1;\r
+    aaIndex['n'] = 2;\r
+    aaIndex['d'] = 3;\r
+    aaIndex['c'] = 4;\r
+    aaIndex['q'] = 5;\r
+    aaIndex['e'] = 6;\r
+    aaIndex['g'] = 7;\r
+    aaIndex['h'] = 8;\r
+    aaIndex['i'] = 9;\r
+    aaIndex['l'] = 10;\r
+    aaIndex['k'] = 11;\r
+    aaIndex['m'] = 12;\r
+    aaIndex['f'] = 13;\r
+    aaIndex['p'] = 14;\r
+    aaIndex['s'] = 15;\r
+    aaIndex['t'] = 16;\r
+    aaIndex['w'] = 17;\r
+    aaIndex['y'] = 18;\r
+    aaIndex['v'] = 19;\r
+    aaIndex['b'] = 20;\r
+    aaIndex['z'] = 21;\r
+    aaIndex['x'] = 22;\r
+    aaIndex['u'] = 22;\r
+    aaIndex['-'] = 23;\r
+    aaIndex['*'] = 23;\r
+    aaIndex['.'] = 23;\r
+    aaIndex[' '] = 23;\r
   }\r
 \r
-  // These numbers should correspond to the indices in the Color hashes\r
-  public static Hashtable aaSpecialsHash = new Hashtable();\r
-\r
   static\r
   {\r
-    aaSpecialsHash.put("-", new Integer(23));\r
-    aaSpecialsHash.put("*", new Integer(24));\r
-    aaSpecialsHash.put(".", new Integer(25));\r
-    aaSpecialsHash.put(" ", new Integer(26));\r
+    nucleotideIndex = new int[132];\r
+    for (int i = 0; i < 132; i++)\r
+      nucleotideIndex[i] = -1;\r
+\r
+    nucleotideIndex['A'] = 0;\r
+    nucleotideIndex['a'] = 0;\r
+    nucleotideIndex['C'] = 1;\r
+    nucleotideIndex['c'] = 1;\r
+    nucleotideIndex['G'] = 2;\r
+    nucleotideIndex['g'] = 2;\r
+    nucleotideIndex['T'] = 3;\r
+    nucleotideIndex['t'] = 3;\r
+    nucleotideIndex['U'] = 4;\r
+    nucleotideIndex['u'] = 4;\r
+    nucleotideIndex['I'] = 5;\r
+    nucleotideIndex['i'] = 5;\r
+    nucleotideIndex['X'] = 6;\r
+    nucleotideIndex['x'] = 6;\r
+    nucleotideIndex['R'] = 7;\r
+    nucleotideIndex['r'] = 7;\r
+    nucleotideIndex['Y'] = 8;\r
+    nucleotideIndex['y'] = 8;\r
+    nucleotideIndex['N'] = 9;\r
+    nucleotideIndex['n'] = 9;\r
+\r
+\r
+    nucleotideName.put("A", "Adenine");\r
+    nucleotideName.put("a", "Adenine");\r
+    nucleotideName.put("G", "Guanine");\r
+    nucleotideName.put("g", "Guanine");\r
+    nucleotideName.put("C", "Cytosine");\r
+    nucleotideName.put("c", "Cytosine");\r
+    nucleotideName.put("T", "Thymine");\r
+    nucleotideName.put("t", "Thymine");\r
+    nucleotideName.put("U", "Uracil");\r
+    nucleotideName.put("u", "Uracil");\r
+    nucleotideName.put("I", "Inosine");\r
+    nucleotideName.put("i", "Inosine");\r
+    nucleotideName.put("X", "Xanthine");\r
+    nucleotideName.put("x", "Xanthine");\r
+    nucleotideName.put("R", "Unknown Purine");\r
+    nucleotideName.put("r", "Unknown Purine");\r
+    nucleotideName.put("Y", "Unknown Pyrimidine");\r
+    nucleotideName.put("y", "Unknown Pyrimidine");\r
+    nucleotideName.put("N", "Unknown");\r
+    nucleotideName.put("n", "Unknown");\r
   }\r
 \r
+\r
   static\r
   {\r
     aa3Hash.put("ALA", new Integer(0));\r
@@ -126,46 +165,68 @@ public class ResidueProperties
     aa3Hash.put("TRP", new Integer(17));\r
     aa3Hash.put("TYR", new Integer(18));\r
     aa3Hash.put("VAL", new Integer(19));\r
-    aa3Hash.put("B", new Integer(20));\r
-    aa3Hash.put("Z", new Integer(21));\r
-    aa3Hash.put("X", new Integer(22));\r
+    // IUB Nomenclature for ambiguous peptides\r
+    aa3Hash.put("ASX", new Integer(20)); // "B";\r
+    aa3Hash.put("GLX", new Integer(21)); // X\r
+    aa3Hash.put("XAA", new Integer(22));// X unknown\r
     aa3Hash.put("-", new Integer(23));\r
     aa3Hash.put("*", new Integer(23));\r
     aa3Hash.put(".", new Integer(23));\r
     aa3Hash.put(" ", new Integer(23));\r
+    aa3Hash.put("Gap", new Integer(23));\r
   }\r
 \r
   static\r
   {\r
     aa2Triplet.put("A", "ALA");\r
+    aa2Triplet.put("a", "ALA");\r
     aa2Triplet.put("R", "ARG");\r
+    aa2Triplet.put("r", "ARG");\r
     aa2Triplet.put("N", "ASN");\r
+    aa2Triplet.put("n", "ASN");\r
     aa2Triplet.put("D", "ASP");\r
+    aa2Triplet.put("d", "ASP");\r
     aa2Triplet.put("C", "CYS");\r
+    aa2Triplet.put("c", "CYS");\r
     aa2Triplet.put("Q", "GLN");\r
+    aa2Triplet.put("q", "GLN");\r
     aa2Triplet.put("E", "GLU");\r
+    aa2Triplet.put("e", "GLU");\r
     aa2Triplet.put("G", "GLY");\r
+    aa2Triplet.put("g", "GLY");\r
     aa2Triplet.put("H", "HIS");\r
+    aa2Triplet.put("h", "HIS");\r
     aa2Triplet.put("I", "ILE");\r
+    aa2Triplet.put("i", "ILE");\r
     aa2Triplet.put("L", "LEU");\r
+    aa2Triplet.put("l", "LEU");\r
     aa2Triplet.put("K", "LYS");\r
+    aa2Triplet.put("k", "LYS");\r
     aa2Triplet.put("M", "MET");\r
+    aa2Triplet.put("m", "MET");\r
     aa2Triplet.put("F", "PHE");\r
+    aa2Triplet.put("f", "PHE");\r
     aa2Triplet.put("P", "PRO");\r
+    aa2Triplet.put("p", "PRO");\r
     aa2Triplet.put("S", "SER");\r
+    aa2Triplet.put("s", "SER");\r
     aa2Triplet.put("T", "THR");\r
+    aa2Triplet.put("t", "THR");\r
     aa2Triplet.put("W", "TRP");\r
+    aa2Triplet.put("w", "TRP");\r
     aa2Triplet.put("Y", "TYR");\r
+    aa2Triplet.put("y", "TYR");\r
     aa2Triplet.put("V", "VAL");\r
+    aa2Triplet.put("v", "VAL");\r
   }\r
 \r
-  public static String[] aa =\r
+  public static final String[] aa =\r
       {\r
       "A", "R", "N", "D", "C", "Q", "E", "G", "H", "I", "L", "K", "M", "F",\r
       "P", "S", "T", "W", "Y", "V", "B", "Z", "X", "_", "*", ".", " "\r
   };\r
-  public static Color midBlue = new Color(100, 100, 255);\r
-  public static Vector scaleColours = new Vector();\r
+  public static final Color midBlue = new Color(100, 100, 255);\r
+  public static final Vector scaleColours = new Vector();\r
 \r
   static\r
   {\r
@@ -181,7 +242,7 @@ public class ResidueProperties
     scaleColours.addElement(Color.white);\r
   }\r
 \r
-  public static Color[] taylor =\r
+  public static final Color[] taylor =\r
       {\r
       new Color(204, 255, 0), // A  Greenish-yellowy-yellow\r
       new Color(0, 0, 255), // R  Blueish-bluey-blue\r
@@ -210,7 +271,7 @@ public class ResidueProperties
       Color.white, // *\r
       Color.white // .\r
   };\r
-  public static Color[] nucleotide =\r
+  public static final Color[] nucleotide =\r
       {\r
       new Color(100, 247, 63), // A\r
       new Color(255, 179, 64), // C\r
@@ -218,7 +279,7 @@ public class ResidueProperties
       new Color(60, 136, 238), // T\r
       new Color(60, 136, 238) // U\r
   };\r
-  public static Color[] color =\r
+  public static final Color[] color =\r
       {\r
       Color.pink, // A\r
       midBlue, // R\r
@@ -250,7 +311,7 @@ public class ResidueProperties
   };\r
 \r
   // Dunno where I got these numbers from\r
-  public static double[] hyd2 =\r
+  public static final double[] hyd2 =\r
       {\r
       0.62, //A\r
       0.29, //R\r
@@ -276,39 +337,39 @@ public class ResidueProperties
       0.0, //Z\r
       0.0 //X\r
   };\r
-  public static double[] helix =\r
+  public static final double[] helix =\r
       {\r
       1.42, 0.98, 0.67, 1.01, 0.70, 1.11, 1.51, 0.57, 1.00, 1.08, 1.21, 1.16,\r
       1.45, 1.13, 0.57, 0.77, 0.83, 1.08, 0.69, 1.06, 0.84, 1.31, 1.00, 0.0\r
   };\r
-  public static double helixmin = 0.57;\r
-  public static double helixmax = 1.51;\r
-  public static double[] strand =\r
+  public static final double helixmin = 0.57;\r
+  public static final double helixmax = 1.51;\r
+  public static final double[] strand =\r
       {\r
       0.83, 0.93, 0.89, 0.54, 1.19, 1.10, 0.37, 0.75, 0.87, 1.60, 1.30, 0.74,\r
       1.05, 1.38, 0.55, 0.75, 1.19, 1.37, 1.47, 1.70, 0.72, 0.74, 1.0, 0.0\r
   };\r
-  public static double strandmin = 0.37;\r
-  public static double strandmax = 1.7;\r
-  public static double[] turn =\r
+  public static final double strandmin = 0.37;\r
+  public static final double strandmax = 1.7;\r
+  public static final double[] turn =\r
       {\r
       0.66, 0.95, 1.56, 1.46, 1.19, 0.98, 0.74, 1.56, 0.95, 0.47, 0.59, 1.01,\r
       0.60, 0.60, 1.52, 1.43, 0.96, 0.96, 1.14, 0.50, 1.51, 0.86, 1.00, 0, 0\r
   };\r
-  public static double turnmin = 0.47;\r
-  public static double turnmax = 1.56;\r
-  public static double[] buried =\r
+  public static final double turnmin = 0.47;\r
+  public static final double turnmax = 1.56;\r
+  public static final double[] buried =\r
       {\r
       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,\r
       0.6, 0.8, 0.7, 1.6, 0.5, 2.9, 0.4, 0.3, 1.358, 0.00\r
   };\r
-  public static double buriedmin = 0.05;\r
-  public static double buriedmax = 4.6;\r
+  public static final double buriedmin = 0.05;\r
+  public static final double buriedmax = 4.6;\r
 \r
   // This is hydropathy index\r
   // Kyte, J., and Doolittle, R.F., J. Mol. Biol.\r
   // 1157, 105-132, 1982\r
-  public static double[] hyd =\r
+  public static final double[] hyd =\r
       {\r
       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,\r
       2.8, -1.6, -0.8, -0.7, -0.9, -1.3, 4.2, -3.5, -3.5, -0.49, 0.0\r
@@ -516,7 +577,7 @@ public class ResidueProperties
       -8, -8, -8, -8, -8, -8, 1\r
   },\r
   };\r
-  public static Hashtable ssHash = new Hashtable(); // stores the number value of the aa\r
+  public static final Hashtable ssHash = new Hashtable(); // stores the number value of the aa\r
 \r
   static\r
   {\r
@@ -544,13 +605,13 @@ public class ResidueProperties
       {\r
       1, 1, 1, 1, 1}, // -\r
   };\r
-  public static Color[] pidColours =\r
+  public static final Color[] pidColours =\r
       {\r
       midBlue, new Color(153, 153, 255),\r
       //    Color.lightGray,\r
       new Color(204, 204, 255),\r
   };\r
-  public static float[] pidThresholds =\r
+  public static final float[] pidThresholds =\r
       {\r
       80, 60, 40, };\r
   public static Hashtable codonHash = new Hashtable();\r
@@ -773,27 +834,6 @@ public class ResidueProperties
     Phe.addElement("TTT");\r
   }\r
 \r
-  public static Color[][] groupColors =\r
-      {\r
-      {\r
-      Color.red, Color.red.brighter(), Color.red.brighter().brighter()},\r
-      {\r
-      Color.orange, Color.orange.brighter(),\r
-      Color.orange.brighter().brighter()\r
-  },\r
-      {\r
-      Color.green, Color.green.brighter(), Color.green.brighter().brighter()},\r
-      {\r
-      Color.blue, Color.blue.brighter(), Color.blue.brighter().brighter()},\r
-      {\r
-      Color.magenta, Color.magenta.brighter(),\r
-      Color.magenta.brighter().brighter()\r
-  },\r
-      {\r
-      Color.cyan, Color.cyan.brighter(), Color.cyan.brighter().brighter()},\r
-      {\r
-      Color.pink, Color.pink.brighter(), Color.pink.brighter().brighter()},\r
-  };\r
 \r
   //Stores residue codes/names and colours and other things\r
   public static Hashtable propHash = new Hashtable();\r
@@ -1084,20 +1124,6 @@ public class ResidueProperties
     propHash.put("polar", polar);\r
   }\r
 \r
-  public static Hashtable chainColours = new Hashtable();\r
-\r
-  static\r
-  {\r
-    chainColours.put("A", Color.red);\r
-    chainColours.put("B", Color.orange);\r
-    chainColours.put("C", Color.yellow);\r
-    chainColours.put("D", Color.green);\r
-    chainColours.put("E", Color.cyan);\r
-    chainColours.put("F", Color.blue);\r
-    chainColours.put("G", Color.magenta);\r
-    chainColours.put("H", Color.pink);\r
-  }\r
-\r
   private ResidueProperties()\r
   {\r
   }\r
@@ -1117,11 +1143,6 @@ public class ResidueProperties
     return hyd;\r
   }\r
 \r
-  public static Hashtable getAAHash()\r
-  {\r
-    return aaHash;\r
-  }\r
-\r
   public static Hashtable getAA3Hash()\r
   {\r
     return aa3Hash;\r
@@ -1139,22 +1160,24 @@ public class ResidueProperties
 \r
   public static int getPAM250(String A1, String A2)\r
   {\r
-    Integer pog1 = (Integer) aaHash.get(A1);\r
-    Integer pog2 = (Integer) aaHash.get(A2);\r
-    int pog = ResidueProperties.PAM250[pog1.intValue()][pog2.intValue()];\r
+    int a = aaIndex[A1.charAt(0)];\r
+    int b = aaIndex[A2.charAt(0)];\r
+\r
+    int pog = ResidueProperties.PAM250[a][b];\r
 \r
     return pog;\r
   }\r
 \r
-  public static int getBLOSUM62(String A1, String A2)\r
+  public static int getBLOSUM62(char c1, char c2)\r
   {\r
     int pog = 0;\r
 \r
     try\r
     {\r
-      Integer pog1 = (Integer) aaHash.get(A1);\r
-      Integer pog2 = (Integer) aaHash.get(A2);\r
-      pog = ResidueProperties.BLOSUM62[pog1.intValue()][pog2.intValue()];\r
+      int a = aaIndex[c1];\r
+      int b = aaIndex[c2];\r
+\r
+      pog = ResidueProperties.BLOSUM62[a][b];\r
     }\r
     catch (Exception e)\r
     {\r
@@ -1183,7 +1206,7 @@ public class ResidueProperties
       String key = (String) e.nextElement();\r
       Vector tmp = (Vector) codonHash.get(key);\r
 \r
-      if (tmp.contains(codon))\r
+      if (tmp.contains(codon.toUpperCase()))\r
       {\r
         return key;\r
       }\r
@@ -1191,9 +1214,4 @@ public class ResidueProperties
 \r
     return null;\r
   }\r
-\r
-  public static Hashtable getChainColours()\r
-  {\r
-    return chainColours;\r
-  }\r
 }\r