aaIndex replaces aaHash
[jalview.git] / src / jalview / schemes / ResidueProperties.java
index f92bfd1..4699dc6 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,90 +25,124 @@ import java.awt.*;
 public class ResidueProperties\r
 {\r
   //Stores residue codes/names and colours and other things\r
-  public static final Hashtable aaHash = new Hashtable(); // stores the number value of the aa\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 nucleotideHash = 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
-    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 final 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
@@ -131,13 +165,15 @@ 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
@@ -798,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
@@ -1109,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
@@ -1142,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
@@ -1164,9 +1160,10 @@ 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
@@ -1177,9 +1174,10 @@ public class ResidueProperties
 \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[A1.charAt(0)];\r
+      int b = aaIndex[A2.charAt(0)];\r
+\r
+      pog = ResidueProperties.BLOSUM62[a][b];\r
     }\r
     catch (Exception e)\r
     {\r
@@ -1208,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
@@ -1216,9 +1214,4 @@ public class ResidueProperties
 \r
     return null;\r
   }\r
-\r
-  public static Hashtable getChainColours()\r
-  {\r
-    return chainColours;\r
-  }\r
 }\r