X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Futil%2FMappingUtilsTest.java;h=492cbb66dab6f444f9d3be8d0aad629f0cdafbe7;hb=ee198b3ca3687f18a2ee186f4e7c7330f4ea30f0;hp=853ebd5eed5d0056ebed320923bd2d03ea9b1be7;hpb=b8058f3f849f44740a695c83e96bdca3a197af5c;p=jalview.git diff --git a/test/jalview/util/MappingUtilsTest.java b/test/jalview/util/MappingUtilsTest.java index 853ebd5..492cbb66 100644 --- a/test/jalview/util/MappingUtilsTest.java +++ b/test/jalview/util/MappingUtilsTest.java @@ -24,7 +24,6 @@ import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertFalse; import static org.testng.AssertJUnit.assertSame; import static org.testng.AssertJUnit.assertTrue; -import static org.testng.internal.junit.ArrayAsserts.assertArrayEquals; import jalview.api.AlignViewportI; import jalview.commands.EditCommand; @@ -40,7 +39,9 @@ import jalview.datamodel.Sequence; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.gui.AlignViewport; -import jalview.io.AppletFormatAdapter; +import jalview.io.DataSourceType; +import jalview.io.FileFormat; +import jalview.io.FileFormatI; import jalview.io.FormatAdapter; import java.awt.Color; @@ -198,10 +199,10 @@ public class MappingUtilsTest * viewport). */ AlignmentI cdna = loadAlignment(">Seq1\nACG\n>Seq2\nTGA\n>Seq3\nTAC\n", - "FASTA"); + FileFormat.Fasta); cdna.setDataset(null); AlignmentI protein = loadAlignment(">Seq1\nK\n>Seq2\nL\n>Seq3\nQ\n", - "FASTA"); + FileFormat.Fasta); protein.setDataset(null); AlignedCodonFrame acf = new AlignedCodonFrame(); MapList map = new MapList(new int[] { 1, 3 }, new int[] { 1, 1 }, 3, 1); @@ -269,11 +270,11 @@ public class MappingUtilsTest * @return * @throws IOException */ - protected AlignmentI loadAlignment(final String data, String format) + protected AlignmentI loadAlignment(final String data, FileFormatI format) throws IOException { AlignmentI a = new FormatAdapter().readFile(data, - AppletFormatAdapter.PASTE, format); + DataSourceType.PASTE, format); a.setDataset(null); return a; } @@ -352,11 +353,11 @@ public class MappingUtilsTest */ AlignmentI cdna = loadAlignment(">Seq1/10-18\nAC-GctGtC-T\n" + ">Seq2/20-27\nTc-GA-G-T-Tc\n" + ">Seq3/30-38\nTtTT-AaCGg-\n", - "FASTA"); + FileFormat.Fasta); cdna.setDataset(null); AlignmentI protein = loadAlignment( ">Seq1/40-41\n-K-P\n>Seq2/50-51\nL--Q\n>Seq3/60-61\nG--S\n", - "FASTA"); + FileFormat.Fasta); protein.setDataset(null); // map first dna to first protein seq @@ -467,10 +468,11 @@ public class MappingUtilsTest * viewport). */ AlignmentI cdna = loadAlignment( - ">Seq1\nACGGCA\n>Seq2\nTGACAG\n>Seq3\nTACGTA\n", "FASTA"); + ">Seq1\nACGGCA\n>Seq2\nTGACAG\n>Seq3\nTACGTA\n", + FileFormat.Fasta); cdna.setDataset(null); AlignmentI protein = loadAlignment(">Seq1\nKA\n>Seq2\nLQ\n>Seq3\nQV\n", - "FASTA"); + FileFormat.Fasta); protein.setDataset(null); AlignedCodonFrame acf = new AlignedCodonFrame(); MapList map = new MapList(new int[] { 1, 6 }, new int[] { 1, 2 }, 3, 1); @@ -550,10 +552,10 @@ public class MappingUtilsTest */ AlignmentI cdna = loadAlignment( ">Seq1\nA-CG-GC--AT-CA\n>Seq2\n-TG-AC-AG-T-AT\n>Seq3\n-T--ACG-TAAT-G\n", - "FASTA"); + FileFormat.Fasta); cdna.setDataset(null); AlignmentI protein = loadAlignment( - ">Seq1\n-KA-S\n>Seq2\n--L-QY\n>Seq3\nQ-V-M\n", "FASTA"); + ">Seq1\n-KA-S\n>Seq2\n--L-QY\n>Seq3\nQ-V-M\n", FileFormat.Fasta); protein.setDataset(null); AlignedCodonFrame acf = new AlignedCodonFrame(); MapList map = new MapList(new int[] { 1, 9 }, new int[] { 1, 3 }, 3, 1); @@ -862,6 +864,10 @@ public class MappingUtilsTest public void testGetLength() { assertEquals(0, MappingUtils.getLength(null)); + + /* + * [start, end] ranges + */ List ranges = new ArrayList(); assertEquals(0, MappingUtils.getLength(ranges)); ranges.add(new int[] { 1, 1 }); @@ -870,6 +876,15 @@ public class MappingUtilsTest assertEquals(10, MappingUtils.getLength(ranges)); ranges.add(new int[] { 20, 10 }); assertEquals(21, MappingUtils.getLength(ranges)); + + /* + * [start, end, start, end...] ranges + */ + ranges.clear(); + ranges.add(new int[] { 1, 5, 8, 4 }); + ranges.add(new int[] { 8, 2 }); + ranges.add(new int[] { 12, 12 }); + assertEquals(18, MappingUtils.getLength(ranges)); } @Test(groups = { "Functional" }) @@ -911,4 +926,107 @@ public class MappingUtilsTest assertFalse(MappingUtils.contains(ranges, -45)); } + /** + * Test the method that drops positions from the start of a mapped range + */ + @Test(groups = "Functional") + public void testRemoveStartPositions() + { + int[] ranges = new int[] { 1, 10 }; + int[] adjusted = MappingUtils.removeStartPositions(0, ranges); + assertEquals("[1, 10]", Arrays.toString(adjusted)); + + adjusted = MappingUtils.removeStartPositions(1, ranges); + assertEquals("[2, 10]", Arrays.toString(adjusted)); + assertEquals("[1, 10]", Arrays.toString(ranges)); + + ranges = adjusted; + adjusted = MappingUtils.removeStartPositions(1, ranges); + assertEquals("[3, 10]", Arrays.toString(adjusted)); + assertEquals("[2, 10]", Arrays.toString(ranges)); + + ranges = new int[] { 2, 3, 10, 12 }; + adjusted = MappingUtils.removeStartPositions(1, ranges); + assertEquals("[3, 3, 10, 12]", Arrays.toString(adjusted)); + assertEquals("[2, 3, 10, 12]", Arrays.toString(ranges)); + + ranges = new int[] { 2, 2, 8, 12 }; + adjusted = MappingUtils.removeStartPositions(1, ranges); + assertEquals("[8, 12]", Arrays.toString(adjusted)); + assertEquals("[2, 2, 8, 12]", Arrays.toString(ranges)); + + ranges = new int[] { 2, 2, 8, 12 }; + adjusted = MappingUtils.removeStartPositions(2, ranges); + assertEquals("[9, 12]", Arrays.toString(adjusted)); + assertEquals("[2, 2, 8, 12]", Arrays.toString(ranges)); + + ranges = new int[] { 2, 2, 4, 4, 9, 12 }; + adjusted = MappingUtils.removeStartPositions(1, ranges); + assertEquals("[4, 4, 9, 12]", Arrays.toString(adjusted)); + assertEquals("[2, 2, 4, 4, 9, 12]", Arrays.toString(ranges)); + + ranges = new int[] { 2, 2, 4, 4, 9, 12 }; + adjusted = MappingUtils.removeStartPositions(2, ranges); + assertEquals("[9, 12]", Arrays.toString(adjusted)); + assertEquals("[2, 2, 4, 4, 9, 12]", Arrays.toString(ranges)); + + ranges = new int[] { 2, 3, 9, 12 }; + adjusted = MappingUtils.removeStartPositions(3, ranges); + assertEquals("[10, 12]", Arrays.toString(adjusted)); + assertEquals("[2, 3, 9, 12]", Arrays.toString(ranges)); + } + + /** + * Test the method that drops positions from the start of a mapped range, on + * the reverse strand + */ + @Test(groups = "Functional") + public void testRemoveStartPositions_reverseStrand() + { + int[] ranges = new int[] { 10, 1 }; + int[] adjusted = MappingUtils.removeStartPositions(0, ranges); + assertEquals("[10, 1]", Arrays.toString(adjusted)); + assertEquals("[10, 1]", Arrays.toString(ranges)); + + ranges = adjusted; + adjusted = MappingUtils.removeStartPositions(1, ranges); + assertEquals("[9, 1]", Arrays.toString(adjusted)); + assertEquals("[10, 1]", Arrays.toString(ranges)); + + ranges = adjusted; + adjusted = MappingUtils.removeStartPositions(1, ranges); + assertEquals("[8, 1]", Arrays.toString(adjusted)); + assertEquals("[9, 1]", Arrays.toString(ranges)); + + ranges = new int[] { 12, 11, 9, 6 }; + adjusted = MappingUtils.removeStartPositions(1, ranges); + assertEquals("[11, 11, 9, 6]", Arrays.toString(adjusted)); + assertEquals("[12, 11, 9, 6]", Arrays.toString(ranges)); + + ranges = new int[] { 12, 12, 8, 4 }; + adjusted = MappingUtils.removeStartPositions(1, ranges); + assertEquals("[8, 4]", Arrays.toString(adjusted)); + assertEquals("[12, 12, 8, 4]", Arrays.toString(ranges)); + + ranges = new int[] { 12, 12, 8, 4 }; + adjusted = MappingUtils.removeStartPositions(2, ranges); + assertEquals("[7, 4]", Arrays.toString(adjusted)); + assertEquals("[12, 12, 8, 4]", Arrays.toString(ranges)); + + ranges = new int[] { 12, 12, 10, 10, 8, 4 }; + adjusted = MappingUtils.removeStartPositions(1, ranges); + assertEquals("[10, 10, 8, 4]", Arrays.toString(adjusted)); + assertEquals("[12, 12, 10, 10, 8, 4]", Arrays.toString(ranges)); + + ranges = new int[] { 12, 12, 10, 10, 8, 4 }; + adjusted = MappingUtils.removeStartPositions(2, ranges); + assertEquals("[8, 4]", Arrays.toString(adjusted)); + assertEquals("[12, 12, 10, 10, 8, 4]", Arrays.toString(ranges)); + + ranges = new int[] { 12, 11, 8, 4 }; + adjusted = MappingUtils.removeStartPositions(3, ranges); + assertEquals("[7, 4]", Arrays.toString(adjusted)); + assertEquals("[12, 11, 8, 4]", Arrays.toString(ranges)); + } + }