fixed base lookup bug in dna pairwise alignment and ensured abiguous and non-standard...
authorjprocter <Jim Procter>
Wed, 11 Apr 2007 13:57:45 +0000 (13:57 +0000)
committerjprocter <Jim Procter>
Wed, 11 Apr 2007 13:57:45 +0000 (13:57 +0000)
src/jalview/analysis/AlignSeq.java
src/jalview/schemes/ResidueProperties.java

index 2fcc593..0de8167 100755 (executable)
@@ -36,21 +36,11 @@ public class AlignSeq
 {
   public static final String PEP = "pep";
   public static final String DNA = "dna";
-  /** DOCUMENT ME!! */
-  public static java.util.Hashtable dnaHash = new java.util.Hashtable();
-
-  static
-  {
-    dnaHash.put("C", new Integer(0));
-    dnaHash.put("T", new Integer(1));
-    dnaHash.put("A", new Integer(2));
-    dnaHash.put("G", new Integer(3));
-    dnaHash.put("-", new Integer(4));
-  }
-
+  
   static String[] dna =
       {
-      "C", "T", "A", "G", "-"};
+    "A", "C", "G", "T", "-"};
+    //"C", "T", "A", "G", "-"};
   static String[] pep =
       {
       "A", "R", "N", "D", "C", "Q", "E", "G", "H", "I", "L", "K", "M", "F",
@@ -420,13 +410,13 @@ public class AlignSeq
       if ( (aseq1[count] != defInt) && (i >= 0))
       {
         aseq1[count] = seq1[i];
-        astr1 = intToStr[seq1[i]] + astr1;
+        astr1 = s1str.charAt(i) + astr1;
       }
 
       if ( (aseq2[count] != defInt) && (j > 0))
       {
         aseq2[count] = seq2[j];
-        astr2 = intToStr[seq2[j]] + astr2;
+        astr2 = s2str.charAt(j) + astr2;
       }
 
       trace = findTrace(i, j);
@@ -458,13 +448,13 @@ public class AlignSeq
     if (aseq1[count] != defInt)
     {
       aseq1[count] = seq1[i];
-      astr1 = intToStr[seq1[i]] + astr1;
+      astr1 = s1str.charAt(i) + astr1;
     }
 
     if (aseq2[count] != defInt)
     {
       aseq2[count] = seq2[j];
-      astr2 = intToStr[seq2[j]] + astr2;
+      astr2 = s2str.charAt(j) + astr2;
     }
   }
 
@@ -473,9 +463,9 @@ public class AlignSeq
    */
   public void printAlignment(java.io.PrintStream os)
   {
+    // TODO: Use original sequence characters rather than re-translated characters in output
     // Find the biggest id length for formatting purposes
     int maxid = s1.getName().length();
-
     if (s2.getName().length() > maxid)
     {
       maxid = s2.getName().length();
@@ -497,7 +487,7 @@ public class AlignSeq
     output.append(" :  " + s2.getStart() + " - " + s2.getEnd() +
                   " (Sequence length = " +
                   s2str.length() + ")\n\n");
-
+    
     for (int j = 0; j < nochunks; j++)
     {
       // Print the first aligned sequence
@@ -505,10 +495,10 @@ public class AlignSeq
 
       for (int i = 0; i < len; i++)
       {
-        if ( (count + i + (j * len)) < aseq1.length)
+        if ( (i + (j * len)) < astr1.length())
         {
-          output.append(new Format("%s").form(intToStr[aseq1[count + i +
-                                              (j * len)]]));
+          output.append(astr1.charAt(i +
+                                              (j * len)));
         }
       }
 
@@ -518,11 +508,10 @@ public class AlignSeq
       // Print out the matching chars
       for (int i = 0; i < len; i++)
       {
-        if ( (count + i + (j * len)) < aseq1.length)
+        if ( (i + (j * len)) < astr1.length())
         {
-          if (intToStr[aseq1[count + i + (j * len)]].equals(
-              intToStr[aseq2[count + i + (j * len)]]) &&
-              !intToStr[aseq1[count + i + (j * len)]].equals("-"))
+          if (astr1.charAt(i + (j * len))==astr2.charAt(i + (j * len)) &&
+              !jalview.util.Comparison.isGap(astr1.charAt(i + (j * len))))
           {
             pid++;
             output.append("|");
@@ -530,8 +519,8 @@ public class AlignSeq
           else if (type.equals("pep"))
           {
             if (ResidueProperties.getPAM250(
-                intToStr[aseq1[count + i + (j * len)]],
-                intToStr[aseq2[count + i + (j * len)]]) > 0)
+                    astr1.charAt(i + (j * len)),
+                    astr2.charAt(i + (j * len)))>0)
             {
               output.append(".");
             }
@@ -554,10 +543,9 @@ public class AlignSeq
 
       for (int i = 0; i < len; i++)
       {
-        if ( (count + i + (j * len)) < aseq1.length)
+        if ( (i + (j * len)) < astr2.length())
         {
-          output.append(new Format("%s").form(intToStr[aseq2[count + i +
-                                              (j * len)]]));
+          output.append(astr2.charAt(i + (j * len)));
         }
       }
 
@@ -807,16 +795,20 @@ public class AlignSeq
         if (type.equals("pep"))
         {
           seq1[i] = ResidueProperties.aaIndex[c];
+          if (seq1[i] > 23)
+          {
+            seq1[i] = 23;
+          }
         }
         else if (type.equals("dna"))
         {
           seq1[i] = ResidueProperties.nucleotideIndex[c];
+          if (seq1[i] > 4)
+          {
+            seq1[i] = 4;
+          }
         }
 
-        if (seq1[i] > 23)
-        {
-          seq1[i] = 23;
-        }
       }
       catch (Exception e)
       {
index 0ae3201..b14d9c6 100755 (executable)
@@ -1167,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)
@@ -1246,4 +1241,14 @@ public class ResidueProperties
     }
     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;
+  }
 }