JAL-845 implement alignment of protein to match cDNA alignment
[jalview.git] / src / jalview / datamodel / Alignment.java
index cb571ac..4558d8d 100755 (executable)
@@ -1688,10 +1688,7 @@ public class Alignment implements AlignmentI
     boolean thatIsProtein = !al.isNucleotide();
     if (!thatIsProtein && !thisIsNucleotide)
     {
-      System.err
-              .println("Alignment of protein from cDNA not yet implemented");
-      return 0;
-      // todo: build it - a variant of Dna.CdnaTranslate()
+      return AlignmentUtils.alignProteinAsDna(this, al);
     }
 
     char thisGapChar = this.getGapCharacter();
@@ -1734,4 +1731,29 @@ public class Alignment implements AlignmentI
     }
     return names;
   }
+
+  /**
+   * Returns a (possibly empty) alignment whose sequences are aligned to match
+   * the current alignment, as mapped by the given codon mappings.
+   * 
+   * @param codonFrames
+   * @return
+   */
+  @Override
+  public AlignmentI getAlignedComplement(Set<AlignedCodonFrame> codonFrames)
+  {
+    // Note: passing codonFrames as a parameter rather than using
+    // this.codonFrameList as more flexible. Specifically, mappings are held
+    // on the protein alignment but we might want to act on dna.
+
+    // TODO we want the gap character of the mapped alignment, not this one!
+    List<SequenceI> alignedSeqs = AlignmentUtils.getAlignedTranslation(
+            getSequences(), getGapCharacter(), codonFrames);
+    final SequenceI[] seqsAsArray = alignedSeqs
+            .toArray(new SequenceI[alignedSeqs.size()]);
+    AlignmentI al = new Alignment(seqsAsArray);
+    al.padGaps();
+    al.setDataset(null);
+    return al;
+  }
 }