aaIndex replaces aaHash
authoramwaterhouse <Andrew Waterhouse>
Tue, 10 Oct 2006 10:28:05 +0000 (10:28 +0000)
committeramwaterhouse <Andrew Waterhouse>
Tue, 10 Oct 2006 10:28:05 +0000 (10:28 +0000)
13 files changed:
src/jalview/analysis/AlignSeq.java
src/jalview/datamodel/BinarySequence.java
src/jalview/gui/UserDefinedColours.java
src/jalview/io/AlignFile.java
src/jalview/schemes/Blosum62ColourScheme.java
src/jalview/schemes/ClustalxColourScheme.java
src/jalview/schemes/Consensus.java
src/jalview/schemes/NucleotideColourScheme.java
src/jalview/schemes/PIDColourScheme.java
src/jalview/schemes/ResidueColourScheme.java
src/jalview/schemes/ResidueProperties.java
src/jalview/schemes/ScoreColourScheme.java
src/jalview/schemes/UserColourScheme.java

index 9b4dfef..0af85f1 100755 (executable)
@@ -751,17 +751,24 @@ public class AlignSeq
 \r
         for (int i = 0; i < s.length(); i++)\r
         {\r
-            String ss = s.substring(i, i + 1).toUpperCase();\r
+           // String ss = s.substring(i, i + 1).toUpperCase();\r
+            char c = s.charAt(i);\r
+            if ('a' <= c && c <= 'z')\r
+            {\r
+              // TO UPPERCASE !!!\r
+              c -= ('a' - 'A');\r
+            }\r
+\r
 \r
             try\r
             {\r
                 if (type.equals("pep"))\r
                 {\r
-                    seq1[i] = ((Integer) ResidueProperties.aaHash.get(ss)).intValue();\r
+                    seq1[i] = ResidueProperties.aaIndex[c];\r
                 }\r
                 else if (type.equals("dna"))\r
                 {\r
-                    seq1[i] = ((Integer) dnaHash.get(ss)).intValue();\r
+                    seq1[i] = ResidueProperties.nucleotideIndex[c];\r
                 }\r
 \r
                 if (seq1[i] > 23)\r
index 423e401..af10e1d 100755 (executable)
@@ -64,9 +64,7 @@ public class BinarySequence extends Sequence
 \r
             try\r
             {\r
-                aanum = ((Integer) ResidueProperties.getAAHash().get(getSequence()\r
-                                                                         .substring(i,\r
-                            i + 1))).intValue();\r
+                aanum = ResidueProperties.aaIndex[getSequence().charAt(i)];\r
             }\r
             catch (NullPointerException e)\r
             {\r
@@ -101,9 +99,7 @@ public class BinarySequence extends Sequence
 \r
             try\r
             {\r
-                aanum = ((Integer) ResidueProperties.getAAHash().get(getSequence()\r
-                                                                         .substring(i,\r
-                            i + 1))).intValue();\r
+                aanum = ResidueProperties.aaIndex[getSequence().charAt(i)];\r
             }\r
             catch (NullPointerException e)\r
             {\r
index d2741a9..86c39f9 100755 (executable)
@@ -583,7 +583,7 @@ public class UserDefinedColours extends GUserDefinedColours
               }\r
               else\r
               {\r
-                index = ((Integer)ResidueProperties.aaHash.get(name)).intValue();\r
+                index = ResidueProperties.aaIndex[name.charAt(0)];\r
               }\r
               if(index == -1)\r
                 continue;\r
index df9d535..0691d82 100755 (executable)
@@ -114,8 +114,7 @@ public abstract class AlignFile extends FileParse
     protected boolean isValidProteinSequence(String sequence)\r
     {\r
         for (int i = 0; i < sequence.length(); i++)\r
-            if (!jalview.schemes.ResidueProperties.aaHash.containsKey(\r
-                        String.valueOf(sequence.charAt(i))))\r
+            if (jalview.schemes.ResidueProperties.aaIndex[sequence.charAt(i)]==-1)\r
             {\r
                 invalidCharacter = sequence.charAt(i);\r
                 return false;\r
index ef6fbb7..ec5d4f1 100755 (executable)
@@ -20,6 +20,7 @@ package jalview.schemes;
 \r
 \r
 import java.awt.*;\r
+import jalview.analysis.AAFrequency;\r
 \r
 public class Blosum62ColourScheme\r
     extends ResidueColourScheme\r
@@ -38,15 +39,17 @@ public class Blosum62ColourScheme
        s = String.valueOf( res -= ('a' - 'A') );\r
     }\r
 \r
-\r
-    if ( j>=consensus.length || (threshold != 0 && !aboveThreshold(s, j) ))\r
+    if (consensus == null ||\r
+        j >= consensus.length ||\r
+        consensus[j] == null ||\r
+        (threshold != 0 && !aboveThreshold(s, j)))\r
     {\r
       return Color.white;\r
     }\r
 \r
     if (!jalview.util.Comparison.isGap( res ))\r
     {\r
-      String max = (String) consensus[j].get("maxResidue");\r
+      String max = (String) consensus[j].get(AAFrequency.MAXRESIDUE);\r
 \r
       if (max.indexOf(s) > -1)\r
       {\r
index 9bc76c2..04610ef 100755 (executable)
@@ -86,8 +86,7 @@ public class ClustalxColourScheme
         }\r
         else\r
         {\r
-          res = ( (Integer) ResidueProperties.aaHash.get(seq.charAt(i) +\r
-              "")).intValue();\r
+          res =  ResidueProperties.aaIndex[seq.charAt(i)];\r
         }\r
 \r
         cons2[i][res]++;\r
@@ -258,7 +257,7 @@ public class ClustalxColourScheme
       return Color.white;\r
     }\r
 \r
-    int i = ( (Integer) ResidueProperties.aaHash.get(s)).intValue();\r
+    int i = ResidueProperties.aaIndex[s.charAt(0)];\r
 \r
     currentColour = Color.white;\r
 \r
index 92dde08..520196f 100755 (executable)
@@ -70,8 +70,7 @@ public class Consensus
 \r
     while (i < s.length())\r
     {\r
-      out[i] = ( (Integer) ResidueProperties.aaHash.get(s.substring(i,\r
-          i + 1))).intValue();\r
+      out[i] = ResidueProperties.aaIndex[s.charAt(i)];\r
       i++;\r
     }\r
 \r
index 9768d9a..6aaef7d 100755 (executable)
@@ -47,7 +47,7 @@ public class NucleotideColourScheme extends ResidueColourScheme
     public Color findColour(String n)\r
     {\r
         // System.out.println("called"); log.debug\r
-        return colors[((Integer) (ResidueProperties.nucleotideHash.get(n))).intValue()];\r
+        return colors[ResidueProperties.nucleotideIndex[n.charAt(0)]];\r
     }\r
 \r
     /**\r
@@ -64,7 +64,7 @@ public class NucleotideColourScheme extends ResidueColourScheme
         {\r
             try\r
             {\r
-                currentColour = colors[((Integer) (ResidueProperties.nucleotideHash.get(n))).intValue()];\r
+                currentColour = colors[ ResidueProperties.nucleotideIndex[n.charAt(0)]];\r
             }\r
             catch (Exception ex)\r
             {\r
index a79f083..e09745a 100755 (executable)
@@ -21,6 +21,7 @@ package jalview.schemes;
 import java.awt.*;\r
 \r
 import jalview.datamodel.*;\r
+import jalview.analysis.AAFrequency;\r
 \r
 public class PIDColourScheme\r
     extends ResidueColourScheme\r
@@ -56,7 +57,7 @@ public class PIDColourScheme
     if(consensus.length<=j)\r
       return Color.white;\r
 \r
-      if ( (Integer.parseInt(consensus[j].get("maxCount").toString()) != -1) &&\r
+      if ( (Integer.parseInt(consensus[j].get(AAFrequency.MAXCOUNT).toString()) != -1) &&\r
           consensus[j].contains(s))\r
       {\r
         sc = ( (Float) consensus[j].get(ignoreGaps)).floatValue();\r
index a993802..7c36208 100755 (executable)
@@ -41,7 +41,7 @@ public class ResidueColourScheme implements ColourSchemeI
     int threshold = 0;\r
 \r
     /* Set when threshold colouring to either pid_gaps or pid_nogaps*/\r
-    protected String ignoreGaps = "pid_gaps";\r
+    protected String ignoreGaps = AAFrequency.PID_GAPS;\r
 \r
     /** Consenus as a hashtable array */\r
     Hashtable [] consensus;\r
@@ -83,7 +83,7 @@ public class ResidueColourScheme implements ColourSchemeI
     */\r
    public Color findColour(String aa)\r
    {\r
-       return colors[((Integer) (ResidueProperties.aaHash.get(aa))).intValue()];\r
+       return colors[ResidueProperties.aaIndex[aa.charAt(0)]];\r
    }\r
 \r
 \r
@@ -91,7 +91,7 @@ public class ResidueColourScheme implements ColourSchemeI
    public Color findColour(String s, int j)\r
    {\r
 \r
-       int index = ((Integer) (ResidueProperties.aaHash.get(s))).intValue();\r
+       int index = ResidueProperties.aaIndex[s.charAt(0)];\r
 \r
        if ((threshold == 0) || aboveThreshold(ResidueProperties.aa[index], j))\r
        {\r
@@ -129,9 +129,9 @@ public class ResidueColourScheme implements ColourSchemeI
     {\r
         threshold = ct;\r
         if(ignoreGaps)\r
-          this.ignoreGaps = "pid_nogaps";\r
+          this.ignoreGaps = AAFrequency.PID_NOGAPS;\r
         else\r
-          this.ignoreGaps = "pid_gaps";\r
+          this.ignoreGaps = AAFrequency.PID_GAPS;\r
     }\r
 \r
     /**\r
@@ -154,7 +154,7 @@ public class ResidueColourScheme implements ColourSchemeI
         }\r
 \r
 \r
-      if ((((Integer) consensus[j].get("maxCount")).intValue() != -1) &&\r
+      if ((((Integer) consensus[j].get(AAFrequency.MAXCOUNT)).intValue() != -1) &&\r
                 consensus[j].contains(s))\r
         {\r
             if (((Float)consensus[j].get(ignoreGaps)).floatValue() >= threshold)\r
index 87efddc..4699dc6 100755 (executable)
@@ -25,90 +25,99 @@ 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
+\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("U", 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("u", 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
+    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
   static\r
   {\r
-    nucleotideHash.put("A", new Integer(0));\r
-    nucleotideHash.put("a", new Integer(0));\r
-    nucleotideHash.put("C", new Integer(1));\r
-    nucleotideHash.put("c", new Integer(1));\r
-    nucleotideHash.put("G", new Integer(2));\r
-    nucleotideHash.put("g", new Integer(2));\r
-    nucleotideHash.put("T", new Integer(3));\r
-    nucleotideHash.put("t", new Integer(3));\r
-    nucleotideHash.put("U", new Integer(4));\r
-    nucleotideHash.put("u", new Integer(4));\r
-    nucleotideHash.put("I", new Integer(5));\r
-    nucleotideHash.put("i", new Integer(5));\r
-    nucleotideHash.put("X", new Integer(6));\r
-    nucleotideHash.put("x", new Integer(6));\r
-    nucleotideHash.put("R", new Integer(7));\r
-    nucleotideHash.put("r", new Integer(7));\r
-    nucleotideHash.put("Y", new Integer(8));\r
-    nucleotideHash.put("y", new Integer(8));\r
-    nucleotideHash.put("N", new Integer(9));\r
-    nucleotideHash.put("n", new Integer(9));\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
@@ -1134,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
@@ -1156,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
@@ -1169,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
index e238d79..8d7a45a 100755 (executable)
@@ -99,7 +99,7 @@ public class ScoreColourScheme extends ResidueColourScheme
             return Color.white;\r
         }\r
 \r
-        currentColour = colors[((Integer) ResidueProperties.aaHash.get(s)).intValue()];\r
+        currentColour = colors[ ResidueProperties.aaIndex[s.charAt(0)] ];\r
 \r
         if(conservationColouring)\r
          applyConservation(j);\r
index bd70c5d..007d358 100755 (executable)
@@ -147,12 +147,10 @@ public class UserColourScheme
         {\r
           token = st2.nextToken();\r
 \r
-          if (ResidueProperties.aaHash.get(token) == null)\r
+          if (ResidueProperties.aaIndex[token.charAt(0)]==-1)\r
             continue;\r
 \r
-          int colIndex =\r
-              ( (Integer) ResidueProperties.aaHash.\r
-               get(token)).intValue();\r
+          int colIndex = ResidueProperties.aaIndex[token.charAt(0)];\r
 \r
            //AW - LOWER CASE DISABLED IN 2.1.01 bug fix release\r
 \r
@@ -192,7 +190,7 @@ public class UserColourScheme
 \r
   public Color findColour(String s, int j)\r
   {\r
-      int index = ((Integer) (ResidueProperties.aaHash.get(s))).intValue();\r
+      int index = ResidueProperties.aaIndex[s.charAt(0)];\r
 \r
       if ((threshold == 0) || aboveThreshold(ResidueProperties.aa[index], j))\r
       {\r