JAL-4366 fixed wrinkles in reconstructing peptide alignment using 3di alignment....
authorJames Procter <j.procter@dundee.ac.uk>
Fri, 12 Jan 2024 11:50:57 +0000 (11:50 +0000)
committerJames Procter <j.procter@dundee.ac.uk>
Fri, 12 Jan 2024 11:50:57 +0000 (11:50 +0000)
src/jalview/gui/AlignViewport.java
test/jalview/datamodel/AlignmentTest.java

index d56764b..3611bce 100644 (file)
@@ -831,18 +831,26 @@ public class AlignViewport extends AlignmentViewport
             ? new Alignment(getAlignment())
             : getAlignment();
     
-    // always create dataset for imported alignment before doing anything else..
-    al.setDataset(null);
     
     if (!al.isNucleotide() && !thisAlignment.isNucleotide())
     {
       // link AA to 3di or other kind of 'alternative' 1:1 mapping alignment
+      if (al.getDataset()==null)
+      {
+        al.setDataset(thisAlignment.getDataset());
+      }
       AlignmentUtils.map3diPeptideToProteinAligment(thisAlignment,al);
+      if (thisAlignment.getCodonFrames().isEmpty()) {thisAlignment.getCodonFrames().addAll(al.getCodonFrames()); }
+      else {al.getCodonFrames().addAll(thisAlignment.getCodonFrames()); };
+
 
     }
     else
     {
-      // link CODON triplets to Protein
+      // shouldn't we be merging dataset here ?
+      // always create dataset for imported alignment before doing anything else..
+        al.setDataset(null);
+        // link CODON triplets to Protein
       AlignmentI protein = al.isNucleotide() ? thisAlignment : al;
       final AlignmentI cdna = al.isNucleotide() ? al : thisAlignment;
 
index 67965c2..30c0de4 100644 (file)
@@ -100,9 +100,9 @@ public class AlignmentTest
   
   private static final String AA_SEQS_2 = 
           ">Seq1Name/5-8\n" +
-          "K-QY--L\n" +
+          "K-QY-L\n" +
           ">Seq2Name/12-15\n" +
-          "-R-FP-W-\n";
+          "-R-FPW\n";
   private static final String AA_SEQS_2_DS = 
           ">Seq1Name/5-8\n" +
           "KQYL\n" +
@@ -813,7 +813,7 @@ public class AlignmentTest
     AlignmentI al1 = loadAlignment(TD_SEQS_2, FileFormat.Fasta);
     AlignmentI al2 = loadAlignment(AA_SEQS_2_DS, FileFormat.Fasta);
     al1.setDataset(null);
-    al2.setDataset(null);
+    al2.setDataset(al1.getDataset());
     AlignmentI al1copy = new Alignment(al1);
     AlignmentI al2copy = new Alignment(al2);
     AlignmentUtils.map3diPeptideToProteinAligment(al2, al1);
@@ -828,6 +828,32 @@ public class AlignmentTest
     
   }
   /**
+   * Recover TdI MSA from protein msa
+   * 
+   * @throws IOException
+   */
+  @Test(groups = { "Functional" })
+  public void testAlignAs_tdi_prot() throws Exception
+  {
+    // see also AlignmentUtilsTests
+    AlignmentI al1 = loadAlignment(AA_SEQS_2, FileFormat.Fasta);
+    AlignmentI al2 = loadAlignment(TD_SEQS_2_DS, FileFormat.Fasta);
+    al1.setDataset(null);
+    al2.setDataset(al1.getDataset());
+    AlignmentI al1copy = new Alignment(al1);
+    AlignmentI al2copy = new Alignment(al2);
+    AlignmentUtils.map3diPeptideToProteinAligment(al1, al2);
+    if (al2.getCodonFrames().isEmpty()) {al2.getCodonFrames().addAll(al1.getCodonFrames()); }
+    else {al1.getCodonFrames().addAll(al2.getCodonFrames()); };
+    
+    ((Alignment) al2).alignAs(al1);
+    assertEquals("K-QY-L", al1.getSequenceAt(0).getSequenceAsString());
+    assertEquals("-R-FPW", al1.getSequenceAt(1).getSequenceAsString());
+    assertEquals("N-MP-R", al2.getSequenceAt(0).getSequenceAsString());
+    assertEquals("-V-XYA", al2.getSequenceAt(1).getSequenceAsString());
+    
+  }
+  /**
    * Test aligning cdna as per protein alignment.
    * 
    * @throws IOException