{
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)
{
}
@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");