JAL-2110 test demonstrating limitation of current implementation of alignAs (simple...
authorJim Procter <jprocter@issues.jalview.org>
Tue, 12 Jul 2016 16:15:23 +0000 (17:15 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Tue, 12 Jul 2016 16:16:57 +0000 (17:16 +0100)
src/jalview/analysis/AlignmentUtils.java
test/jalview/analysis/AlignmentUtilsTests.java

index 7264cd2..5e04d31 100644 (file)
@@ -2624,6 +2624,8 @@ public class AlignmentUtils
     Map<SequenceI, SequenceI> alignedDatasets = new HashMap<SequenceI, SequenceI>();
     for (SequenceI seq : aligned.getSequences())
     {
+      // JAL-2110: fail if two or more alignment sequences have a common dataset
+      // sequence.
       alignedDatasets.put(seq.getDatasetSequence(), seq);
     }
 
@@ -2646,6 +2648,8 @@ public class AlignmentUtils
     {
       SequenceI alignedSequence = alignedDatasets.get(seq
               .getDatasetSequence());
+      // JAL-2110: fail if two or more alignment sequences have common dataset
+      // sequence.
       // TODO: getSequenceAsString() will be deprecated in the future
       // TODO: need to leave to SequenceI implementor to update gaps
       seq.setSequence(alignedSequence.getSequenceAsString());
index 5c75992..a0c9ace 100644 (file)
@@ -2442,5 +2442,34 @@ public class AlignmentUtilsTests
     al1.addSequence(dna6);
     assertFalse(AlignmentUtils.alignAsSameSequences(al1, al2));
   }
+
+  @Test(groups = "Functional")
+  public void testAlignAsSameSequencesMultipleSubSeq()
+  {
+    SequenceI dna1 = new Sequence("dna1", "cccGGGTTTaaa");
+    SequenceI dna2 = new Sequence("dna2", "CCCgggtttAAA");
+    SequenceI as1 = dna1.deriveSequence(), as2 = dna1.deriveSequence()
+            .getSubSequence(3, 7), as3 = dna2.deriveSequence();
+    as1.insertCharAt(6, 5, '-');
+    String s_as1 = as1.getSequenceAsString();
+    as2.insertCharAt(6, 5, '-');
+    String s_as2 = as2.getSequenceAsString();
+    as3.insertCharAt(6, 5, '-');
+    String s_as3 = as3.getSequenceAsString();
+    AlignmentI aligned = new Alignment(new SequenceI[] { as1, as2, as3 });
+
+    // why do we need to cast this still ?
+    ((Alignment) aligned).createDatasetAlignment();
+    SequenceI uas1 = dna1.deriveSequence(), uas2 = dna1.deriveSequence()
+            .getSubSequence(3, 7), uas3 = dna2.deriveSequence();
+    AlignmentI tobealigned = new Alignment(new SequenceI[] { uas1, uas2,
+        uas3 });
+    ((Alignment) tobealigned).createDatasetAlignment();
+
+    assertTrue(AlignmentUtils.alignAsSameSequences(tobealigned, aligned));
+    assertEquals(s_as1, uas1.getSequenceAsString());
+    assertEquals(s_as2, uas2.getSequenceAsString());
+    assertEquals(s_as3, uas3.getSequenceAsString());
+  }
     
 }