From fbc1dd3e5d38efcee395a49e1774226bf45d6687 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Tue, 12 Jul 2016 17:15:23 +0100 Subject: [PATCH] JAL-2110 test demonstrating limitation of current implementation of alignAs (simple case) --- src/jalview/analysis/AlignmentUtils.java | 4 ++++ test/jalview/analysis/AlignmentUtilsTests.java | 29 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/jalview/analysis/AlignmentUtils.java b/src/jalview/analysis/AlignmentUtils.java index 7264cd2..5e04d31 100644 --- a/src/jalview/analysis/AlignmentUtils.java +++ b/src/jalview/analysis/AlignmentUtils.java @@ -2624,6 +2624,8 @@ public class AlignmentUtils Map alignedDatasets = new HashMap(); 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()); diff --git a/test/jalview/analysis/AlignmentUtilsTests.java b/test/jalview/analysis/AlignmentUtilsTests.java index 5c75992..a0c9ace 100644 --- a/test/jalview/analysis/AlignmentUtilsTests.java +++ b/test/jalview/analysis/AlignmentUtilsTests.java @@ -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()); + } } -- 1.7.10.2