X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Futil%2FMappingUtilsTest.java;h=7100381d38a178d458f4dfe9afd34f1c6a81bc8c;hb=c6c67aaa8e2d236305a3495f4edfc8cc88e22b79;hp=758694a3a8c95b0e3589a3e1e17809e255b1327f;hpb=a23ea387c12b87e15490f4a7f9afbdf34c232cf1;p=jalview.git diff --git a/test/jalview/util/MappingUtilsTest.java b/test/jalview/util/MappingUtilsTest.java index 758694a..7100381 100644 --- a/test/jalview/util/MappingUtilsTest.java +++ b/test/jalview/util/MappingUtilsTest.java @@ -43,12 +43,9 @@ import jalview.io.FormatAdapter; import java.awt.Color; import java.io.IOException; +import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; -import java.util.LinkedHashSet; import java.util.List; -import java.util.Set; import org.testng.annotations.Test; @@ -77,7 +74,8 @@ public class MappingUtilsTest MapList map = new MapList(new int[] { 5, 10 }, new int[] { 12, 13 }, 3, 1); acf.addMap(seq1.getDatasetSequence(), aseq1.getDatasetSequence(), map); - Set acfList = Collections.singleton(acf); + List acfList = Arrays.asList(new AlignedCodonFrame[] + { acf }); /* * Check protein residue 12 maps to codon 5-7, 13 to codon 8-10 @@ -129,7 +127,8 @@ public class MappingUtilsTest MapList map = new MapList(new int[] { 6, 6, 8, 9, 11, 11, 13, 13, 15, 15 }, new int[] { 8, 9 }, 3, 1); acf.addMap(seq1.getDatasetSequence(), aseq1.getDatasetSequence(), map); - Set acfList = Collections.singleton(acf); + List acfList = Arrays.asList(new AlignedCodonFrame[] + { acf }); /* * Check protein residue 8 maps to [6, 8, 9] @@ -209,7 +208,8 @@ public class MappingUtilsTest acf.addMap(cdna.getSequenceAt(seq).getDatasetSequence(), protein .getSequenceAt(seq).getDatasetSequence(), map); } - Set acfList = Collections.singleton(acf); + List acfList = Arrays.asList(new AlignedCodonFrame[] + { acf }); AlignViewportI dnaView = new AlignViewport(cdna); AlignViewportI proteinView = new AlignViewport(protein); @@ -343,8 +343,10 @@ public class MappingUtilsTest protected void setupMappedAlignments() throws IOException { /* - * Set up dna and protein Seq1/2/3 with mappings (held on the protein - * viewport). Lower case for introns. + * Map (upper-case = coding): + * Seq1/10-18 AC-GctGtC-T to Seq1/40 -K-P + * Seq2/20-27 Tc-GA-G-T-T to Seq2/20-27 L--Q + * Seq3/30-38 TtTT-AaCGg- to Seq3/60-61\nG--S */ 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", @@ -373,7 +375,8 @@ public class MappingUtilsTest 61 }, 3, 1); acf.addMap(cdna.getSequenceAt(2).getDatasetSequence(), protein .getSequenceAt(2).getDatasetSequence(), map); - Set acfList = Collections.singleton(acf); + List acfList = Arrays.asList(new AlignedCodonFrame[] + { acf }); dnaView = new AlignViewport(cdna); proteinView = new AlignViewport(protein); @@ -474,7 +477,8 @@ public class MappingUtilsTest acf.addMap(cdna.getSequenceAt(seq).getDatasetSequence(), protein .getSequenceAt(seq).getDatasetSequence(), map); } - Set acfList = Collections.singleton(acf); + List acfList = Arrays.asList(new AlignedCodonFrame[] + { acf }); AlignViewportI dnaView = new AlignViewport(cdna); AlignViewportI proteinView = new AlignViewport(protein); @@ -556,7 +560,8 @@ public class MappingUtilsTest acf.addMap(cdna.getSequenceAt(seq).getDatasetSequence(), protein .getSequenceAt(seq).getDatasetSequence(), map); } - Set acfList = Collections.singleton(acf); + List acfList = Arrays.asList(new AlignedCodonFrame[] + { acf }); AlignViewportI dnaView = new AlignViewport(cdna); AlignViewportI proteinView = new AlignViewport(protein); @@ -651,7 +656,7 @@ public class MappingUtilsTest AlignedCodonFrame acf3 = new AlignedCodonFrame(); acf3.addMap(seq3.getDatasetSequence(), seq1.getDatasetSequence(), map); - Set mappings = new HashSet(); + List mappings = new ArrayList(); mappings.add(acf1); mappings.add(acf2); mappings.add(acf3); @@ -707,7 +712,7 @@ public class MappingUtilsTest AlignedCodonFrame acf = new AlignedCodonFrame(); MapList map = new MapList(new int[] { 8, 16 }, new int[] { 5, 7 }, 3, 1); acf.addMap(dna.getDatasetSequence(), protein.getDatasetSequence(), map); - Set mappings = new LinkedHashSet(); + List mappings = new ArrayList(); mappings.add(acf); AlignmentI prot = new Alignment(new SequenceI[] { protein }); @@ -775,4 +780,79 @@ public class MappingUtilsTest Arrays.toString(MappingUtils.flattenRanges(new int[] { 12, 12, 9, 7, 4, 2, 1 }))); } + + /** + * Test mapping a column selection including hidden columns + * + * @throws IOException + */ + @Test(groups = { "Functional" }) + public void testMapColumnSelection_hiddenColumns() throws IOException + { + setupMappedAlignments(); + + ColumnSelection proteinSelection = new ColumnSelection(); + + /* + * Column 0 in protein picks up Seq2/L, Seq3/G which map to cols 0-4 and 0-3 + * in dna respectively, overall 0-4 + */ + proteinSelection.hideColumns(0); + ColumnSelection dnaSelection = MappingUtils.mapColumnSelection(proteinSelection, + proteinView, dnaView); + assertEquals("[]", dnaSelection.getSelected().toString()); + List hidden = dnaSelection.getHiddenColumns(); + assertEquals(1, hidden.size()); + assertEquals("[0, 4]", Arrays.toString(hidden.get(0))); + + /* + * Column 1 in protein picks up Seq1/K which maps to cols 0-3 in dna + */ + proteinSelection.revealAllHiddenColumns(); + // the unhidden columns are now marked selected! + assertEquals("[0]", proteinSelection.getSelected().toString()); + // deselect these or hideColumns will be expanded to include 0 + proteinSelection.clear(); + proteinSelection.hideColumns(1); + dnaSelection = MappingUtils.mapColumnSelection(proteinSelection, proteinView, dnaView); + hidden = dnaSelection.getHiddenColumns(); + assertEquals(1, hidden.size()); + assertEquals("[0, 3]", Arrays.toString(hidden.get(0))); + + /* + * Column 2 in protein picks up gaps only - no mapping + */ + proteinSelection.revealAllHiddenColumns(); + proteinSelection.clear(); + proteinSelection.hideColumns(2); + dnaSelection = MappingUtils.mapColumnSelection(proteinSelection, proteinView, dnaView); + assertTrue(dnaSelection.getHiddenColumns().isEmpty()); + + /* + * Column 3 in protein picks up Seq1/P, Seq2/Q, Seq3/S which map to columns + * 6-9, 6-10, 5-8 respectively, overall to 5-10 + */ + proteinSelection.revealAllHiddenColumns(); + proteinSelection.clear(); + proteinSelection.hideColumns(3); // 5-10 hidden in dna + proteinSelection.addElement(1); // 0-3 selected in dna + dnaSelection = MappingUtils.mapColumnSelection(proteinSelection, proteinView, dnaView); + assertEquals("[0, 1, 2, 3]", dnaSelection.getSelected().toString()); + hidden = dnaSelection.getHiddenColumns(); + assertEquals(1, hidden.size()); + assertEquals("[5, 10]", Arrays.toString(hidden.get(0))); + + /* + * Combine hiding columns 1 and 3 to get discontiguous hidden columns + */ + proteinSelection.revealAllHiddenColumns(); + proteinSelection.clear(); + proteinSelection.hideColumns(1); + proteinSelection.hideColumns(3); + dnaSelection = MappingUtils.mapColumnSelection(proteinSelection, proteinView, dnaView); + hidden = dnaSelection.getHiddenColumns(); + assertEquals(2, hidden.size()); + assertEquals("[0, 3]", Arrays.toString(hidden.get(0))); + assertEquals("[5, 10]", Arrays.toString(hidden.get(1))); + } }