JAL-845 implement alignment of protein to match cDNA alignment
[jalview.git] / src / jalview / datamodel / AlignedCodon.java
index d0e62a1..0daa3fb 100644 (file)
@@ -2,7 +2,8 @@ package jalview.datamodel;
 
 /**
  * Holds the aligned column positions (base 0) for one codon in a nucleotide
- * sequence. The object is immutable once created.
+ * sequence, and (optionally) its peptide translation. The object is immutable
+ * once created.
  * 
  * Example: in "G-AT-C-GA" the aligned codons are (0, 2, 3) and (5, 7, 8).
  * 
@@ -17,11 +18,19 @@ public final class AlignedCodon
 
   public final int pos3;
 
+  public final String product;
+
   public AlignedCodon(int i, int j, int k)
   {
+    this(i, j, k, null);
+  }
+
+  public AlignedCodon(int i, int j, int k, String prod)
+  {
     pos1 = i;
     pos2 = j;
     pos3 = k;
+    product = prod;
   }
 
   /**
@@ -42,7 +51,10 @@ public final class AlignedCodon
   }
 
   /**
-   * Two aligned codons are equal if all their base positions are the same.
+   * Two aligned codons are equal if all their base positions are the same. We
+   * don't care about the protein product. This test is required for correct
+   * alignment of translated gapped dna alignments (the same codon positions in
+   * different sequences occupy the same column in the translated alignment).
    */
   @Override
   public boolean equals(Object o)
@@ -66,6 +78,9 @@ public final class AlignedCodon
   @Override
   public String toString()
   {
-    return "[" + pos1 + ", " + pos2 + ", " + pos3 + "]";
+    StringBuilder sb = new StringBuilder();
+    sb.append("[").append(pos1).append(", ").append(pos2).append(", ")
+            .append(pos3).append("]");
+    return sb.toString();
   }
 }