X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=test%2Fjalview%2Fdatamodel%2FAlignmentTest.java;h=b4b0e126bd309fabff7dee6eca50bc4eb04bb4c0;hb=d6eb02943c3388257841b208e1fb65bd4c0be3b7;hp=5d299bb5a7550b30d35f5a9db19d17db3bb01939;hpb=7b928cacb8aa11d0ece7e7c0eaa02c2b25cb7c0f;p=jalview.git diff --git a/test/jalview/datamodel/AlignmentTest.java b/test/jalview/datamodel/AlignmentTest.java index 5d299bb..b4b0e12 100644 --- a/test/jalview/datamodel/AlignmentTest.java +++ b/test/jalview/datamodel/AlignmentTest.java @@ -22,6 +22,8 @@ package jalview.datamodel; import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertFalse; +import static org.testng.AssertJUnit.assertNotNull; +import static org.testng.AssertJUnit.assertNull; import static org.testng.AssertJUnit.assertSame; import static org.testng.AssertJUnit.assertTrue; @@ -30,8 +32,9 @@ import jalview.io.FormatAdapter; import jalview.util.MapList; import java.io.IOException; -import java.util.Collections; +import java.util.Arrays; import java.util.Iterator; +import java.util.List; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -247,7 +250,7 @@ public class AlignmentTest ((Alignment) al1).alignAs(al2, false, true); assertEquals("ACG---GCUCCA------ACT", al1.getSequenceAt(0) .getSequenceAsString()); - assertEquals("---CGT---TAACGA---AGT", al1.getSequenceAt(1) + assertEquals("---CGT---TAACGA---AGT---", al1.getSequenceAt(1) .getSequenceAsString()); } @@ -392,9 +395,12 @@ public class AlignmentTest public void testCopyConstructor() throws IOException { AlignmentI protein = loadAlignment(AA_SEQS_1, FormatAdapter.PASTE); + // create sequence and alignment datasets protein.setDataset(null); AlignedCodonFrame acf = new AlignedCodonFrame(); - protein.getDataset().setCodonFrames(Collections.singleton(acf)); + List acfList = Arrays.asList(new AlignedCodonFrame[] + { acf }); + protein.getDataset().setCodonFrames(acfList); AlignmentI copy = new Alignment(protein); /* @@ -406,8 +412,85 @@ public class AlignmentTest .getSequenceAt(0).getDatasetSequence()); assertSame(copy.getSequenceAt(1).getDatasetSequence(), protein .getSequenceAt(1).getDatasetSequence()); - // and the same alignment dataset (?) - // or a new one with the same dataset sequences? - assertSame(copy.getDataset(), protein.getDataset()); + + // TODO should the copy constructor copy the dataset? + // or make a new one referring to the same dataset sequences?? + assertNull(copy.getDataset()); + // assertArrayEquals(copy.getDataset().getSequencesArray(), protein + // .getDataset().getSequencesArray()); + } + + /** + * Test behaviour of createDataset + * + * @throws IOException + */ + @Test(groups = "Functional") + public void testCreateDatasetAlignment() throws IOException + { + AlignmentI protein = new FormatAdapter().readFile(AA_SEQS_1, + AppletFormatAdapter.PASTE, "FASTA"); + /* + * create a dataset sequence on first sequence + * leave the second without one + */ + protein.getSequenceAt(0).createDatasetSequence(); + assertNotNull(protein.getSequenceAt(0).getDatasetSequence()); + assertNull(protein.getSequenceAt(1).getDatasetSequence()); + + /* + * add a mapping to the alignment + */ + AlignedCodonFrame acf = new AlignedCodonFrame(); + protein.addCodonFrame(acf); + assertNull(protein.getDataset()); + assertTrue(protein.getCodonFrames().contains(acf)); + + /* + * create the alignment dataset + * note this creates sequence datasets where missing + * as a side-effect (in this case, on seq2 + */ + // TODO promote this method to AlignmentI + ((Alignment) protein).createDatasetAlignment(); + + // TODO this method should return AlignmentI not Alignment !! + Alignment ds = protein.getDataset(); + + // side-effect: dataset created on second sequence + assertNotNull(protein.getSequenceAt(1).getDatasetSequence()); + // dataset alignment has references to dataset sequences + assertEquals(ds.getSequenceAt(0), protein.getSequenceAt(0) + .getDatasetSequence()); + assertEquals(ds.getSequenceAt(1), protein.getSequenceAt(1) + .getDatasetSequence()); + + // codon frames should have been moved to the dataset + // getCodonFrames() should delegate to the dataset: + assertTrue(protein.getCodonFrames().contains(acf)); + // prove the codon frames are indeed on the dataset: + assertTrue(ds.getCodonFrames().contains(acf)); + } + + @Test(groups = "Functional") + public void testAddCodonFrame() + { + AlignmentI align = new Alignment(new SequenceI[] {}); + AlignedCodonFrame acf = new AlignedCodonFrame(); + align.addCodonFrame(acf); + assertEquals(1, align.getCodonFrames().size()); + assertTrue(align.getCodonFrames().contains(acf)); + // can't add the same object twice: + align.addCodonFrame(acf); + assertEquals(1, align.getCodonFrames().size()); + + // create dataset alignment - mappings move to dataset + ((Alignment) align).createDatasetAlignment(); + assertSame(align.getCodonFrames(), align.getDataset().getCodonFrames()); + assertEquals(1, align.getCodonFrames().size()); + + AlignedCodonFrame acf2 = new AlignedCodonFrame(); + align.addCodonFrame(acf2); + assertTrue(align.getDataset().getCodonFrames().contains(acf)); } }