From: Jim Procter Date: Mon, 22 Aug 2016 11:55:36 +0000 (+0100) Subject: JAL-2154 always check dataset sequence for sequence instance exists in dataset before... X-Git-Tag: Release_2_10_0~47^2~4^2~43^2~24 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=0d9271962a4c5e720ec8284d579bda635b59b231;p=jalview.git JAL-2154 always check dataset sequence for sequence instance exists in dataset before adding it in AlignmentI.addSequence() --- diff --git a/src/jalview/datamodel/Alignment.java b/src/jalview/datamodel/Alignment.java index fd918fc..2f64759 100755 --- a/src/jalview/datamodel/Alignment.java +++ b/src/jalview/datamodel/Alignment.java @@ -226,18 +226,21 @@ public class Alignment implements AlignmentI { if (dataset != null) { + // maintain dataset integrity - if (snew.getDatasetSequence() != null) - { - getDataset().addSequence(snew.getDatasetSequence()); - } - else + SequenceI dsseq = snew.getDatasetSequence(); + if (dsseq == null) { // derive new sequence SequenceI adding = snew.deriveSequence(); - getDataset().addSequence(adding.getDatasetSequence()); snew = adding; + dsseq = snew.getDatasetSequence(); } + if (getDataset().findIndex(dsseq) == -1) + { + getDataset().addSequence(dsseq); + } + } if (sequences == null) { diff --git a/test/jalview/datamodel/AlignmentTest.java b/test/jalview/datamodel/AlignmentTest.java index 379a9c5..2863340 100644 --- a/test/jalview/datamodel/AlignmentTest.java +++ b/test/jalview/datamodel/AlignmentTest.java @@ -857,6 +857,27 @@ public class AlignmentTest } @Test(groups = "Functional") + public void testAddSequencePreserveDatasetIntegrity() + { + Sequence seq = new Sequence("testSeq", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + Alignment align = new Alignment(new SequenceI[] { seq }); + align.createDatasetAlignment(); + AlignmentI ds = align.getDataset(); + SequenceI copy = new Sequence(seq); + copy.insertCharAt(3, 5, '-'); + align.addSequence(copy); + Assert.assertEquals(align.getDataset().getHeight(), 1, + "Dataset shouldn't have more than one sequence."); + + Sequence seq2 = new Sequence("newtestSeq", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + align.addSequence(seq2); + Assert.assertEquals(align.getDataset().getHeight(), 2, + "Dataset should now have two sequences."); + + assertAlignmentDatasetRefs(align, + "addSequence broke dataset reference integrity"); + } + @Test(groups = "Functional") public void getVisibleStartAndEndIndexTest() { Sequence seq = new Sequence("testSeq", "ABCDEFGHIJKLMNOPQRSTUVWXYZ");