Merge branch 'develop' into JAL-1705_trialMerge
[jalview.git] / test / jalview / util / MappingUtilsTest.java
index b3a1d8a..7100381 100644 (file)
@@ -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",
@@ -778,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<int[]> 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)));
+  }
 }