From 1b911af46e474fd504a4d505327e02b684d9a397 Mon Sep 17 00:00:00 2001 From: kiramt Date: Mon, 24 Apr 2017 13:59:47 +0100 Subject: [PATCH] JAL-2388 Finished split of hidden columns and selected columns --- src/jalview/appletgui/SeqPanel.java | 13 ++- src/jalview/datamodel/ColumnSelection.java | 4 +- src/jalview/gui/SeqPanel.java | 16 ++-- src/jalview/io/JSONFile.java | 6 +- src/jalview/util/MappingUtils.java | 18 ++-- src/jalview/viewmodel/AlignmentViewport.java | 2 +- test/jalview/datamodel/ColumnSelectionTest.java | 8 +- test/jalview/datamodel/HiddenColumnsTest.java | 10 +-- test/jalview/util/MappingUtilsTest.java | 102 +++++++++++++++-------- 9 files changed, 109 insertions(+), 70 deletions(-) diff --git a/src/jalview/appletgui/SeqPanel.java b/src/jalview/appletgui/SeqPanel.java index fd4b364..ceae253 100644 --- a/src/jalview/appletgui/SeqPanel.java +++ b/src/jalview/appletgui/SeqPanel.java @@ -1812,7 +1812,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, * Check for selection in a view of which this one is a dna/protein * complement. */ - if (selectionFromTranslation(seqsel, colsel, source)) + if (selectionFromTranslation(seqsel, colsel, hidden, source)) { return; } @@ -1946,7 +1946,8 @@ public class SeqPanel extends Panel implements MouseMotionListener, * @param source */ protected boolean selectionFromTranslation(SequenceGroup seqsel, - ColumnSelection colsel, SelectionSource source) + ColumnSelection colsel, HiddenColumns hidden, + SelectionSource source) { if (!(source instanceof AlignViewportI)) { @@ -1969,9 +1970,13 @@ public class SeqPanel extends Panel implements MouseMotionListener, /* * Map column selection */ - ColumnSelection cs = MappingUtils.mapColumnSelection(colsel, sourceAv, - av); + // ColumnSelection cs = MappingUtils.mapColumnSelection(colsel, sourceAv, + // av); + ColumnSelection cs = new ColumnSelection(); + HiddenColumns hs = new HiddenColumns(); + MappingUtils.mapColumnSelection(colsel, hidden, sourceAv, av, cs, hs); av.setColumnSelection(cs); + av.getAlignment().setHiddenColumns(hs); ap.scalePanelHolder.repaint(); ap.repaint(); diff --git a/src/jalview/datamodel/ColumnSelection.java b/src/jalview/datamodel/ColumnSelection.java index 4b1eb56..4d69fa4 100644 --- a/src/jalview/datamodel/ColumnSelection.java +++ b/src/jalview/datamodel/ColumnSelection.java @@ -498,7 +498,7 @@ public class ColumnSelection * @param res * int */ - public void hideSelectedColumns(int col, AlignmentI al) + public void hideSelectedColumns(int col, HiddenColumns hidden) { /* * deselect column (whether selected or not!) @@ -531,7 +531,7 @@ public class ColumnSelection min = max; } - al.getHiddenColumns().hideColumns(min, max); + hidden.hideColumns(min, max); } diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index 282e826..063ab7d 100644 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -1956,8 +1956,7 @@ public class SeqPanel extends JPanel implements MouseListener, */ @Override public void selection(SequenceGroup seqsel, ColumnSelection colsel, - HiddenColumns hidden, - SelectionSource source) + HiddenColumns hidden, SelectionSource source) { // TODO: fix this hack - source of messages is align viewport, but SeqPanel // handles selection messages... @@ -1982,7 +1981,7 @@ public class SeqPanel extends JPanel implements MouseListener, * Check for selection in a view of which this one is a dna/protein * complement. */ - if (selectionFromTranslation(seqsel, colsel, source)) + if (selectionFromTranslation(seqsel, colsel, hidden, source)) { return; } @@ -2077,7 +2076,8 @@ public class SeqPanel extends JPanel implements MouseListener, * @param source */ protected boolean selectionFromTranslation(SequenceGroup seqsel, - ColumnSelection colsel, SelectionSource source) + ColumnSelection colsel, HiddenColumns hidden, + SelectionSource source) { if (!(source instanceof AlignViewportI)) { @@ -2100,9 +2100,13 @@ public class SeqPanel extends JPanel implements MouseListener, /* * Map column selection */ - ColumnSelection cs = MappingUtils.mapColumnSelection(colsel, sourceAv, - av); + // ColumnSelection cs = MappingUtils.mapColumnSelection(colsel, sourceAv, + // av); + ColumnSelection cs = new ColumnSelection(); + HiddenColumns hs = new HiddenColumns(); + MappingUtils.mapColumnSelection(colsel, hidden, sourceAv, av, cs, hs); av.setColumnSelection(cs); + av.getAlignment().setHiddenColumns(hs); PaintRefresher.Refresh(this, av.getSequenceSetId()); diff --git a/src/jalview/io/JSONFile.java b/src/jalview/io/JSONFile.java index dcf0f5d..e89dcfb 100644 --- a/src/jalview/io/JSONFile.java +++ b/src/jalview/io/JSONFile.java @@ -83,8 +83,6 @@ public class JSONFile extends AlignFile implements ComplexAlignFile private FeatureRenderer fr; - private List hiddenColumnsList; - private HiddenColumns hiddenColumns; private List hiddenSeqRefs; @@ -667,12 +665,12 @@ public class JSONFile extends AlignFile implements ComplexAlignFile String hiddenCols = (String) jvSettingsJson.get("hiddenCols"); if (hiddenCols != null && !hiddenCols.isEmpty()) { - HiddenColumns hidden = new HiddenColumns(); + hiddenColumns = new HiddenColumns(); String[] rangeStrings = hiddenCols.split(";"); for (String rangeString : rangeStrings) { String[] range = rangeString.split("-"); - hidden.hideColumns(Integer.valueOf(range[0]), + hiddenColumns.hideColumns(Integer.valueOf(range[0]), Integer.valueOf(range[1])); } } diff --git a/src/jalview/util/MappingUtils.java b/src/jalview/util/MappingUtils.java index 44a55ec..33c43d3 100644 --- a/src/jalview/util/MappingUtils.java +++ b/src/jalview/util/MappingUtils.java @@ -509,18 +509,20 @@ public final class MappingUtils * @param mapTo * @return */ - public static ColumnSelection mapColumnSelection(ColumnSelection colsel, - AlignViewportI mapFrom, AlignViewportI mapTo) + public static void mapColumnSelection(ColumnSelection colsel, + HiddenColumns hiddencols, AlignViewportI mapFrom, + AlignViewportI mapTo, ColumnSelection newColSel, + HiddenColumns newHidden) { boolean targetIsNucleotide = mapTo.isNucleotide(); AlignViewportI protein = targetIsNucleotide ? mapFrom : mapTo; List codonFrames = protein.getAlignment() .getCodonFrames(); - ColumnSelection mappedColumns = new ColumnSelection(); + // ColumnSelection mappedColumns = new ColumnSelection(); if (colsel == null) { - return mappedColumns; + return; // mappedColumns; } char fromGapChar = mapFrom.getAlignment().getGapCharacter(); @@ -534,16 +536,16 @@ public final class MappingUtils for (Integer sel : colsel.getSelected()) { - mapColumn(sel.intValue(), codonFrames, mappedColumns, fromSequences, + mapColumn(sel.intValue(), codonFrames, newColSel, fromSequences, toSequences, fromGapChar); } - for (int[] hidden : colsel.getListOfCols()) + for (int[] hidden : hiddencols.getListOfCols()) { - mapHiddenColumns(hidden, codonFrames, mappedColumns, fromSequences, + mapHiddenColumns(hidden, codonFrames, newHidden, fromSequences, toSequences, fromGapChar); } - return mappedColumns; + return; // mappedColumns; } /** diff --git a/src/jalview/viewmodel/AlignmentViewport.java b/src/jalview/viewmodel/AlignmentViewport.java index a70e382..9c8c233 100644 --- a/src/jalview/viewmodel/AlignmentViewport.java +++ b/src/jalview/viewmodel/AlignmentViewport.java @@ -1356,7 +1356,7 @@ public abstract class AlignmentViewport implements AlignViewportI, { if (start == end) { - colSel.hideSelectedColumns(start, alignment); + colSel.hideSelectedColumns(start, alignment.getHiddenColumns()); } else { diff --git a/test/jalview/datamodel/ColumnSelectionTest.java b/test/jalview/datamodel/ColumnSelectionTest.java index 6debd87..e5f2daa 100644 --- a/test/jalview/datamodel/ColumnSelectionTest.java +++ b/test/jalview/datamodel/ColumnSelectionTest.java @@ -106,7 +106,7 @@ public class ColumnSelectionTest cs.addElement(5); cs.addElement(6); // hide column 5 (and adjacent): - cs.hideSelectedColumns(5, al); + cs.hideSelectedColumns(5, al.getHiddenColumns()); // 4,5,6 now hidden: List hidden = al.getHiddenColumns().getListOfCols(); assertEquals(1, hidden.size()); @@ -120,7 +120,7 @@ public class ColumnSelectionTest cs.addElement(4); cs.addElement(5); cs.addElement(6); - cs.hideSelectedColumns(4, al); + cs.hideSelectedColumns(4, al.getHiddenColumns()); hidden = al.getHiddenColumns().getListOfCols(); assertEquals(1, hidden.size()); assertEquals("[4, 6]", Arrays.toString(hidden.get(0))); @@ -132,7 +132,7 @@ public class ColumnSelectionTest cs.addElement(4); cs.addElement(5); cs.addElement(6); - cs.hideSelectedColumns(6, al); + cs.hideSelectedColumns(6, al.getHiddenColumns()); hidden = al.getHiddenColumns().getListOfCols(); assertEquals(1, hidden.size()); assertEquals("[4, 6]", Arrays.toString(hidden.get(0))); @@ -143,7 +143,7 @@ public class ColumnSelectionTest cs = new ColumnSelection(); cs.addElement(4); cs.addElement(6); - cs.hideSelectedColumns(5, al); + cs.hideSelectedColumns(5, al.getHiddenColumns()); hidden = al.getHiddenColumns().getListOfCols(); assertEquals(1, hidden.size()); assertEquals("[4, 6]", Arrays.toString(hidden.get(0))); diff --git a/test/jalview/datamodel/HiddenColumnsTest.java b/test/jalview/datamodel/HiddenColumnsTest.java index be658d5..5eaecd3 100644 --- a/test/jalview/datamodel/HiddenColumnsTest.java +++ b/test/jalview/datamodel/HiddenColumnsTest.java @@ -242,7 +242,7 @@ public class HiddenColumnsTest Arrays.toString(cs.locateVisibleBoundsOfSequence(seq))); // hidden column on gap after end of sequence - should not affect bounds - colsel.hideSelectedColumns(13, al); + colsel.hideSelectedColumns(13, al.getHiddenColumns()); assertEquals( Arrays.toString(new int[] { seq.findIndex(seq.getStart()) - 1, seq.findIndex(seq.getEnd()) - 1, seq.getStart(), @@ -253,7 +253,7 @@ public class HiddenColumnsTest cs.revealAllHiddenColumns(colsel); // hidden column on gap before beginning of sequence - should vis bounds by // one - colsel.hideSelectedColumns(0, al); + colsel.hideSelectedColumns(0, al.getHiddenColumns()); assertEquals( Arrays.toString(new int[] { seq.findIndex(seq.getStart()) - 2, seq.findIndex(seq.getEnd()) - 2, seq.getStart(), @@ -310,12 +310,12 @@ public class HiddenColumnsTest ColumnSelection colsel = new ColumnSelection(); HiddenColumns cs = al.getHiddenColumns(); - colsel.hideSelectedColumns(5, al); + colsel.hideSelectedColumns(5, al.getHiddenColumns()); List hidden = cs.getListOfCols(); assertEquals(1, hidden.size()); assertEquals("[5, 5]", Arrays.toString(hidden.get(0))); - colsel.hideSelectedColumns(3, al); + colsel.hideSelectedColumns(3, al.getHiddenColumns()); assertEquals(2, hidden.size()); // two hidden ranges, in order: assertSame(hidden, cs.getListOfCols()); @@ -324,7 +324,7 @@ public class HiddenColumnsTest // hiding column 4 expands [3, 3] to [3, 4] // and merges to [5, 5] to make [3, 5] - colsel.hideSelectedColumns(4, al); + colsel.hideSelectedColumns(4, al.getHiddenColumns()); hidden = cs.getListOfCols(); assertEquals(1, hidden.size()); assertEquals("[3, 5]", Arrays.toString(hidden.get(0))); diff --git a/test/jalview/util/MappingUtilsTest.java b/test/jalview/util/MappingUtilsTest.java index 78a867e..bd97ad8 100644 --- a/test/jalview/util/MappingUtilsTest.java +++ b/test/jalview/util/MappingUtilsTest.java @@ -33,6 +33,7 @@ import jalview.datamodel.AlignedCodonFrame; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentI; import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.SearchResultMatchI; import jalview.datamodel.SearchResultsI; import jalview.datamodel.Sequence; @@ -300,49 +301,60 @@ public class MappingUtilsTest setupMappedAlignments(); ColumnSelection colsel = new ColumnSelection(); + HiddenColumns hidden = new HiddenColumns(); /* * 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 */ colsel.addElement(0); - ColumnSelection cs = MappingUtils.mapColumnSelection(colsel, - proteinView, dnaView); + ColumnSelection cs = new ColumnSelection(); + HiddenColumns hs = new HiddenColumns(); + MappingUtils.mapColumnSelection(colsel, hidden, proteinView, dnaView, + cs, hs); assertEquals("[0, 1, 2, 3, 4]", cs.getSelected().toString()); /* * Column 1 in protein picks up Seq1/K which maps to cols 0-3 in dna */ + cs.clear(); colsel.clear(); colsel.addElement(1); - cs = MappingUtils.mapColumnSelection(colsel, proteinView, dnaView); + MappingUtils.mapColumnSelection(colsel, hidden, proteinView, dnaView, + cs, hs); assertEquals("[0, 1, 2, 3]", cs.getSelected().toString()); /* * Column 2 in protein picks up gaps only - no mapping */ + cs.clear(); colsel.clear(); colsel.addElement(2); - cs = MappingUtils.mapColumnSelection(colsel, proteinView, dnaView); + MappingUtils.mapColumnSelection(colsel, hidden, proteinView, + dnaView, cs, hs); assertEquals("[]", cs.getSelected().toString()); /* * 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 */ + cs.clear(); colsel.clear(); colsel.addElement(3); - cs = MappingUtils.mapColumnSelection(colsel, proteinView, dnaView); + MappingUtils.mapColumnSelection(colsel, hidden, proteinView, + dnaView, cs, hs); assertEquals("[5, 6, 7, 8, 9, 10]", cs.getSelected().toString()); /* * Combine selection of columns 1 and 3 to get a discontiguous mapped * selection */ + cs.clear(); colsel.clear(); colsel.addElement(1); colsel.addElement(3); - cs = MappingUtils.mapColumnSelection(colsel, proteinView, dnaView); + MappingUtils.mapColumnSelection(colsel, hidden, proteinView, + dnaView, cs, hs); assertEquals("[0, 1, 2, 3, 5, 6, 7, 8, 9, 10]", cs.getSelected() .toString()); } @@ -407,14 +419,17 @@ public class MappingUtilsTest setupMappedAlignments(); ColumnSelection colsel = new ColumnSelection(); + HiddenColumns hidden = new HiddenColumns(); /* * Column 0 in dna picks up first bases which map to residue 1, columns 0-1 * in protein. */ + ColumnSelection cs = new ColumnSelection(); + HiddenColumns hs = new HiddenColumns(); colsel.addElement(0); - ColumnSelection cs = MappingUtils.mapColumnSelection(colsel, dnaView, - proteinView); + MappingUtils.mapColumnSelection(colsel, hidden, dnaView, proteinView, + cs, hs); assertEquals("[0, 1]", cs.getSelected().toString()); /* @@ -424,7 +439,9 @@ public class MappingUtilsTest colsel.addElement(3); colsel.addElement(4); colsel.addElement(5); - cs = MappingUtils.mapColumnSelection(colsel, dnaView, proteinView); + cs.clear(); + MappingUtils.mapColumnSelection(colsel, hidden, dnaView, proteinView, + cs, hs); assertEquals("[0, 1, 3]", cs.getSelected().toString()); } @@ -432,8 +449,10 @@ public class MappingUtilsTest public void testMapColumnSelection_null() throws IOException { setupMappedAlignments(); - ColumnSelection cs = MappingUtils.mapColumnSelection(null, dnaView, - proteinView); + ColumnSelection cs = new ColumnSelection(); + HiddenColumns hs = new HiddenColumns(); + MappingUtils.mapColumnSelection(null, null, dnaView, proteinView, cs, + hs); assertTrue("mapped selection not empty", cs.getSelected().isEmpty()); } @@ -882,69 +901,80 @@ public class MappingUtilsTest setupMappedAlignments(); ColumnSelection proteinSelection = new ColumnSelection(); + HiddenColumns hiddenCols = new HiddenColumns(); /* * 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.hideSelectedColumns(0); - ColumnSelection dnaSelection = MappingUtils.mapColumnSelection( - proteinSelection, proteinView, dnaView); + proteinSelection.hideSelectedColumns(0, hiddenCols); + ColumnSelection dnaSelection = new ColumnSelection(); + HiddenColumns dnaHidden = new HiddenColumns(); + MappingUtils.mapColumnSelection(proteinSelection, hiddenCols, + proteinView, dnaView, dnaSelection, dnaHidden); assertEquals("[]", dnaSelection.getSelected().toString()); - List hidden = dnaSelection.getListOfCols(); + List hidden = dnaHidden.getListOfCols(); 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(); + dnaSelection = new ColumnSelection(); + dnaHidden = new HiddenColumns(); + hiddenCols.revealAllHiddenColumns(proteinSelection); // 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.hideSelectedColumns(1); - dnaSelection = MappingUtils.mapColumnSelection(proteinSelection, - proteinView, dnaView); - hidden = dnaSelection.getListOfCols(); + proteinSelection.hideSelectedColumns(1, hiddenCols); + MappingUtils.mapColumnSelection(proteinSelection, hiddenCols, + proteinView, dnaView, dnaSelection, dnaHidden); + hidden = dnaHidden.getListOfCols(); assertEquals(1, hidden.size()); assertEquals("[0, 3]", Arrays.toString(hidden.get(0))); /* * Column 2 in protein picks up gaps only - no mapping */ - proteinSelection.revealAllHiddenColumns(); + dnaSelection = new ColumnSelection(); + dnaHidden = new HiddenColumns(); + hiddenCols.revealAllHiddenColumns(proteinSelection); proteinSelection.clear(); - proteinSelection.hideSelectedColumns(2); - dnaSelection = MappingUtils.mapColumnSelection(proteinSelection, - proteinView, dnaView); - assertTrue(dnaSelection.getListOfCols().isEmpty()); + proteinSelection.hideSelectedColumns(2, hiddenCols); + MappingUtils.mapColumnSelection(proteinSelection, hiddenCols, + proteinView, dnaView, dnaSelection, dnaHidden); + assertTrue(dnaHidden.getListOfCols().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(); + dnaSelection = new ColumnSelection(); + dnaHidden = new HiddenColumns(); + hiddenCols.revealAllHiddenColumns(proteinSelection); proteinSelection.clear(); - proteinSelection.hideSelectedColumns(3); // 5-10 hidden in dna + proteinSelection.hideSelectedColumns(3, hiddenCols); // 5-10 hidden in dna proteinSelection.addElement(1); // 0-3 selected in dna - dnaSelection = MappingUtils.mapColumnSelection(proteinSelection, - proteinView, dnaView); + MappingUtils.mapColumnSelection(proteinSelection, hiddenCols, + proteinView, dnaView, dnaSelection, dnaHidden); assertEquals("[0, 1, 2, 3]", dnaSelection.getSelected().toString()); - hidden = dnaSelection.getListOfCols(); + hidden = dnaHidden.getListOfCols(); 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(); + dnaSelection = new ColumnSelection(); + dnaHidden = new HiddenColumns(); + hiddenCols.revealAllHiddenColumns(proteinSelection); proteinSelection.clear(); - proteinSelection.hideSelectedColumns(1); - proteinSelection.hideSelectedColumns(3); - dnaSelection = MappingUtils.mapColumnSelection(proteinSelection, - proteinView, dnaView); - hidden = dnaSelection.getListOfCols(); + proteinSelection.hideSelectedColumns(1, hiddenCols); + proteinSelection.hideSelectedColumns(3, hiddenCols); + MappingUtils.mapColumnSelection(proteinSelection, hiddenCols, + proteinView, dnaView, dnaSelection, dnaHidden); + hidden = dnaHidden.getListOfCols(); assertEquals(2, hidden.size()); assertEquals("[0, 3]", Arrays.toString(hidden.get(0))); assertEquals("[5, 10]", Arrays.toString(hidden.get(1))); -- 1.7.10.2