JAL-845 implement alignment of protein to match cDNA alignment
[jalview.git] / src / jalview / datamodel / Alignment.java
index 5b41c1d..4558d8d 100755 (executable)
@@ -1588,6 +1588,39 @@ public class Alignment implements AlignmentI
     }
   }
 
+
+ private SequenceI seqrep=null;
+
+ /**
+  * 
+  * @return the representative sequence for this group
+  */
+ public SequenceI getSeqrep()
+ {
+   return seqrep;
+ }
+
+ /**
+  * set the representative sequence for this group. Note - this affects the
+  * interpretation of the Hidereps attribute.
+  * 
+  * @param seqrep
+  *          the seqrep to set (null means no sequence representative)
+  */
+ public void setSeqrep(SequenceI seqrep)
+ {
+   this.seqrep = seqrep;
+ }
+
+ /**
+  * 
+  * @return true if group has a sequence representative
+  */
+ public boolean hasSeqrep()
+ {
+   return seqrep != null;
+ }
+
   @Override
   public int getEndRes()
   {
@@ -1655,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();
@@ -1701,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;
+  }
 }