AlignedCodonFrame holds mapping information between individual cDNA regions on dna...
[jalview.git] / src / jalview / schemes / ResidueProperties.java
index 5604ca3..9ac87ab 100755 (executable)
@@ -1,6 +1,6 @@
 /*
  * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -24,20 +24,21 @@ import java.awt.*;
 
 public class ResidueProperties
 {
-  public static Hashtable scoreMatrices=new Hashtable();
+  public static Hashtable scoreMatrices = new Hashtable();
   //Stores residue codes/names and colours and other things
-  public static final int [] aaIndex; // aaHash version 2.1.1 and below
-  public static final int [] nucleotideIndex;
+  public static final int[] aaIndex; // aaHash version 2.1.1 and below
+  public static final int[] nucleotideIndex;
   public static final Hashtable aa3Hash = new Hashtable();
   public static final Hashtable aa2Triplet = new Hashtable();
   public static final Hashtable nucleotideName = new Hashtable();
 
-
   static
   {
-    aaIndex = new int[132];
-    for(int i=0; i<132; i++)
-      aaIndex[i] = -1;
+    aaIndex = new int[255];
+    for (int i = 0; i < 255; i++)
+    {
+      aaIndex[i] = 23;
+    }
 
     aaIndex['A'] = 0;
     aaIndex['R'] = 1;
@@ -86,18 +87,16 @@ public class ResidueProperties
     aaIndex['b'] = 20;
     aaIndex['z'] = 21;
     aaIndex['x'] = 22;
-    aaIndex['u'] = 22;
-    aaIndex['-'] = 23;
-    aaIndex['*'] = 23;
-    aaIndex['.'] = 23;
-    aaIndex[' '] = 23;
+    aaIndex['u'] = 22; // TODO: selenocystine triplet and codons needed. also extend subt. matrices
   }
 
   static
   {
-    nucleotideIndex = new int[132];
-    for (int i = 0; i < 132; i++)
+    nucleotideIndex = new int[255];
+    for (int i = 0; i < 255; i++)
+    {
       nucleotideIndex[i] = -1;
+    }
 
     nucleotideIndex['A'] = 0;
     nucleotideIndex['a'] = 0;
@@ -120,7 +119,6 @@ public class ResidueProperties
     nucleotideIndex['N'] = 9;
     nucleotideIndex['n'] = 9;
 
-
     nucleotideName.put("A", "Adenine");
     nucleotideName.put("a", "Adenine");
     nucleotideName.put("G", "Guanine");
@@ -143,7 +141,6 @@ public class ResidueProperties
     nucleotideName.put("n", "Unknown");
   }
 
-
   static
   {
     aa3Hash.put("ALA", new Integer(0));
@@ -169,7 +166,7 @@ public class ResidueProperties
     // IUB Nomenclature for ambiguous peptides
     aa3Hash.put("ASX", new Integer(20)); // "B";
     aa3Hash.put("GLX", new Integer(21)); // X
-    aa3Hash.put("XAA", new Integer(22));// X unknown
+    aa3Hash.put("XAA", new Integer(22)); // X unknown
     aa3Hash.put("-", new Integer(23));
     aa3Hash.put("*", new Integer(23));
     aa3Hash.put(".", new Integer(23));
@@ -609,11 +606,13 @@ public class ResidueProperties
   /**
    * register matrices in list
    */
-  static {
-    scoreMatrices.put("BLOSUM62", new ScoreMatrix("BLOSUM62",BLOSUM62, 0));
-    scoreMatrices.put("PAM250", new ScoreMatrix("PAM250",PAM250, 0));
+  static
+  {
+    scoreMatrices.put("BLOSUM62", new ScoreMatrix("BLOSUM62", BLOSUM62, 0));
+    scoreMatrices.put("PAM250", new ScoreMatrix("PAM250", PAM250, 0));
     scoreMatrices.put("DNA", new ScoreMatrix("DNA", DNA, 1));
   }
+
   public static final Color[] pidColours =
       {
       midBlue, new Color(153, 153, 255),
@@ -843,7 +842,6 @@ public class ResidueProperties
     Phe.addElement("TTT");
   }
 
-
   //Stores residue codes/names and colours and other things
   public static Hashtable propHash = new Hashtable();
   public static Hashtable hydrophobic = new Hashtable();
@@ -1169,12 +1167,7 @@ public class ResidueProperties
 
   public static int getPAM250(String A1, String A2)
   {
-    int a = aaIndex[A1.charAt(0)];
-    int b = aaIndex[A2.charAt(0)];
-
-    int pog = ResidueProperties.PAM250[a][b];
-
-    return pog;
+    return getPAM250(A1.charAt(0), A2.charAt(0));
   }
 
   public static int getBLOSUM62(char c1, char c2)
@@ -1224,10 +1217,13 @@ public class ResidueProperties
     return null;
   }
 
-  public static int[][] getDefaultPeptideMatrix() {
+  public static int[][] getDefaultPeptideMatrix()
+  {
     return ResidueProperties.getBLOSUM62();
   }
-  public static int[][] getDefaultDnaMatrix() {
+
+  public static int[][] getDefaultDnaMatrix()
+  {
     return ResidueProperties.getDNA();
   }
 
@@ -1236,10 +1232,61 @@ public class ResidueProperties
    * @param pwtype
    * @return matrix in scoreMatrices with key pwtype or null
    */
-  public static ScoreMatrix getScoreMatrix(String pwtype) {
-    Object val=scoreMatrices.get(pwtype);
-    if (val!=null)
+  public static ScoreMatrix getScoreMatrix(String pwtype)
+  {
+    Object val = scoreMatrices.get(pwtype);
+    if (val != null)
+    {
       return (ScoreMatrix) val;
+    }
     return null;
   }
+
+  public static int getPAM250(char c, char d)
+  {
+    int a = aaIndex[c];
+    int b = aaIndex[d];
+
+    int pog = ResidueProperties.PAM250[a][b];
+
+    return pog;
+  }
+
+  public static Hashtable toDssp3State;
+  static {
+    toDssp3State = new Hashtable();
+    toDssp3State.put("H", "H");
+    toDssp3State.put("E", "E");
+    toDssp3State.put("C", " ");
+    toDssp3State.put(" ", " ");
+    toDssp3State.put("T", " ");
+    toDssp3State.put("B", "E");
+    toDssp3State.put("G", "H");
+    toDssp3State.put("I", "H");
+    toDssp3State.put("X", " ");
+  }
+  /**
+   * translate from other dssp secondary structure alphabets to 3-state
+   * @param ssstring
+   * @return ssstring as a three-state secondary structure assignment.
+   */
+  public static String getDssp3state(String ssstring)
+  {
+    if (ssstring==null)
+    {
+      return null;
+    }
+    StringBuffer ss = new StringBuffer();
+    for (int i=0; i<ssstring.length(); i++)
+    {
+      String ssc = ssstring.substring(i, i+1);
+      if (toDssp3State.containsKey(ssc))
+      {
+        ss.append((String) toDssp3State.get(ssc));
+      } else {
+        ss.append(" ");
+      }
+    }
+    return ss.toString();
+  }
 }