X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fdatamodel%2FAlignedCodonFrameTest.java;h=1c856734f4f67ecf1921c5ea5a4475babf76fd60;hb=57dd16688caa6dacaeaf465bab3ee8b6126e1a51;hp=c081cedc247bbc3ef668a393e3b7f4c7c6b73202;hpb=3412b273e964fb1a9d22564b04a5f0c827ec2461;p=jalview.git diff --git a/test/jalview/datamodel/AlignedCodonFrameTest.java b/test/jalview/datamodel/AlignedCodonFrameTest.java index c081ced..1c85673 100644 --- a/test/jalview/datamodel/AlignedCodonFrameTest.java +++ b/test/jalview/datamodel/AlignedCodonFrameTest.java @@ -1,23 +1,44 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9) + * Copyright (C) 2015 The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ package jalview.datamodel; import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertNull; -import org.testng.annotations.Test; + import jalview.util.MapList; import java.util.Arrays; +import org.testng.annotations.Test; + public class AlignedCodonFrameTest { /** * Test the method that locates the first aligned sequence that has a mapping. */ - @Test + @Test(groups = { "Functional" }) public void testFindAlignedSequence() { - AlignmentI cdna = new Alignment(new SequenceI[] - {}); + AlignmentI cdna = new Alignment(new SequenceI[] {}); final Sequence seq1 = new Sequence("Seq1", "C-G-TA-GC"); seq1.createDatasetSequence(); cdna.addSequence(seq1); @@ -25,8 +46,7 @@ public class AlignedCodonFrameTest seq2.createDatasetSequence(); cdna.addSequence(seq2); - AlignmentI aa = new Alignment(new SequenceI[] - {}); + AlignmentI aa = new Alignment(new SequenceI[] {}); final Sequence aseq1 = new Sequence("Seq1", "-P-R"); aseq1.createDatasetSequence(); aa.addSequence(aseq1); @@ -41,27 +61,23 @@ public class AlignedCodonFrameTest assertNull(acf.findAlignedSequence(seq1, aa)); - MapList map = new MapList(new int[] - { 1, 6 }, new int[] - { 1, 2 }, 3, 1); + MapList map = new MapList(new int[] { 1, 6 }, new int[] { 1, 2 }, 3, 1); acf.addMap(seq1.getDatasetSequence(), aseq2.getDatasetSequence(), map); /* * DNA seq1 maps to AA seq2 */ - assertEquals(aa.getSequenceAt(1), - acf.findAlignedSequence(cdna + assertEquals(aa.getSequenceAt(1), acf.findAlignedSequence(cdna .getSequenceAt(0).getDatasetSequence(), aa)); - assertEquals(cdna.getSequenceAt(0), - acf.findAlignedSequence(aa + assertEquals(cdna.getSequenceAt(0), acf.findAlignedSequence(aa .getSequenceAt(1).getDatasetSequence(), cdna)); } /** * Test the method that locates the mapped codon for a protein position. */ - @Test + @Test(groups = { "Functional" }) public void testGetMappedRegion() { // introns lower case, exons upper case @@ -85,13 +101,11 @@ public class AlignedCodonFrameTest /* * Set up the mappings for the exons (upper-case bases) */ - MapList map = new MapList(new int[] - { 2, 4, 6, 6, 8, 9 }, new int[] - { 1, 2 }, 3, 1); + MapList map = new MapList(new int[] { 2, 4, 6, 6, 8, 9 }, new int[] { + 1, 2 }, 3, 1); acf.addMap(seq1.getDatasetSequence(), aseq1.getDatasetSequence(), map); - map = new MapList(new int[] - { 1, 2, 4, 5, 7, 8 }, new int[] - { 1, 2 }, 3, 1); + map = new MapList(new int[] { 1, 2, 4, 5, 7, 8 }, new int[] { 1, 2 }, + 3, 1); acf.addMap(seq2.getDatasetSequence(), aseq2.getDatasetSequence(), map); assertEquals("[2, 4]", @@ -109,7 +123,7 @@ public class AlignedCodonFrameTest assertNull(acf.getMappedRegion(seq1, aseq2, 1)); } - @Test + @Test(groups = { "Functional" }) public void testGetMappedCodon() { final Sequence seq1 = new Sequence("Seq1", "c-G-TA-gC-gT-T"); @@ -127,14 +141,39 @@ public class AlignedCodonFrameTest /* * Set up the mappings for the exons (upper-case bases) */ - MapList map = new MapList(new int[] - { 2, 4, 6, 6, 8, 9 }, new int[] - { 1, 2 }, 3, 1); + MapList map = new MapList(new int[] { 2, 4, 6, 6, 8, 9 }, new int[] { + 1, 2 }, 3, 1); acf.addMap(seq1.getDatasetSequence(), aseq1.getDatasetSequence(), map); - + assertEquals("[G, T, A]", Arrays.toString(acf.getMappedCodon( aseq1.getDatasetSequence(), 1))); assertEquals("[C, T, T]", Arrays.toString(acf.getMappedCodon( aseq1.getDatasetSequence(), 2))); } + + /** + * Test for the case where sequences have start > 1 + */ + @Test(groups = { "Functional" }) + public void testGetMappedCodon_forSubSequences() + { + final Sequence seq1 = new Sequence("Seq1", "c-G-TA-gC-gT-T", 27, 35); + seq1.createDatasetSequence(); + + final Sequence aseq1 = new Sequence("Seq1", "-P-R", 12, 13); + aseq1.createDatasetSequence(); + + /* + * Set up the mappings for the exons (upper-case bases) + */ + AlignedCodonFrame acf = new AlignedCodonFrame(); + MapList map = new MapList(new int[] { 28, 30, 32, 32, 34, 35 }, + new int[] { 12, 13 }, 3, 1); + acf.addMap(seq1.getDatasetSequence(), aseq1.getDatasetSequence(), map); + + assertEquals("[G, T, A]", Arrays.toString(acf.getMappedCodon( + aseq1.getDatasetSequence(), 12))); + assertEquals("[C, T, T]", Arrays.toString(acf.getMappedCodon( + aseq1.getDatasetSequence(), 13))); + } }