From d1707d4c26db76cfeb640f0dbeb3e3427fd40eb7 Mon Sep 17 00:00:00 2001 From: kiramt Date: Mon, 24 Apr 2017 10:37:33 +0100 Subject: [PATCH] JAL-2388 Hidden cols separated from column selection (almost complete) --- src/jalview/api/ComplexAlignFile.java | 4 +- src/jalview/appletgui/AlignFrame.java | 19 +- src/jalview/appletgui/AlignViewport.java | 4 +- src/jalview/appletgui/AlignmentPanel.java | 13 +- src/jalview/appletgui/AnnotationColumnChooser.java | 30 +- src/jalview/appletgui/AnnotationLabels.java | 3 +- src/jalview/appletgui/AnnotationPanel.java | 11 +- src/jalview/appletgui/CutAndPasteTransfer.java | 6 +- src/jalview/appletgui/IdCanvas.java | 3 +- src/jalview/appletgui/OverviewPanel.java | 7 +- src/jalview/appletgui/PCAPanel.java | 10 +- src/jalview/appletgui/ScalePanel.java | 26 +- src/jalview/appletgui/SeqCanvas.java | 24 +- src/jalview/appletgui/SeqPanel.java | 38 +- src/jalview/appletgui/TreePanel.java | 11 +- src/jalview/bin/JalviewLite.java | 8 +- src/jalview/datamodel/Alignment.java | 17 +- src/jalview/datamodel/AlignmentAnnotation.java | 12 +- src/jalview/datamodel/AlignmentI.java | 4 + src/jalview/datamodel/AlignmentView.java | 41 +- src/jalview/datamodel/CigarArray.java | 6 +- src/jalview/datamodel/ColumnSelection.java | 997 +------------------ src/jalview/datamodel/HiddenColumns.java | 1050 ++++++++++++++++++++ src/jalview/datamodel/SeqCigar.java | 12 +- src/jalview/ext/jmol/JalviewJmolBinding.java | 10 +- src/jalview/ext/jmol/JmolCommands.java | 4 +- src/jalview/ext/rbvi/chimera/ChimeraCommands.java | 4 +- .../ext/rbvi/chimera/JalviewChimeraBinding.java | 6 +- src/jalview/gui/AlignFrame.java | 30 +- src/jalview/gui/AlignViewport.java | 17 +- src/jalview/gui/AlignmentPanel.java | 23 +- src/jalview/gui/AnnotationColumnChooser.java | 30 +- src/jalview/gui/AnnotationLabels.java | 9 +- src/jalview/gui/AnnotationPanel.java | 15 +- src/jalview/gui/AppVarna.java | 3 +- src/jalview/gui/CutAndPasteTransfer.java | 8 +- src/jalview/gui/IdCanvas.java | 3 +- src/jalview/gui/Jalview2XML.java | 9 +- src/jalview/gui/OverviewPanel.java | 13 +- src/jalview/gui/PCAPanel.java | 8 +- src/jalview/gui/PopupMenu.java | 20 +- src/jalview/gui/ScalePanel.java | 34 +- src/jalview/gui/SeqCanvas.java | 26 +- src/jalview/gui/SeqPanel.java | 37 +- src/jalview/gui/StructureViewerBase.java | 6 +- src/jalview/gui/TreePanel.java | 8 +- src/jalview/gui/VamsasApplication.java | 13 +- src/jalview/io/AnnotationFile.java | 44 +- src/jalview/io/FileLoader.java | 6 +- src/jalview/io/FormatAdapter.java | 18 +- src/jalview/io/HTMLOutput.java | 4 +- src/jalview/io/HtmlFile.java | 14 +- src/jalview/io/JSONFile.java | 28 +- src/jalview/javascript/JsSelectionSender.java | 3 +- src/jalview/renderer/AnnotationRenderer.java | 10 +- src/jalview/renderer/ScaleRenderer.java | 8 +- src/jalview/structure/SelectionListener.java | 4 +- .../structure/StructureSelectionManager.java | 6 +- .../structures/models/AAStructureBindingModel.java | 6 +- src/jalview/util/MappingUtils.java | 5 +- src/jalview/viewmodel/AlignmentViewport.java | 75 +- src/jalview/viewmodel/OverviewDimensions.java | 6 +- src/jalview/ws/jws1/JPredThread.java | 10 +- src/jalview/ws/jws1/MsaWSThread.java | 6 +- src/jalview/ws/jws2/MsaWSThread.java | 10 +- src/jalview/ws/rest/RestClient.java | 12 +- src/jalview/ws/rest/RestJobThread.java | 26 +- test/jalview/analysis/DnaTest.java | 14 +- test/jalview/datamodel/ColumnSelectionTest.java | 489 +-------- test/jalview/datamodel/HiddenColumnsTest.java | 497 +++++++++ test/jalview/gui/AlignFrameTest.java | 14 +- test/jalview/io/AnnotationFileIOTest.java | 4 +- test/jalview/io/JSONFileTest.java | 16 +- .../models/AAStructureBindingModelTest.java | 4 +- test/jalview/util/MappingUtilsTest.java | 22 +- test/jalview/viewmodel/OverviewDimensionsTest.java | 8 +- 76 files changed, 2219 insertions(+), 1842 deletions(-) create mode 100644 src/jalview/datamodel/HiddenColumns.java create mode 100644 test/jalview/datamodel/HiddenColumnsTest.java diff --git a/src/jalview/api/ComplexAlignFile.java b/src/jalview/api/ComplexAlignFile.java index 2bf2782..1b579ad 100644 --- a/src/jalview/api/ComplexAlignFile.java +++ b/src/jalview/api/ComplexAlignFile.java @@ -20,7 +20,7 @@ */ package jalview.api; -import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.SequenceI; /** @@ -50,7 +50,7 @@ public interface ComplexAlignFile * * @return */ - public ColumnSelection getColumnSelection(); + public HiddenColumns getHiddenColumns(); /** * Retrieves hidden sequences from a complex file parser diff --git a/src/jalview/appletgui/AlignFrame.java b/src/jalview/appletgui/AlignFrame.java index 2646ede..681c777 100644 --- a/src/jalview/appletgui/AlignFrame.java +++ b/src/jalview/appletgui/AlignFrame.java @@ -43,6 +43,7 @@ import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; import jalview.datamodel.AlignmentOrder; import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.PDBEntry; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceGroup; @@ -169,14 +170,14 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, } public AlignFrame(AlignmentI al, SequenceI[] hiddenSeqs, - ColumnSelection columnSelection, JalviewLite applet, + HiddenColumns hidden, JalviewLite applet, String title, boolean embedded) { - this(al, hiddenSeqs, columnSelection, applet, title, embedded, true); + this(al, hiddenSeqs, hidden, applet, title, embedded, true); } public AlignFrame(AlignmentI al, SequenceI[] hiddenSeqs, - ColumnSelection columnSelection, JalviewLite applet, + HiddenColumns hidden, JalviewLite applet, String title, boolean embedded, boolean addToDisplay) { if (applet != null) @@ -219,9 +220,9 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, { viewport.hideSequence(hiddenSeqs); } - if (columnSelection != null) + if (hidden != null) { - viewport.setColumnSelection(columnSelection); + viewport.getAlignment().setHiddenColumns(hidden); } viewport.setScaleAboveWrapped(scaleAbove.getState()); @@ -1924,7 +1925,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, { copiedHiddenColumns = new Vector(); int hiddenOffset = viewport.getSelectionGroup().getStartRes(); - for (int[] region : viewport.getColumnSelection().getHiddenColumns()) + for (int[] region : viewport.getAlignment().getHiddenColumns() + .getListOfCols()) { copiedHiddenColumns.addElement(new int[] { region[0] - hiddenOffset, region[1] - hiddenOffset }); @@ -4198,9 +4200,10 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, * @param csel * - columns to be selected on the alignment */ - public void select(SequenceGroup sel, ColumnSelection csel) + public void select(SequenceGroup sel, ColumnSelection csel, + HiddenColumns hidden) { - alignPanel.seqPanel.selection(sel, csel, null); + alignPanel.seqPanel.selection(sel, csel, hidden, null); } public void scrollTo(int row, int column) diff --git a/src/jalview/appletgui/AlignViewport.java b/src/jalview/appletgui/AlignViewport.java index 065c503..d11ed48 100644 --- a/src/jalview/appletgui/AlignViewport.java +++ b/src/jalview/appletgui/AlignViewport.java @@ -27,6 +27,7 @@ import jalview.bin.JalviewLite; import jalview.commands.CommandI; import jalview.datamodel.AlignmentI; import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.SearchResults; import jalview.datamodel.SearchResultsI; import jalview.datamodel.Sequence; @@ -333,7 +334,8 @@ public class AlignViewport extends AlignmentViewport implements { getStructureSelectionManager().sendSelection( new SequenceGroup(getSelectionGroup()), - new ColumnSelection(getColumnSelection()), this); + new ColumnSelection(getColumnSelection()), + new HiddenColumns(getAlignment().getHiddenColumns()), this); } /** diff --git a/src/jalview/appletgui/AlignmentPanel.java b/src/jalview/appletgui/AlignmentPanel.java index 3ae0394..a2a0b30 100644 --- a/src/jalview/appletgui/AlignmentPanel.java +++ b/src/jalview/appletgui/AlignmentPanel.java @@ -419,11 +419,12 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, int start = -1; if (av.hasHiddenColumns()) { - start = av.getColumnSelection().findColumnPosition(ostart); - end = av.getColumnSelection().findColumnPosition(end); + AlignmentI al = av.getAlignment(); + start = al.getHiddenColumns().findColumnPosition(ostart); + end = al.getHiddenColumns().findColumnPosition(end); if (start == end) { - if (!scrollToNearest && !av.getColumnSelection().isVisible(ostart)) + if (!scrollToNearest && !al.getHiddenColumns().isVisible(ostart)) { // don't scroll - position isn't visible return false; @@ -725,7 +726,8 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, if (av.hasHiddenColumns()) { - width = av.getColumnSelection().findColumnPosition(width); + width = av.getAlignment().getHiddenColumns() + .findColumnPosition(width); } if (x < 0) { @@ -1009,7 +1011,8 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, if (av.hasHiddenColumns()) { - maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1; + maxwidth = av.getAlignment().getHiddenColumns() + .findColumnPosition(maxwidth) - 1; } int canvasWidth = seqPanel.seqCanvas diff --git a/src/jalview/appletgui/AnnotationColumnChooser.java b/src/jalview/appletgui/AnnotationColumnChooser.java index a8dff62..7efb490 100644 --- a/src/jalview/appletgui/AnnotationColumnChooser.java +++ b/src/jalview/appletgui/AnnotationColumnChooser.java @@ -21,7 +21,7 @@ package jalview.appletgui; import jalview.datamodel.AlignmentAnnotation; -import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.schemes.AnnotationColourGradient; import jalview.util.MessageManager; import jalview.viewmodel.annotationfilter.AnnotationFilterParameter; @@ -110,7 +110,7 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements private int actionOption = ACTION_OPTION_SELECT; - private ColumnSelection oldColumnSelection; + private HiddenColumns oldHiddenColumns; public AnnotationColumnChooser() { @@ -140,7 +140,7 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements { return; } - setOldColumnSelection(av.getColumnSelection()); + setOldHiddenColumns(av.getAlignment().getHiddenColumns()); adjusting = true; Vector list = new Vector(); int index = 1; @@ -282,26 +282,26 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements @SuppressWarnings("unchecked") public void reset() { - if (this.getOldColumnSelection() != null) + if (this.getOldHiddenColumns() != null) { av.getColumnSelection().clear(); if (av.getAnnotationColumnSelectionState() != null) { - ColumnSelection oldSelection = av + HiddenColumns oldHidden = av .getAnnotationColumnSelectionState() - .getOldColumnSelection(); - if (oldSelection != null && oldSelection.getHiddenColumns() != null - && !oldSelection.getHiddenColumns().isEmpty()) + .getOldHiddenColumns(); + if (oldHidden != null && oldHidden.getListOfCols() != null + && !oldHidden.getListOfCols().isEmpty()) { - for (Iterator itr = oldSelection.getHiddenColumns() + for (Iterator itr = oldHidden.getListOfCols() .iterator(); itr.hasNext();) { int positions[] = itr.next(); av.hideColumns(positions[0], positions[1]); } } - av.setColumnSelection(oldSelection); + av.getAlignment().setHiddenColumns(oldHidden); } ap.paintAlignment(true); } @@ -508,16 +508,16 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements ap.paintAlignment(true); } - public ColumnSelection getOldColumnSelection() + public HiddenColumns getOldHiddenColumns() { - return oldColumnSelection; + return oldHiddenColumns; } - public void setOldColumnSelection(ColumnSelection currentColumnSelection) + public void setOldHiddenColumns(HiddenColumns currentHiddenColumns) { - if (currentColumnSelection != null) + if (currentHiddenColumns != null) { - this.oldColumnSelection = new ColumnSelection(currentColumnSelection); + this.oldHiddenColumns = new HiddenColumns(currentHiddenColumns); } } diff --git a/src/jalview/appletgui/AnnotationLabels.java b/src/jalview/appletgui/AnnotationLabels.java index ad74b25..9444a76 100755 --- a/src/jalview/appletgui/AnnotationLabels.java +++ b/src/jalview/appletgui/AnnotationLabels.java @@ -839,7 +839,8 @@ public class AnnotationLabels extends Panel implements ActionListener, if (av.hasHiddenColumns()) { jalview.appletgui.AlignFrame.copiedHiddenColumns = new Vector(); - for (int[] region : av.getColumnSelection().getHiddenColumns()) + for (int[] region : av.getAlignment().getHiddenColumns() + .getListOfCols()) { jalview.appletgui.AlignFrame.copiedHiddenColumns .addElement(new int[] { region[0], region[1] }); diff --git a/src/jalview/appletgui/AnnotationPanel.java b/src/jalview/appletgui/AnnotationPanel.java index 0ec7adf..5026ee4 100755 --- a/src/jalview/appletgui/AnnotationPanel.java +++ b/src/jalview/appletgui/AnnotationPanel.java @@ -165,7 +165,7 @@ public class AnnotationPanel extends Panel implements AwtRenderPanelI, { for (int index : av.getColumnSelection().getSelected()) { - if (av.getColumnSelection().isVisible(index)) + if (av.getAlignment().getHiddenColumns().isVisible(index)) { anot[index] = null; } @@ -189,7 +189,7 @@ public class AnnotationPanel extends Panel implements AwtRenderPanelI, { // TODO: JAL-2001 - provide a fast method to list visible selected // columns - if (!av.getColumnSelection().isVisible(index)) + if (!av.getAlignment().getHiddenColumns().isVisible(index)) { continue; } @@ -211,7 +211,7 @@ public class AnnotationPanel extends Panel implements AwtRenderPanelI, for (int index : av.getColumnSelection().getSelected()) { - if (!av.getColumnSelection().isVisible(index)) + if (!av.getAlignment().getHiddenColumns().isVisible(index)) { continue; } @@ -271,7 +271,7 @@ public class AnnotationPanel extends Panel implements AwtRenderPanelI, for (int index : av.getColumnSelection().getSelected()) { - if (!av.getColumnSelection().isVisible(index)) + if (!av.getAlignment().getHiddenColumns().isVisible(index)) { continue; } @@ -467,7 +467,8 @@ public class AnnotationPanel extends Panel implements AwtRenderPanelI, if (av.hasHiddenColumns()) { - column = av.getColumnSelection().adjustForHiddenColumns(column); + column = av.getAlignment().getHiddenColumns() + .adjustForHiddenColumns(column); } if (row > -1 && column < aa[row].annotations.length diff --git a/src/jalview/appletgui/CutAndPasteTransfer.java b/src/jalview/appletgui/CutAndPasteTransfer.java index c658734..1e806a5 100644 --- a/src/jalview/appletgui/CutAndPasteTransfer.java +++ b/src/jalview/appletgui/CutAndPasteTransfer.java @@ -25,7 +25,7 @@ import jalview.api.ComplexAlignFile; import jalview.api.FeaturesSourceI; import jalview.bin.JalviewLite; import jalview.datamodel.AlignmentI; -import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceI; import jalview.io.AlignmentFileReaderI; @@ -257,8 +257,8 @@ public class CutAndPasteTransfer extends Panel implements ActionListener, if (source instanceof ComplexAlignFile) { - ColumnSelection colSel = ((ComplexAlignFile) source) - .getColumnSelection(); + HiddenColumns colSel = ((ComplexAlignFile) source) + .getHiddenColumns(); SequenceI[] hiddenSeqs = ((ComplexAlignFile) source) .getHiddenSequences(); boolean showSeqFeatures = ((ComplexAlignFile) source) diff --git a/src/jalview/appletgui/IdCanvas.java b/src/jalview/appletgui/IdCanvas.java index abcbd70..db9e661 100755 --- a/src/jalview/appletgui/IdCanvas.java +++ b/src/jalview/appletgui/IdCanvas.java @@ -218,7 +218,8 @@ public class IdCanvas extends Panel if (av.hasHiddenColumns()) { - maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1; + maxwidth = av.getAlignment().getHiddenColumns() + .findColumnPosition(maxwidth) - 1; } int annotationHeight = 0; diff --git a/src/jalview/appletgui/OverviewPanel.java b/src/jalview/appletgui/OverviewPanel.java index 3ef2936..eaeafef 100755 --- a/src/jalview/appletgui/OverviewPanel.java +++ b/src/jalview/appletgui/OverviewPanel.java @@ -144,7 +144,7 @@ public class OverviewPanel extends Panel implements Runnable, private void mouseAction(MouseEvent evt) { od.updateViewportFromMouse(evt.getX(), evt.getY(), av.getAlignment() - .getHiddenSequences(), av.getColumnSelection(), av + .getHiddenSequences(), av.getAlignment().getHiddenColumns(), av .getRanges()); ap.setScrollValues(od.getScrollCol(), od.getScrollRow()); ap.paintAlignment(false); @@ -319,7 +319,7 @@ public class OverviewPanel extends Panel implements Runnable, } if (hiddenRow - || (hasHiddenCols && !av.getColumnSelection() + || (hasHiddenCols && !av.getAlignment().getHiddenColumns() .isVisible(lastcol))) { color = color.darker().darker(); @@ -335,7 +335,8 @@ public class OverviewPanel extends Panel implements Runnable, public void setBoxPosition() { od.setBoxPosition(av.getAlignment() - .getHiddenSequences(), av.getColumnSelection(), av.getRanges()); +.getHiddenSequences(), av + .getAlignment().getHiddenColumns(), av.getRanges()); repaint(); } diff --git a/src/jalview/appletgui/PCAPanel.java b/src/jalview/appletgui/PCAPanel.java index c5ec0c1..2ef7d10 100644 --- a/src/jalview/appletgui/PCAPanel.java +++ b/src/jalview/appletgui/PCAPanel.java @@ -22,7 +22,7 @@ package jalview.appletgui; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentView; -import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.SeqCigar; import jalview.datamodel.SequenceI; import jalview.util.MessageManager; @@ -116,6 +116,7 @@ public class PCAPanel extends EmbmenuFrame implements Runnable, /** * DOCUMENT ME! */ + @Override public void run() { // TODO progress indicator @@ -164,6 +165,7 @@ public class PCAPanel extends EmbmenuFrame implements Runnable, rc.paint(rc.getGraphics()); } + @Override public void actionPerformed(ActionEvent evt) { if (evt.getSource() == inputData) @@ -183,6 +185,7 @@ public class PCAPanel extends EmbmenuFrame implements Runnable, } } + @Override public void itemStateChanged(ItemEvent evt) { if (evt.getSource() == xCombobox) @@ -265,7 +268,7 @@ public class PCAPanel extends EmbmenuFrame implements Runnable, } ; Object[] alAndColsel = pcaModel.getSeqtrings() - .getAlignmentAndColumnSelection(gc); + .getAlignmentAndHiddenColumns(gc); if (alAndColsel != null && alAndColsel[0] != null) { @@ -273,7 +276,8 @@ public class PCAPanel extends EmbmenuFrame implements Runnable, AlignFrame af = new AlignFrame(al, av.applet, "Original Data for PCA", false); - af.viewport.setHiddenColumns((ColumnSelection) alAndColsel[1]); + af.viewport.getAlignment().setHiddenColumns( + (HiddenColumns) alAndColsel[1]); } } diff --git a/src/jalview/appletgui/ScalePanel.java b/src/jalview/appletgui/ScalePanel.java index 15d82a5..e0ec011 100755 --- a/src/jalview/appletgui/ScalePanel.java +++ b/src/jalview/appletgui/ScalePanel.java @@ -21,6 +21,7 @@ package jalview.appletgui; import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.SequenceGroup; import jalview.renderer.ScaleRenderer; import jalview.renderer.ScaleRenderer.ScaleMark; @@ -81,7 +82,7 @@ public class ScalePanel extends Panel implements MouseMotionListener, if (av.hasHiddenColumns()) { - res = av.getColumnSelection().adjustForHiddenColumns(x); + res = av.getAlignment().getHiddenColumns().adjustForHiddenColumns(x); } else { @@ -170,7 +171,7 @@ public class ScalePanel extends Panel implements MouseMotionListener, }); pop.add(item); - if (av.getColumnSelection().hasManyHiddenColumns()) + if (av.getAlignment().getHiddenColumns().hasManyHiddenColumns()) { item = new MenuItem(MessageManager.getString("action.reveal_all")); item.addActionListener(new ActionListener() @@ -239,7 +240,8 @@ public class ScalePanel extends Panel implements MouseMotionListener, if (av.hasHiddenColumns()) { - res = av.getColumnSelection().adjustForHiddenColumns(res); + res = av.getAlignment().getHiddenColumns() + .adjustForHiddenColumns(res); } if (!stretchingGroup) @@ -280,7 +282,7 @@ public class ScalePanel extends Panel implements MouseMotionListener, int res = (evt.getX() / av.getCharWidth()) + av.getRanges().getStartRes(); res = Math.max(0, res); - res = cs.adjustForHiddenColumns(res); + res = av.getAlignment().getHiddenColumns().adjustForHiddenColumns(res); res = Math.min(res, av.getAlignment().getWidth() - 1); min = Math.min(res, min); max = Math.max(res, max); @@ -329,10 +331,11 @@ public class ScalePanel extends Panel implements MouseMotionListener, int res = (evt.getX() / av.getCharWidth()) + av.getRanges().getStartRes(); - res = av.getColumnSelection().adjustForHiddenColumns(res); + res = av.getAlignment().getHiddenColumns().adjustForHiddenColumns(res); reveal = null; - for (int[] region : av.getColumnSelection().getHiddenColumns()) + for (int[] region : av.getAlignment().getHiddenColumns() + .getListOfCols()) { if (res + 1 == region[0] || res - 1 == region[1]) { @@ -370,21 +373,22 @@ public class ScalePanel extends Panel implements MouseMotionListener, // Fill the selected columns ColumnSelection cs = av.getColumnSelection(); + HiddenColumns hidden = av.getAlignment().getHiddenColumns(); int avCharWidth = av.getCharWidth(); int avcharHeight = av.getCharHeight(); if (cs != null) { gg.setColor(new Color(220, 0, 0)); - boolean hasHiddenColumns = cs.hasHiddenColumns(); + boolean hasHiddenColumns = hidden.hasHiddenColumns(); for (int sel : cs.getSelected()) { // TODO: JAL-2001 - provide a fast method to list visible selected in a // given range if (hasHiddenColumns) { - if (cs.isVisible(sel)) + if (hidden.isVisible(sel)) { - sel = cs.findColumnPosition(sel); + sel = hidden.findColumnPosition(sel); } else { @@ -443,10 +447,10 @@ public class ScalePanel extends Panel implements MouseMotionListener, if (av.getShowHiddenMarkers()) { int widthx = 1 + endx - startx; - for (int i = 0; i < cs.getHiddenColumns().size(); i++) + for (int i = 0; i < hidden.getListOfCols().size(); i++) { - res = cs.findHiddenRegionPosition(i) - startx; + res = hidden.findHiddenRegionPosition(i) - startx; if (res < 0 || res > widthx) { diff --git a/src/jalview/appletgui/SeqCanvas.java b/src/jalview/appletgui/SeqCanvas.java index ed8a46d..28aa9ba 100755 --- a/src/jalview/appletgui/SeqCanvas.java +++ b/src/jalview/appletgui/SeqCanvas.java @@ -21,6 +21,7 @@ package jalview.appletgui; import jalview.datamodel.AlignmentI; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.SearchResultsI; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; @@ -123,14 +124,17 @@ public class SeqCanvas extends Panel ypos += avcharHeight; if (av.hasHiddenColumns()) { - startx = av.getColumnSelection().adjustForHiddenColumns(startx); - endx = av.getColumnSelection().adjustForHiddenColumns(endx); + startx = av.getAlignment().getHiddenColumns() + .adjustForHiddenColumns(startx); + endx = av.getAlignment().getHiddenColumns() + .adjustForHiddenColumns(endx); } int maxwidth = av.getAlignment().getWidth(); if (av.hasHiddenColumns()) { - maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1; + maxwidth = av.getAlignment().getHiddenColumns() + .findColumnPosition(maxwidth) - 1; } // WEST SCALE @@ -170,7 +174,8 @@ public class SeqCanvas extends Panel if (av.hasHiddenColumns()) { - endx = av.getColumnSelection().adjustForHiddenColumns(endx); + endx = av.getAlignment().getHiddenColumns() + .adjustForHiddenColumns(endx); } SequenceI seq; @@ -440,7 +445,8 @@ public class SeqCanvas extends Panel if (av.hasHiddenColumns()) { - maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1; + maxwidth = av.getAlignment().getHiddenColumns() + .findColumnPosition(maxwidth) - 1; } while ((ypos <= canvasHeight) && (startRes < maxwidth)) @@ -474,12 +480,13 @@ public class SeqCanvas extends Panel } if (av.hasHiddenColumns() && av.getShowHiddenMarkers()) { + HiddenColumns hidden = av.getAlignment().getHiddenColumns(); g.setColor(Color.blue); int res; - for (int i = 0; i < av.getColumnSelection().getHiddenColumns() + for (int i = 0; i < hidden.getListOfCols() .size(); i++) { - res = av.getColumnSelection().findHiddenRegionPosition(i) + res = hidden.findHiddenRegionPosition(i) - startRes; if (res < 0 || res > endx - startRes) @@ -558,7 +565,8 @@ public class SeqCanvas extends Panel if (av.hasHiddenColumns()) { - for (int[] region : av.getColumnSelection().getHiddenColumns()) + HiddenColumns hidden = av.getAlignment().getHiddenColumns(); + for (int[] region : hidden.getListOfCols()) { int hideStart = region[0]; int hideEnd = region[1]; diff --git a/src/jalview/appletgui/SeqPanel.java b/src/jalview/appletgui/SeqPanel.java index 0e12703..fd4b364 100644 --- a/src/jalview/appletgui/SeqPanel.java +++ b/src/jalview/appletgui/SeqPanel.java @@ -25,6 +25,7 @@ import jalview.commands.EditCommand; import jalview.commands.EditCommand.Action; import jalview.datamodel.AlignmentI; import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.SearchResultMatchI; import jalview.datamodel.SearchResults; import jalview.datamodel.SearchResultsI; @@ -180,19 +181,22 @@ public class SeqPanel extends Panel implements MouseMotionListener, seqCanvas.cursorX += dx; seqCanvas.cursorY += dy; if (av.hasHiddenColumns() - && !av.getColumnSelection().isVisible(seqCanvas.cursorX)) + && !av.getAlignment().getHiddenColumns() + .isVisible(seqCanvas.cursorX)) { int original = seqCanvas.cursorX - dx; int maxWidth = av.getAlignment().getWidth(); - while (!av.getColumnSelection().isVisible(seqCanvas.cursorX) + while (!av.getAlignment().getHiddenColumns() + .isVisible(seqCanvas.cursorX) && seqCanvas.cursorX < maxWidth && seqCanvas.cursorX > 0) { seqCanvas.cursorX += dx; } if (seqCanvas.cursorX >= maxWidth - || !av.getColumnSelection().isVisible(seqCanvas.cursorX)) + || !av.getAlignment().getHiddenColumns() + .isVisible(seqCanvas.cursorX)) { seqCanvas.cursorX = original; } @@ -228,6 +232,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, else { ViewportRanges ranges = av.getRanges(); + HiddenColumns hidden = av.getAlignment().getHiddenColumns(); while (seqCanvas.cursorY < ranges.getStartSeq()) { ap.scrollUp(true); @@ -236,8 +241,8 @@ public class SeqPanel extends Panel implements MouseMotionListener, { ap.scrollUp(false); } - while (seqCanvas.cursorX < av.getColumnSelection() - .adjustForHiddenColumns(ranges.getStartRes())) + while (seqCanvas.cursorX < hidden.adjustForHiddenColumns(ranges + .getStartRes())) { if (!ap.scrollRight(false)) @@ -245,8 +250,8 @@ public class SeqPanel extends Panel implements MouseMotionListener, break; } } - while (seqCanvas.cursorX > av.getColumnSelection() - .adjustForHiddenColumns(ranges.getEndRes())) + while (seqCanvas.cursorX > hidden.adjustForHiddenColumns(ranges + .getEndRes())) { if (!ap.scrollRight(true)) { @@ -638,7 +643,8 @@ public class SeqPanel extends Panel implements MouseMotionListener, if (av.hasHiddenColumns()) { - res = av.getColumnSelection().adjustForHiddenColumns(res); + res = av.getAlignment().getHiddenColumns() + .adjustForHiddenColumns(res); } return res; @@ -1131,8 +1137,10 @@ public class SeqPanel extends Panel implements MouseMotionListener, if (av.hasHiddenColumns()) { fixedColumns = true; - int y1 = av.getColumnSelection().getHiddenBoundaryLeft(startres); - int y2 = av.getColumnSelection().getHiddenBoundaryRight(startres); + int y1 = av.getAlignment().getHiddenColumns() + .getHiddenBoundaryLeft(startres); + int y2 = av.getAlignment().getHiddenColumns() + .getHiddenBoundaryRight(startres); if ((insertGap && startres > y1 && lastres < y1) || (!insertGap && startres < y2 && lastres > y2)) @@ -1203,8 +1211,8 @@ public class SeqPanel extends Panel implements MouseMotionListener, { if (sg.getSize() == av.getAlignment().getHeight()) { - if ((av.hasHiddenColumns() && startres < av - .getColumnSelection().getHiddenBoundaryRight(startres))) + if ((av.hasHiddenColumns() && startres < av.getAlignment() + .getHiddenColumns().getHiddenBoundaryRight(startres))) { endEditing(); return; @@ -1787,7 +1795,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, */ @Override public void selection(SequenceGroup seqsel, ColumnSelection colsel, - SelectionSource source) + HiddenColumns hidden, SelectionSource source) { // TODO: fix this hack - source of messages is align viewport, but SeqPanel // handles selection messages... @@ -1877,8 +1885,8 @@ public class SeqPanel extends Panel implements MouseMotionListener, } if (copycolsel && av.hasHiddenColumns() - && (av.getColumnSelection() == null || av.getColumnSelection() - .getHiddenColumns() == null)) + && (av.getColumnSelection() == null || av.getAlignment() + .getHiddenColumns().getListOfCols() == null)) { System.err.println("Bad things"); } diff --git a/src/jalview/appletgui/TreePanel.java b/src/jalview/appletgui/TreePanel.java index b4b8ec2..23b23be 100644 --- a/src/jalview/appletgui/TreePanel.java +++ b/src/jalview/appletgui/TreePanel.java @@ -25,7 +25,7 @@ import jalview.api.analysis.ScoreModelI; import jalview.api.analysis.ViewBasedAnalysisI; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentView; -import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.SequenceI; import jalview.io.NewickFile; import jalview.schemes.ResidueProperties; @@ -69,6 +69,7 @@ public class TreePanel extends EmbmenuFrame implements ActionListener, return tree; } + @Override public void finalize() throws Throwable { ap = null; @@ -172,7 +173,7 @@ public class TreePanel extends EmbmenuFrame implements ActionListener, } ; Object[] alAndColsel = tree.seqData - .getAlignmentAndColumnSelection(gc); + .getAlignmentAndHiddenColumns(gc); if (alAndColsel != null && alAndColsel[0] != null) { @@ -180,7 +181,8 @@ public class TreePanel extends EmbmenuFrame implements ActionListener, AlignFrame af = new AlignFrame(al, av.applet, "Original Data for Tree", false); - af.viewport.setHiddenColumns((ColumnSelection) alAndColsel[1]); + af.viewport.getAlignment().setHiddenColumns( + (HiddenColumns) alAndColsel[1]); } } else @@ -200,6 +202,7 @@ public class TreePanel extends EmbmenuFrame implements ActionListener, this.newtree = newtree; } + @Override public void run() { if (newtree != null) @@ -286,6 +289,7 @@ public class TreePanel extends EmbmenuFrame implements ActionListener, } } + @Override public void actionPerformed(ActionEvent evt) { if (evt.getSource() == newickOutput) @@ -302,6 +306,7 @@ public class TreePanel extends EmbmenuFrame implements ActionListener, } } + @Override public void itemStateChanged(ItemEvent evt) { if (evt.getSource() == fitToWindow) diff --git a/src/jalview/bin/JalviewLite.java b/src/jalview/bin/JalviewLite.java index 7fa5147..dbc707d 100644 --- a/src/jalview/bin/JalviewLite.java +++ b/src/jalview/bin/JalviewLite.java @@ -31,6 +31,7 @@ import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentI; import jalview.datamodel.AlignmentOrder; import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.PDBEntry; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceGroup; @@ -485,7 +486,8 @@ public class JalviewLite extends Applet implements @Override public void run() { - alf.select(sel, csel); + alf.select(sel, csel, alf.getAlignViewport().getAlignment() + .getHiddenColumns()); } }); } @@ -2273,9 +2275,9 @@ public class JalviewLite extends Applet implements SequenceI repseq = alignFrame.viewport.getAlignment() .getSequenceAt(0); alignFrame.viewport.getAlignment().setSeqrep(repseq); - ColumnSelection cs = new ColumnSelection(); + HiddenColumns cs = new HiddenColumns(); cs.hideInsertionsFor(repseq); - alignFrame.viewport.setColumnSelection(cs); + alignFrame.viewport.getAlignment().setHiddenColumns(cs); alignFrame.alignPanel.fontChanged(); alignFrame.alignPanel.setScrollValues(0, 0); result = true; diff --git a/src/jalview/datamodel/Alignment.java b/src/jalview/datamodel/Alignment.java index 2dafc0c..cff3890 100755 --- a/src/jalview/datamodel/Alignment.java +++ b/src/jalview/datamodel/Alignment.java @@ -62,6 +62,8 @@ public class Alignment implements AlignmentI HiddenSequences hiddenSequences; + HiddenColumns hiddenCols; + public Hashtable alignmentProperties; private List codonFrameList; @@ -70,6 +72,7 @@ public class Alignment implements AlignmentI { groups = Collections.synchronizedList(new ArrayList()); hiddenSequences = new HiddenSequences(this); + hiddenCols = new HiddenColumns(); codonFrameList = new ArrayList(); nucleotide = Comparison.isNucleotide(seqs); @@ -125,7 +128,7 @@ public class Alignment implements AlignmentI public Alignment(SeqCigar[] alseqs) { SequenceI[] seqs = SeqCigar.createAlignmentSequences(alseqs, - gapCharacter, new ColumnSelection(), null); + gapCharacter, new HiddenColumns(), null); initAlignment(seqs); } @@ -1327,6 +1330,12 @@ public class Alignment implements AlignmentI } @Override + public HiddenColumns getHiddenColumns() + { + return hiddenCols; + } + + @Override public CigarArray getCompactAlignment() { synchronized (sequences) @@ -1946,4 +1955,10 @@ public class Alignment implements AlignmentI } return new int[] { startPos, endPos }; } + + @Override + public void setHiddenColumns(HiddenColumns cols) + { + hiddenCols = cols; + } } diff --git a/src/jalview/datamodel/AlignmentAnnotation.java b/src/jalview/datamodel/AlignmentAnnotation.java index 6117baf..e8dbeee 100755 --- a/src/jalview/datamodel/AlignmentAnnotation.java +++ b/src/jalview/datamodel/AlignmentAnnotation.java @@ -20,6 +20,10 @@ */ package jalview.datamodel; +import jalview.analysis.Rna; +import jalview.analysis.SecStrConsensus.SimpleBP; +import jalview.analysis.WUSSParseException; + import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -28,10 +32,6 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; -import jalview.analysis.Rna; -import jalview.analysis.SecStrConsensus.SimpleBP; -import jalview.analysis.WUSSParseException; - /** * DOCUMENT ME! * @@ -1150,14 +1150,14 @@ public class AlignmentAnnotation * @param colSel */ public AlignmentAnnotation(AlignmentAnnotation alignmentAnnotation, - ColumnSelection colSel) + HiddenColumns hidden) { this(alignmentAnnotation); if (annotations == null) { return; } - colSel.makeVisibleAnnotation(this); + hidden.makeVisibleAnnotation(this); } public void setPadGaps(boolean padgaps, char gapchar) diff --git a/src/jalview/datamodel/AlignmentI.java b/src/jalview/datamodel/AlignmentI.java index 2abb1f8..2e61f9d 100755 --- a/src/jalview/datamodel/AlignmentI.java +++ b/src/jalview/datamodel/AlignmentI.java @@ -358,6 +358,8 @@ public interface AlignmentI extends AnnotatedCollectionI HiddenSequences getHiddenSequences(); + HiddenColumns getHiddenColumns(); + /** * Compact representation of alignment * @@ -587,4 +589,6 @@ public interface AlignmentI extends AnnotatedCollectionI */ public int[] getVisibleStartAndEndIndex(List hiddenCols); + public void setHiddenColumns(HiddenColumns cols); + } diff --git a/src/jalview/datamodel/AlignmentView.java b/src/jalview/datamodel/AlignmentView.java index 9db9f38..a61d0d1 100644 --- a/src/jalview/datamodel/AlignmentView.java +++ b/src/jalview/datamodel/AlignmentView.java @@ -141,13 +141,14 @@ public class AlignmentView * the view */ public AlignmentView(AlignmentI alignment, - ColumnSelection columnSelection, SequenceGroup selection, + HiddenColumns hidden, + SequenceGroup selection, boolean hasHiddenColumns, boolean selectedRegionOnly, boolean recordGroups) { // refactored from AlignViewport.getAlignmentView(selectedOnly); this(new jalview.datamodel.CigarArray(alignment, - (hasHiddenColumns ? columnSelection : null), + (hasHiddenColumns ? hidden : null), (selectedRegionOnly ? selection : null)), (selectedRegionOnly && selection != null) ? selection .getStartRes() : 0); @@ -330,13 +331,13 @@ public class AlignmentView * char * @return Object[] { SequenceI[], ColumnSelection} */ - public Object[] getAlignmentAndColumnSelection(char gapCharacter) + public Object[] getAlignmentAndHiddenColumns(char gapCharacter) { - ColumnSelection colsel = new ColumnSelection(); + HiddenColumns hidden = new HiddenColumns(); return new Object[] { - SeqCigar.createAlignmentSequences(sequences, gapCharacter, colsel, - contigs), colsel }; + SeqCigar.createAlignmentSequences(sequences, gapCharacter, hidden, + contigs), hidden }; } /** @@ -710,7 +711,8 @@ public class AlignmentView if (contigs != null && contigs.length > 0) { SequenceI[] alignment = new SequenceI[sequences.length]; - ColumnSelection columnselection = new ColumnSelection(); + // ColumnSelection columnselection = new ColumnSelection(); + HiddenColumns hidden = new HiddenColumns(); if (contigs != null && contigs.length > 0) { int start = 0; @@ -823,7 +825,7 @@ public class AlignmentView } } // mark hidden segment as hidden in the new alignment - columnselection.hideColumns(nwidth, nwidth + contigs[contig + 2] + hidden.hideColumns(nwidth, nwidth + contigs[contig + 2] - 1); nwidth += contigs[contig + 2]; } @@ -901,7 +903,7 @@ public class AlignmentView } } } - return new Object[] { alignment, columnselection }; + return new Object[] { alignment, hidden }; } else { @@ -920,7 +922,7 @@ public class AlignmentView } else { - return getAlignmentAndColumnSelection(gapCharacter); + return getAlignmentAndHiddenColumns(gapCharacter); } } } @@ -1135,7 +1137,7 @@ public class AlignmentView } public static void testSelectionViews(AlignmentI alignment, - ColumnSelection csel, SequenceGroup selection) + HiddenColumns hidden, SequenceGroup selection) { System.out.println("Testing standard view creation:\n"); AlignmentView view = null; @@ -1143,7 +1145,7 @@ public class AlignmentView { System.out .println("View with no hidden columns, no limit to selection, no groups to be collected:"); - view = new AlignmentView(alignment, csel, selection, false, false, + view = new AlignmentView(alignment, hidden, selection, false, false, false); summariseAlignmentView(view, System.out); @@ -1157,7 +1159,7 @@ public class AlignmentView { System.out .println("View with no hidden columns, no limit to selection, and all groups to be collected:"); - view = new AlignmentView(alignment, csel, selection, false, false, + view = new AlignmentView(alignment, hidden, selection, false, false, true); summariseAlignmentView(view, System.out); } catch (Exception e) @@ -1170,7 +1172,7 @@ public class AlignmentView { System.out .println("View with no hidden columns, limited to selection and no groups to be collected:"); - view = new AlignmentView(alignment, csel, selection, false, true, + view = new AlignmentView(alignment, hidden, selection, false, true, false); summariseAlignmentView(view, System.out); } catch (Exception e) @@ -1183,7 +1185,7 @@ public class AlignmentView { System.out .println("View with no hidden columns, limited to selection, and all groups to be collected:"); - view = new AlignmentView(alignment, csel, selection, false, true, + view = new AlignmentView(alignment, hidden, selection, false, true, true); summariseAlignmentView(view, System.out); } catch (Exception e) @@ -1196,7 +1198,7 @@ public class AlignmentView { System.out .println("View *with* hidden columns, no limit to selection, no groups to be collected:"); - view = new AlignmentView(alignment, csel, selection, true, false, + view = new AlignmentView(alignment, hidden, selection, true, false, false); summariseAlignmentView(view, System.out); } catch (Exception e) @@ -1209,7 +1211,7 @@ public class AlignmentView { System.out .println("View *with* hidden columns, no limit to selection, and all groups to be collected:"); - view = new AlignmentView(alignment, csel, selection, true, false, + view = new AlignmentView(alignment, hidden, selection, true, false, true); summariseAlignmentView(view, System.out); } catch (Exception e) @@ -1222,7 +1224,7 @@ public class AlignmentView { System.out .println("View *with* hidden columns, limited to selection and no groups to be collected:"); - view = new AlignmentView(alignment, csel, selection, true, true, + view = new AlignmentView(alignment, hidden, selection, true, true, false); summariseAlignmentView(view, System.out); } catch (Exception e) @@ -1235,7 +1237,8 @@ public class AlignmentView { System.out .println("View *with* hidden columns, limited to selection, and all groups to be collected:"); - view = new AlignmentView(alignment, csel, selection, true, true, true); + view = new AlignmentView(alignment, hidden, selection, true, true, + true); summariseAlignmentView(view, System.out); } catch (Exception e) { diff --git a/src/jalview/datamodel/CigarArray.java b/src/jalview/datamodel/CigarArray.java index f6e5862..a48a178 100644 --- a/src/jalview/datamodel/CigarArray.java +++ b/src/jalview/datamodel/CigarArray.java @@ -20,6 +20,8 @@ */ package jalview.datamodel; +import htsjdk.samtools.Cigar; + import java.util.List; public class CigarArray extends CigarBase @@ -85,12 +87,12 @@ public class CigarArray extends CigarBase * @param columnSelection * @param selectionGroup */ - public CigarArray(AlignmentI alignment, ColumnSelection columnSelection, + public CigarArray(AlignmentI alignment, HiddenColumns hidden, SequenceGroup selectionGroup) { this(constructSeqCigarArray(alignment, selectionGroup)); constructFromAlignment(alignment, - columnSelection != null ? columnSelection.getHiddenColumns() + hidden != null ? hidden.getListOfCols() : null, selectionGroup); } diff --git a/src/jalview/datamodel/ColumnSelection.java b/src/jalview/datamodel/ColumnSelection.java index 97bc5a3..4b1eb56 100644 --- a/src/jalview/datamodel/ColumnSelection.java +++ b/src/jalview/datamodel/ColumnSelection.java @@ -20,7 +20,6 @@ */ package jalview.datamodel; -import jalview.util.Comparison; import jalview.util.ShiftList; import jalview.viewmodel.annotationfilter.AnnotationFilterParameter; import jalview.viewmodel.annotationfilter.AnnotationFilterParameter.SearchableAnnotationField; @@ -29,7 +28,6 @@ import java.util.ArrayList; import java.util.BitSet; import java.util.Collections; import java.util.List; -import java.util.Vector; /** * Data class holding the selected columns and hidden column ranges for a view. @@ -268,11 +266,7 @@ public class ColumnSelection IntList selection = new IntList(); - /* - * list of hidden column [start, end] ranges; the list is maintained in - * ascending start column order - */ - Vector hiddenColumns; + HiddenColumns hiddenColumns = new HiddenColumns(); /** * Add a column to the selection @@ -405,47 +399,12 @@ public class ColumnSelection * @param left * shift in edit (+ve for removal, or -ve for inserts) */ - public List compensateForEdit(int start, int change) - { - List deletedHiddenColumns = null; - selection.compensateForEdits(start, change); - - if (hiddenColumns != null) + /* public List compensateForEdit(int start, int change) { - deletedHiddenColumns = new ArrayList(); - int hSize = hiddenColumns.size(); - for (int i = 0; i < hSize; i++) - { - int[] region = hiddenColumns.elementAt(i); - if (region[0] > start && start + change > region[1]) - { - deletedHiddenColumns.add(region); - - hiddenColumns.removeElementAt(i); - i--; - hSize--; - continue; - } - - if (region[0] > start) - { - region[0] -= change; - region[1] -= change; - } - - if (region[0] < 0) - { - region[0] = 0; - } - - } - - this.revealHiddenColumns(0); + selection.compensateForEdits(start, change); + return hiddenColumns.compensateForEdit(start, change, this); } - - return deletedHiddenColumns; - } - + */ /** * propagate shift in alignment columns to column selection special version of * compensateForEdit - allowing for edits within hidden regions @@ -457,37 +416,8 @@ public class ColumnSelection */ private void compensateForDelEdits(int start, int change) { - selection.compensateForEdits(start, change); - - if (hiddenColumns != null) - { - for (int i = 0; i < hiddenColumns.size(); i++) - { - int[] region = hiddenColumns.elementAt(i); - if (region[0] >= start) - { - region[0] -= change; - } - if (region[1] >= start) - { - region[1] -= change; - } - if (region[1] < region[0]) - { - hiddenColumns.removeElementAt(i--); - } - - if (region[0] < 0) - { - region[0] = 0; - } - if (region[1] < 0) - { - region[1] = 0; - } - } - } + hiddenColumns.compensateForDelEdits(start, change); } /** @@ -497,7 +427,7 @@ public class ColumnSelection * @param shiftrecord * @return */ - public ShiftList compensateForEdits(ShiftList shiftrecord) + private ShiftList compensateForEdits(ShiftList shiftrecord) { if (shiftrecord != null) { @@ -508,7 +438,6 @@ public class ColumnSelection for (int i = 0, j = shifts.size(); i < j; i++) { int[] sh = shifts.get(i); - // compensateForEdit(shifted+sh[0], sh[1]); compensateForDelEdits(shifted + sh[0], sh[1]); shifted -= sh[1]; } @@ -518,100 +447,6 @@ public class ColumnSelection return null; } - /** - * removes intersection of position,length ranges in deletions from the - * start,end regions marked in intervals. - * - * @param shifts - * @param intervals - * @return - */ - private boolean pruneIntervalVector(final List shifts, - Vector intervals) - { - boolean pruned = false; - int i = 0, j = intervals.size() - 1, s = 0, t = shifts.size() - 1; - int hr[] = intervals.elementAt(i); - int sr[] = shifts.get(s); - while (i <= j && s <= t) - { - boolean trailinghn = hr[1] >= sr[0]; - if (!trailinghn) - { - if (i < j) - { - hr = intervals.elementAt(++i); - } - else - { - i++; - } - continue; - } - int endshift = sr[0] + sr[1]; // deletion ranges - -ve means an insert - if (endshift < hr[0] || endshift < sr[0]) - { // leadinghc disjoint or not a deletion - if (s < t) - { - sr = shifts.get(++s); - } - else - { - s++; - } - continue; - } - boolean leadinghn = hr[0] >= sr[0]; - boolean leadinghc = hr[0] < endshift; - boolean trailinghc = hr[1] < endshift; - if (leadinghn) - { - if (trailinghc) - { // deleted hidden region. - intervals.removeElementAt(i); - pruned = true; - j--; - if (i <= j) - { - hr = intervals.elementAt(i); - } - continue; - } - if (leadinghc) - { - hr[0] = endshift; // clip c terminal region - leadinghn = !leadinghn; - pruned = true; - } - } - if (!leadinghn) - { - if (trailinghc) - { - if (trailinghn) - { - hr[1] = sr[0] - 1; - pruned = true; - } - } - else - { - // sr contained in hr - if (s < t) - { - sr = shifts.get(++s); - } - else - { - s++; - } - continue; - } - } - } - return pruned; // true if any interval was removed or modified by - // operations. - } /** * remove any hiddenColumns or selected columns and shift remaining based on a @@ -619,22 +454,15 @@ public class ColumnSelection * * @param deletions */ - public void pruneDeletions(ShiftList deletions) + private void pruneDeletions(ShiftList deletions) { if (deletions != null) { final List shifts = deletions.getShifts(); if (shifts != null && shifts.size() > 0) { - // delete any intervals intersecting. - if (hiddenColumns != null) - { - pruneIntervalVector(shifts, hiddenColumns); - if (hiddenColumns != null && hiddenColumns.size() == 0) - { - hiddenColumns = null; - } - } + hiddenColumns.pruneDeletions(shifts); + if (selection != null && selection.size() > 0) { selection.pruneColumnList(shifts); @@ -649,353 +477,20 @@ public class ColumnSelection } } - /** - * This Method is used to return all the HiddenColumn regions - * - * @return empty list or List of hidden column intervals - */ - public List getHiddenColumns() - { - return hiddenColumns == null ? Collections. emptyList() - : hiddenColumns; - } - /** - * Return absolute column index for a visible column index - * - * @param column - * int column index in alignment view (count from zero) - * @return alignment column index for column - */ - public int adjustForHiddenColumns(int column) - { - int result = column; - if (hiddenColumns != null) - { - for (int i = 0; i < hiddenColumns.size(); i++) - { - int[] region = hiddenColumns.elementAt(i); - if (result >= region[0]) - { - result += region[1] - region[0] + 1; - } - } - } - return result; - } - - /** - * Use this method to find out where a column will appear in the visible - * alignment when hidden columns exist. If the column is not visible, then the - * left-most visible column will always be returned. - * - * @param hiddenColumn - * the column index in the full alignment including hidden columns - * @return the position of the column in the visible alignment - */ - public int findColumnPosition(int hiddenColumn) - { - int result = hiddenColumn; - if (hiddenColumns != null) - { - int index = 0; - int[] region; - do - { - region = hiddenColumns.elementAt(index++); - if (hiddenColumn > region[1]) - { - result -= region[1] + 1 - region[0]; - } - } while ((hiddenColumn > region[1]) && (index < hiddenColumns.size())); - - if (hiddenColumn >= region[0] && hiddenColumn <= region[1]) - { - // Here the hidden column is within a region, so - // we want to return the position of region[0]-1, adjusted for any - // earlier hidden columns. - // Calculate the difference between the actual hidden col position - // and region[0]-1, and then subtract from result to convert result from - // the adjusted hiddenColumn value to the adjusted region[0]-1 value - - // However, if the region begins at 0 we cannot return region[0]-1 - // just return 0 - if (region[0] == 0) - { - return 0; - } - else - { - return result - (hiddenColumn - region[0] + 1); - } - } - } - return result; // return the shifted position after removing hidden columns. - } - - /** - * Find the visible column which is a given visible number of columns to the - * left of another visible column. i.e. for a startColumn x, the column which - * is distance 1 away will be column x-1. - * - * @param visibleDistance - * the number of visible columns to offset by - * @param startColumn - * the column to start from - * @return the position of the column in the visible alignment - */ - public int subtractVisibleColumns(int visibleDistance, int startColumn) - { - int distance = visibleDistance; - - // in case startColumn is in a hidden region, move it to the left - int start = adjustForHiddenColumns(findColumnPosition(startColumn)); - - // get index of hidden region to left of start - int index = getHiddenIndexLeft(start); - if (index == -1) - { - // no hidden regions to left of startColumn - return start - distance; - } - - // walk backwards through the alignment subtracting the counts of visible - // columns from distance - int[] region; - int gap = 0; - int nextstart = start; - - while ((index > -1) && (distance - gap > 0)) - { - // subtract the gap to right of region from distance - distance -= gap; - start = nextstart; - - // calculate the next gap - region = hiddenColumns.get(index); - gap = start - region[1]; - - // set start to just to left of current region - nextstart = region[0] - 1; - index--; - } - - if (distance - gap > 0) - { - // fell out of loop because there are no more hidden regions - distance -= gap; - return nextstart - distance; - } - return start - distance; - - } - - /** - * Use this method to determine where the next hiddenRegion starts - * - * @param hiddenRegion - * index of hidden region (counts from 0) - * @return column number in visible view - */ - public int findHiddenRegionPosition(int hiddenRegion) - { - int result = 0; - if (hiddenColumns != null) - { - int index = 0; - int gaps = 0; - do - { - int[] region = hiddenColumns.elementAt(index); - if (hiddenRegion == 0) - { - return region[0]; - } - - gaps += region[1] + 1 - region[0]; - result = region[1] + 1; - index++; - } while (index <= hiddenRegion); - - result -= gaps; - } - - return result; - } - - /** - * THis method returns the rightmost limit of a region of an alignment with - * hidden columns. In otherwords, the next hidden column. - * - * @param index - * int - */ - public int getHiddenBoundaryRight(int alPos) - { - if (hiddenColumns != null) - { - int index = 0; - do - { - int[] region = hiddenColumns.elementAt(index); - if (alPos < region[0]) - { - return region[0]; - } - - index++; - } while (index < hiddenColumns.size()); - } - - return alPos; - - } - - /** - * This method returns the leftmost limit of a region of an alignment with - * hidden columns. In otherwords, the previous hidden column. - * - * @param index - * int - */ - public int getHiddenBoundaryLeft(int alPos) - { - if (hiddenColumns != null) - { - int index = hiddenColumns.size() - 1; - do - { - int[] region = hiddenColumns.elementAt(index); - if (alPos > region[1]) - { - return region[1]; - } - - index--; - } while (index > -1); - } - - return alPos; - - } - - /** - * This method returns the index of the hidden region to the left of a column - * position. If the column is in a hidden region it returns the index of the - * region to the left. If there is no hidden region to the left it returns -1. - * - * @param pos - * int - */ - private int getHiddenIndexLeft(int pos) - { - if (hiddenColumns != null) - { - int index = hiddenColumns.size() - 1; - do - { - int[] region = hiddenColumns.elementAt(index); - if (pos > region[1]) - { - return index; - } - - index--; - } while (index > -1); - } - - return -1; - - } - - public void hideSelectedColumns() + public void hideSelectedColumns(AlignmentI al) { synchronized (selection) { for (int[] selregions : selection.getRanges()) { - hideColumns(selregions[0], selregions[1]); + al.getHiddenColumns().hideColumns(selregions[0], selregions[1]); } selection.clear(); } } - /** - * Adds the specified column range to the hidden columns - * - * @param start - * @param end - */ - public void hideColumns(int start, int end) - { - if (hiddenColumns == null) - { - hiddenColumns = new Vector(); - } - - /* - * traverse existing hidden ranges and insert / amend / append as - * appropriate - */ - for (int i = 0; i < hiddenColumns.size(); i++) - { - int[] region = hiddenColumns.elementAt(i); - - if (end < region[0] - 1) - { - /* - * insert discontiguous preceding range - */ - hiddenColumns.insertElementAt(new int[] { start, end }, i); - return; - } - - if (end <= region[1]) - { - /* - * new range overlaps existing, or is contiguous preceding it - adjust - * start column - */ - region[0] = Math.min(region[0], start); - return; - } - - if (start <= region[1] + 1) - { - /* - * new range overlaps existing, or is contiguous following it - adjust - * start and end columns - */ - region[0] = Math.min(region[0], start); - region[1] = Math.max(region[1], end); - - /* - * also update or remove any subsequent ranges - * that are overlapped - */ - while (i < hiddenColumns.size() - 1) - { - int[] nextRegion = hiddenColumns.get(i + 1); - if (nextRegion[0] > end + 1) - { - /* - * gap to next hidden range - no more to update - */ - break; - } - region[1] = Math.max(nextRegion[1], end); - hiddenColumns.remove(i + 1); - } - return; - } - } - - /* - * remaining case is that the new range follows everything else - */ - hiddenColumns.addElement(new int[] { start, end }); - } /** * Hides the specified column and any adjacent selected columns @@ -1003,7 +498,7 @@ public class ColumnSelection * @param res * int */ - public void hideColumns(int col) + public void hideSelectedColumns(int col, AlignmentI al) { /* * deselect column (whether selected or not!) @@ -1036,72 +531,12 @@ public class ColumnSelection min = max; } - hideColumns(min, max); + al.getHiddenColumns().hideColumns(min, max); } - /** - * Unhides, and adds to the selection list, all hidden columns - */ - public void revealAllHiddenColumns() - { - if (hiddenColumns != null) - { - for (int i = 0; i < hiddenColumns.size(); i++) - { - int[] region = hiddenColumns.elementAt(i); - for (int j = region[0]; j < region[1] + 1; j++) - { - addElement(j); - } - } - } - - hiddenColumns = null; - } - - /** - * Reveals, and marks as selected, the hidden column range with the given - * start column - * - * @param start - */ - public void revealHiddenColumns(int start) - { - for (int i = 0; i < hiddenColumns.size(); i++) - { - int[] region = hiddenColumns.elementAt(i); - if (start == region[0]) - { - for (int j = region[0]; j < region[1] + 1; j++) - { - addElement(j); - } - hiddenColumns.removeElement(region); - break; - } - } - if (hiddenColumns.size() == 0) - { - hiddenColumns = null; - } - } - public boolean isVisible(int column) - { - if (hiddenColumns != null) - { - for (int[] region : hiddenColumns) - { - if (column >= region[0] && column <= region[1]) - { - return false; - } - } - } - return true; - } /** * Copy constructor @@ -1113,21 +548,6 @@ public class ColumnSelection if (copy != null) { selection = new IntList(copy.selection); - if (copy.hiddenColumns != null) - { - hiddenColumns = new Vector(copy.hiddenColumns.size()); - for (int i = 0, j = copy.hiddenColumns.size(); i < j; i++) - { - int[] rh, cp; - rh = copy.hiddenColumns.elementAt(i); - if (rh != null) - { - cp = new int[rh.length]; - System.arraycopy(rh, 0, cp, 0, rh.length); - hiddenColumns.addElement(cp); - } - } - } } } @@ -1138,312 +558,10 @@ public class ColumnSelection { } - public String[] getVisibleSequenceStrings(int start, int end, - SequenceI[] seqs) - { - int i, iSize = seqs.length; - String selections[] = new String[iSize]; - if (hiddenColumns != null && hiddenColumns.size() > 0) - { - for (i = 0; i < iSize; i++) - { - StringBuffer visibleSeq = new StringBuffer(); - List regions = getHiddenColumns(); - - int blockStart = start, blockEnd = end; - int[] region; - int hideStart, hideEnd; - - for (int j = 0; j < regions.size(); j++) - { - region = regions.get(j); - hideStart = region[0]; - hideEnd = region[1]; - - if (hideStart < start) - { - continue; - } - - blockStart = Math.min(blockStart, hideEnd + 1); - blockEnd = Math.min(blockEnd, hideStart); - - if (blockStart > blockEnd) - { - break; - } - - visibleSeq.append(seqs[i].getSequence(blockStart, blockEnd)); - - blockStart = hideEnd + 1; - blockEnd = end; - } - - if (end > blockStart) - { - visibleSeq.append(seqs[i].getSequence(blockStart, end)); - } - - selections[i] = visibleSeq.toString(); - } - } - else - { - for (i = 0; i < iSize; i++) - { - selections[i] = seqs[i].getSequenceAsString(start, end); - } - } - - return selections; - } - - /** - * return all visible segments between the given start and end boundaries - * - * @param start - * (first column inclusive from 0) - * @param end - * (last column - not inclusive) - * @return int[] {i_start, i_end, ..} where intervals lie in - * start<=i_start<=i_end 0) - { - List visiblecontigs = new ArrayList(); - List regions = getHiddenColumns(); - - int vstart = start; - int[] region; - int hideStart, hideEnd; - - for (int j = 0; vstart < end && j < regions.size(); j++) - { - region = regions.get(j); - hideStart = region[0]; - hideEnd = region[1]; - - if (hideEnd < vstart) - { - continue; - } - if (hideStart > vstart) - { - visiblecontigs.add(new int[] { vstart, hideStart - 1 }); - } - vstart = hideEnd + 1; - } - - if (vstart < end) - { - visiblecontigs.add(new int[] { vstart, end - 1 }); - } - int[] vcontigs = new int[visiblecontigs.size() * 2]; - for (int i = 0, j = visiblecontigs.size(); i < j; i++) - { - int[] vc = visiblecontigs.get(i); - visiblecontigs.set(i, null); - vcontigs[i * 2] = vc[0]; - vcontigs[i * 2 + 1] = vc[1]; - } - visiblecontigs.clear(); - return vcontigs; - } - else - { - return new int[] { start, end - 1 }; - } - } - - /** - * Locate the first and last position visible for this sequence. if seq isn't - * visible then return the position of the left and right of the hidden - * boundary region, and the corresponding alignment column indices for the - * extent of the sequence - * - * @param seq - * @return int[] { visible start, visible end, first seqpos, last seqpos, - * alignment index for seq start, alignment index for seq end } - */ - public int[] locateVisibleBoundsOfSequence(SequenceI seq) - { - int fpos = seq.getStart(), lpos = seq.getEnd(); - int start = 0; - - if (hiddenColumns == null || hiddenColumns.size() == 0) - { - int ifpos = seq.findIndex(fpos) - 1, ilpos = seq.findIndex(lpos) - 1; - return new int[] { ifpos, ilpos, fpos, lpos, ifpos, ilpos }; - } - - // Simply walk along the sequence whilst watching for hidden column - // boundaries - List regions = getHiddenColumns(); - int spos = fpos, lastvispos = -1, rcount = 0, hideStart = seq - .getLength(), hideEnd = -1; - int visPrev = 0, visNext = 0, firstP = -1, lastP = -1; - boolean foundStart = false; - for (int p = 0, pLen = seq.getLength(); spos <= seq.getEnd() - && p < pLen; p++) - { - if (!Comparison.isGap(seq.getCharAt(p))) - { - // keep track of first/last column - // containing sequence data regardless of visibility - if (firstP == -1) - { - firstP = p; - } - lastP = p; - // update hidden region start/end - while (hideEnd < p && rcount < regions.size()) - { - int[] region = regions.get(rcount++); - visPrev = visNext; - visNext += region[0] - visPrev; - hideStart = region[0]; - hideEnd = region[1]; - } - if (hideEnd < p) - { - hideStart = seq.getLength(); - } - // update visible boundary for sequence - if (p < hideStart) - { - if (!foundStart) - { - fpos = spos; - start = p; - foundStart = true; - } - lastvispos = p; - lpos = spos; - } - // look for next sequence position - spos++; - } - } - if (foundStart) - { - return new int[] { findColumnPosition(start), - findColumnPosition(lastvispos), fpos, lpos, firstP, lastP }; - } - // otherwise, sequence was completely hidden - return new int[] { visPrev, visNext, 0, 0, firstP, lastP }; - } - - /** - * delete any columns in alignmentAnnotation that are hidden (including - * sequence associated annotation). - * - * @param alignmentAnnotation - */ - public void makeVisibleAnnotation(AlignmentAnnotation alignmentAnnotation) - { - makeVisibleAnnotation(-1, -1, alignmentAnnotation); - } - - /** - * delete any columns in alignmentAnnotation that are hidden (including - * sequence associated annotation). - * - * @param start - * remove any annotation to the right of this column - * @param end - * remove any annotation to the left of this column - * @param alignmentAnnotation - * the annotation to operate on - */ - public void makeVisibleAnnotation(int start, int end, - AlignmentAnnotation alignmentAnnotation) - { - if (alignmentAnnotation.annotations == null) - { - return; - } - if (start == end && end == -1) - { - start = 0; - end = alignmentAnnotation.annotations.length; - } - if (hiddenColumns != null && hiddenColumns.size() > 0) - { - // then mangle the alignmentAnnotation annotation array - Vector annels = new Vector(); - Annotation[] els = null; - List regions = getHiddenColumns(); - int blockStart = start, blockEnd = end; - int[] region; - int hideStart, hideEnd, w = 0; - - for (int j = 0; j < regions.size(); j++) - { - region = regions.get(j); - hideStart = region[0]; - hideEnd = region[1]; - - if (hideStart < start) - { - continue; - } - - blockStart = Math.min(blockStart, hideEnd + 1); - blockEnd = Math.min(blockEnd, hideStart); - - if (blockStart > blockEnd) - { - break; - } - annels.addElement(els = new Annotation[blockEnd - blockStart]); - System.arraycopy(alignmentAnnotation.annotations, blockStart, els, - 0, els.length); - w += els.length; - blockStart = hideEnd + 1; - blockEnd = end; - } - if (end > blockStart) - { - annels.addElement(els = new Annotation[end - blockStart + 1]); - if ((els.length + blockStart) <= alignmentAnnotation.annotations.length) - { - // copy just the visible segment of the annotation row - System.arraycopy(alignmentAnnotation.annotations, blockStart, - els, 0, els.length); - } - else - { - // copy to the end of the annotation row - System.arraycopy(alignmentAnnotation.annotations, blockStart, - els, 0, - (alignmentAnnotation.annotations.length - blockStart)); - } - w += els.length; - } - if (w == 0) - { - return; - } - alignmentAnnotation.annotations = new Annotation[w]; - w = 0; - for (Annotation[] chnk : annels) - { - System.arraycopy(chnk, 0, alignmentAnnotation.annotations, w, - chnk.length); - w += chnk.length; - } - } - else - { - alignmentAnnotation.restrict(start, end); - } - } /** * Invert the column selection from first to end-1. leaves hiddenColumns @@ -1452,9 +570,9 @@ public class ColumnSelection * @param first * @param end */ - public void invertColumnSelection(int first, int width) + public void invertColumnSelection(int first, int width, AlignmentI al) { - boolean hasHidden = hiddenColumns != null && hiddenColumns.size() > 0; + boolean hasHidden = al.getHiddenColumns().hasHidden(); for (int i = first; i < width; i++) { if (contains(i)) @@ -1463,7 +581,7 @@ public class ColumnSelection } else { - if (!hasHidden || isVisible(i)) + if (!hasHidden || al.getHiddenColumns().isVisible(i)) { addElement(i); } @@ -1483,7 +601,8 @@ public class ColumnSelection { for (Integer col : colsel.getSelected()) { - if (hiddenColumns != null && isVisible(col.intValue())) + if (hiddenColumns != null + && hiddenColumns.isVisible(col.intValue())) { selection.add(col); } @@ -1502,7 +621,7 @@ public class ColumnSelection selection = new IntList(); if (colsel.selection != null && colsel.selection.size() > 0) { - if (hiddenColumns != null && hiddenColumns.size() > 0) + if (hiddenColumns.hasHidden()) { // only select visible columns in this columns selection addElementsFrom(colsel); @@ -1538,7 +657,7 @@ public class ColumnSelection // return propagateInsertions(profileseq, al, ) char gc = al.getGapCharacter(); - Object[] alandcolsel = input.getAlignmentAndColumnSelection(gc); + Object[] alandcolsel = input.getAlignmentAndHiddenColumns(gc); ColumnSelection nview = (ColumnSelection) alandcolsel[1]; SequenceI origseq = ((SequenceI[]) alandcolsel[0])[profsqpos]; nview.propagateInsertions(profileseq, al, origseq); @@ -1555,18 +674,18 @@ public class ColumnSelection * - sequence corresponding to profileseq which defines gap map for * modifying al */ - public void propagateInsertions(SequenceI profileseq, AlignmentI al, + private void propagateInsertions(SequenceI profileseq, AlignmentI al, SequenceI origseq) { char gc = al.getGapCharacter(); // recover mapping between sequence's non-gap positions and positions // mapping to view. pruneDeletions(ShiftList.parseMap(origseq.gapMap())); - int[] viscontigs = getVisibleContigs(0, profileseq.getLength()); + int[] viscontigs = hiddenColumns.getVisibleContigs(0, + profileseq.getLength()); int spos = 0; int offset = 0; - // input.pruneDeletions(ShiftList.parseMap(((SequenceI[]) - // alandcolsel[0])[0].gapMap())) + // add profile to visible contigs for (int v = 0; v < viscontigs.length; v += 2) { @@ -1670,45 +789,14 @@ public class ColumnSelection return (selection != null && selection.size() > 0); } - /** - * - * @return true if there are columns hidden - */ - public boolean hasHiddenColumns() - { - return hiddenColumns != null && hiddenColumns.size() > 0; - } - - /** - * - * @return true if there are more than one set of columns hidden - */ - public boolean hasManyHiddenColumns() - { - return hiddenColumns != null && hiddenColumns.size() > 1; - } - /** - * mark the columns corresponding to gap characters as hidden in the column - * selection - * - * @param sr - */ - public void hideInsertionsFor(SequenceI sr) - { - List inserts = sr.getInsertions(); - for (int[] r : inserts) - { - hideColumns(r[0], r[1]); - } - } public boolean filterAnnotations(Annotation[] annotations, AnnotationFilterParameter filterParams) { // JBPNote - this method needs to be refactored to become independent of // viewmodel package - this.revealAllHiddenColumns(); + hiddenColumns.revealAllHiddenColumns(this); this.clear(); int count = 0; do @@ -1797,15 +885,7 @@ public class ColumnSelection public int hashCode() { int hashCode = selection.hashCode(); - if (hiddenColumns != null) - { - for (int[] hidden : hiddenColumns) - { - hashCode = 31 * hashCode + hidden[0]; - hashCode = 31 * hashCode + hidden[1]; - } - } - return hashCode; + return hiddenColumns.hashCode(hashCode); } /** @@ -1836,28 +916,7 @@ public class ColumnSelection return false; } - /* - * check hidden columns are either both null, or match - */ - if (this.hiddenColumns == null) - { - return (that.hiddenColumns == null); - } - if (that.hiddenColumns == null - || that.hiddenColumns.size() != this.hiddenColumns.size()) - { - return false; - } - int i = 0; - for (int[] thisRange : hiddenColumns) - { - int[] thatRange = that.hiddenColumns.get(i++); - if (thisRange[0] != thatRange[0] || thisRange[1] != thatRange[1]) - { - return false; - } - } - return true; + return this.hiddenColumns.equals(that.hiddenColumns); } /** diff --git a/src/jalview/datamodel/HiddenColumns.java b/src/jalview/datamodel/HiddenColumns.java new file mode 100644 index 0000000..0b7e246 --- /dev/null +++ b/src/jalview/datamodel/HiddenColumns.java @@ -0,0 +1,1050 @@ +package jalview.datamodel; + +import jalview.util.Comparison; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Vector; + +public class HiddenColumns +{ + /* + * list of hidden column [start, end] ranges; the list is maintained in + * ascending start column order + */ + private Vector hiddenColumns; + + /** + * This Method is used to return all the HiddenColumn regions + * + * @return empty list or List of hidden column intervals + */ + public List getListOfCols() + { + return hiddenColumns == null ? Collections. emptyList() + : hiddenColumns; + } + + public boolean hasHidden() + { + return (hiddenColumns != null) && (!hiddenColumns.isEmpty()); + } + + @Override + public boolean equals(Object obj) + { + if (!(obj instanceof HiddenColumns)) + { + return false; + } + HiddenColumns that = (HiddenColumns) obj; + + /* + * check hidden columns are either both null, or match + */ + if (this.hiddenColumns == null) + { + return (that.hiddenColumns == null); + } + if (that.hiddenColumns == null + || that.hiddenColumns.size() != this.hiddenColumns.size()) + { + return false; + } + int i = 0; + for (int[] thisRange : hiddenColumns) + { + int[] thatRange = that.hiddenColumns.get(i++); + if (thisRange[0] != thatRange[0] || thisRange[1] != thatRange[1]) + { + return false; + } + } + return true; + } + + /** + * Return absolute column index for a visible column index + * + * @param column + * int column index in alignment view (count from zero) + * @return alignment column index for column + */ + public int adjustForHiddenColumns(int column) + { + int result = column; + if (hiddenColumns != null) + { + for (int i = 0; i < hiddenColumns.size(); i++) + { + int[] region = hiddenColumns.elementAt(i); + if (result >= region[0]) + { + result += region[1] - region[0] + 1; + } + } + } + return result; + } + + /** + * Use this method to find out where a column will appear in the visible + * alignment when hidden columns exist. If the column is not visible, then the + * left-most visible column will always be returned. + * + * @param hiddenColumn + * the column index in the full alignment including hidden columns + * @return the position of the column in the visible alignment + */ + public int findColumnPosition(int hiddenColumn) + { + int result = hiddenColumn; + if (hiddenColumns != null) + { + int index = 0; + int[] region; + do + { + region = hiddenColumns.elementAt(index++); + if (hiddenColumn > region[1]) + { + result -= region[1] + 1 - region[0]; + } + } while ((hiddenColumn > region[1]) && (index < hiddenColumns.size())); + + if (hiddenColumn >= region[0] && hiddenColumn <= region[1]) + { + // Here the hidden column is within a region, so + // we want to return the position of region[0]-1, adjusted for any + // earlier hidden columns. + // Calculate the difference between the actual hidden col position + // and region[0]-1, and then subtract from result to convert result from + // the adjusted hiddenColumn value to the adjusted region[0]-1 value + + // However, if the region begins at 0 we cannot return region[0]-1 + // just return 0 + if (region[0] == 0) + { + return 0; + } + else + { + return result - (hiddenColumn - region[0] + 1); + } + } + } + return result; // return the shifted position after removing hidden columns. + } + + /** + * Find the visible column which is a given visible number of columns to the + * left of another visible column. i.e. for a startColumn x, the column which + * is distance 1 away will be column x-1. + * + * @param visibleDistance + * the number of visible columns to offset by + * @param startColumn + * the column to start from + * @return the position of the column in the visible alignment + */ + public int subtractVisibleColumns(int visibleDistance, int startColumn) + { + int distance = visibleDistance; + + // in case startColumn is in a hidden region, move it to the left + int start = adjustForHiddenColumns(findColumnPosition(startColumn)); + + // get index of hidden region to left of start + int index = getHiddenIndexLeft(start); + if (index == -1) + { + // no hidden regions to left of startColumn + return start - distance; + } + + // walk backwards through the alignment subtracting the counts of visible + // columns from distance + int[] region; + int gap = 0; + int nextstart = start; + + while ((index > -1) && (distance - gap > 0)) + { + // subtract the gap to right of region from distance + distance -= gap; + start = nextstart; + + // calculate the next gap + region = hiddenColumns.get(index); + gap = start - region[1]; + + // set start to just to left of current region + nextstart = region[0] - 1; + index--; + } + + if (distance - gap > 0) + { + // fell out of loop because there are no more hidden regions + distance -= gap; + return nextstart - distance; + } + return start - distance; + + } + + /** + * Use this method to determine where the next hiddenRegion starts + * + * @param hiddenRegion + * index of hidden region (counts from 0) + * @return column number in visible view + */ + public int findHiddenRegionPosition(int hiddenRegion) + { + int result = 0; + if (hiddenColumns != null) + { + int index = 0; + int gaps = 0; + do + { + int[] region = hiddenColumns.elementAt(index); + if (hiddenRegion == 0) + { + return region[0]; + } + + gaps += region[1] + 1 - region[0]; + result = region[1] + 1; + index++; + } while (index <= hiddenRegion); + + result -= gaps; + } + + return result; + } + + /** + * This method returns the rightmost limit of a region of an alignment with + * hidden columns. In otherwords, the next hidden column. + * + * @param index + * int + */ + public int getHiddenBoundaryRight(int alPos) + { + if (hiddenColumns != null) + { + int index = 0; + do + { + int[] region = hiddenColumns.elementAt(index); + if (alPos < region[0]) + { + return region[0]; + } + + index++; + } while (index < hiddenColumns.size()); + } + + return alPos; + + } + + /** + * This method returns the leftmost limit of a region of an alignment with + * hidden columns. In otherwords, the previous hidden column. + * + * @param index + * int + */ + public int getHiddenBoundaryLeft(int alPos) + { + if (hiddenColumns != null) + { + int index = hiddenColumns.size() - 1; + do + { + int[] region = hiddenColumns.elementAt(index); + if (alPos > region[1]) + { + return region[1]; + } + + index--; + } while (index > -1); + } + + return alPos; + + } + + /** + * This method returns the index of the hidden region to the left of a column + * position. If the column is in a hidden region it returns the index of the + * region to the left. If there is no hidden region to the left it returns -1. + * + * @param pos + * int + */ + private int getHiddenIndexLeft(int pos) + { + if (hiddenColumns != null) + { + int index = hiddenColumns.size() - 1; + do + { + int[] region = hiddenColumns.elementAt(index); + if (pos > region[1]) + { + return index; + } + + index--; + } while (index > -1); + } + + return -1; + + } + + /** + * Adds the specified column range to the hidden columns + * + * @param start + * @param end + */ + public void hideColumns(int start, int end) + { + if (hiddenColumns == null) + { + hiddenColumns = new Vector(); + } + + /* + * traverse existing hidden ranges and insert / amend / append as + * appropriate + */ + for (int i = 0; i < hiddenColumns.size(); i++) + { + int[] region = hiddenColumns.elementAt(i); + + if (end < region[0] - 1) + { + /* + * insert discontiguous preceding range + */ + hiddenColumns.insertElementAt(new int[] { start, end }, i); + return; + } + + if (end <= region[1]) + { + /* + * new range overlaps existing, or is contiguous preceding it - adjust + * start column + */ + region[0] = Math.min(region[0], start); + return; + } + + if (start <= region[1] + 1) + { + /* + * new range overlaps existing, or is contiguous following it - adjust + * start and end columns + */ + region[0] = Math.min(region[0], start); + region[1] = Math.max(region[1], end); + + /* + * also update or remove any subsequent ranges + * that are overlapped + */ + while (i < hiddenColumns.size() - 1) + { + int[] nextRegion = hiddenColumns.get(i + 1); + if (nextRegion[0] > end + 1) + { + /* + * gap to next hidden range - no more to update + */ + break; + } + region[1] = Math.max(nextRegion[1], end); + hiddenColumns.remove(i + 1); + } + return; + } + } + + /* + * remaining case is that the new range follows everything else + */ + hiddenColumns.addElement(new int[] { start, end }); + } + + public boolean isVisible(int column) + { + if (hiddenColumns != null) + { + for (int[] region : hiddenColumns) + { + if (column >= region[0] && column <= region[1]) + { + return false; + } + } + } + + return true; + } + + /** + * ColumnSelection + */ + public HiddenColumns() + { + } + + /** + * Copy constructor + * + * @param copy + */ + public HiddenColumns(HiddenColumns copy) + { + if (copy != null) + { + if (copy.hiddenColumns != null) + { + hiddenColumns = new Vector(copy.hiddenColumns.size()); + for (int i = 0, j = copy.hiddenColumns.size(); i < j; i++) + { + int[] rh, cp; + rh = copy.hiddenColumns.elementAt(i); + if (rh != null) + { + cp = new int[rh.length]; + System.arraycopy(rh, 0, cp, 0, rh.length); + hiddenColumns.addElement(cp); + } + } + } + } + } + + /** + * propagate shift in alignment columns to column selection + * + * @param start + * beginning of edit + * @param left + * shift in edit (+ve for removal, or -ve for inserts) + */ + public List compensateForEdit(int start, int change, + ColumnSelection sel) + { + List deletedHiddenColumns = null; + + if (hiddenColumns != null) + { + deletedHiddenColumns = new ArrayList(); + int hSize = hiddenColumns.size(); + for (int i = 0; i < hSize; i++) + { + int[] region = hiddenColumns.elementAt(i); + if (region[0] > start && start + change > region[1]) + { + deletedHiddenColumns.add(region); + + hiddenColumns.removeElementAt(i); + i--; + hSize--; + continue; + } + + if (region[0] > start) + { + region[0] -= change; + region[1] -= change; + } + + if (region[0] < 0) + { + region[0] = 0; + } + + } + + this.revealHiddenColumns(0, sel); + } + + return deletedHiddenColumns; + } + + /** + * propagate shift in alignment columns to column selection special version of + * compensateForEdit - allowing for edits within hidden regions + * + * @param start + * beginning of edit + * @param left + * shift in edit (+ve for removal, or -ve for inserts) + */ + public void compensateForDelEdits(int start, int change) + { + if (hiddenColumns != null) + { + for (int i = 0; i < hiddenColumns.size(); i++) + { + int[] region = hiddenColumns.elementAt(i); + if (region[0] >= start) + { + region[0] -= change; + } + if (region[1] >= start) + { + region[1] -= change; + } + if (region[1] < region[0]) + { + hiddenColumns.removeElementAt(i--); + } + + if (region[0] < 0) + { + region[0] = 0; + } + if (region[1] < 0) + { + region[1] = 0; + } + } + } + } + + /** + * return all visible segments between the given start and end boundaries + * + * @param start + * (first column inclusive from 0) + * @param end + * (last column - not inclusive) + * @return int[] {i_start, i_end, ..} where intervals lie in + * start<=i_start<=i_end 0) + { + List visiblecontigs = new ArrayList(); + List regions = getListOfCols(); + + int vstart = start; + int[] region; + int hideStart, hideEnd; + + for (int j = 0; vstart < end && j < regions.size(); j++) + { + region = regions.get(j); + hideStart = region[0]; + hideEnd = region[1]; + + if (hideEnd < vstart) + { + continue; + } + if (hideStart > vstart) + { + visiblecontigs.add(new int[] { vstart, hideStart - 1 }); + } + vstart = hideEnd + 1; + } + + if (vstart < end) + { + visiblecontigs.add(new int[] { vstart, end - 1 }); + } + int[] vcontigs = new int[visiblecontigs.size() * 2]; + for (int i = 0, j = visiblecontigs.size(); i < j; i++) + { + int[] vc = visiblecontigs.get(i); + visiblecontigs.set(i, null); + vcontigs[i * 2] = vc[0]; + vcontigs[i * 2 + 1] = vc[1]; + } + visiblecontigs.clear(); + return vcontigs; + } + else + { + return new int[] { start, end - 1 }; + } + } + + public String[] getVisibleSequenceStrings(int start, int end, + SequenceI[] seqs) + { + int i, iSize = seqs.length; + String selections[] = new String[iSize]; + if (hiddenColumns != null && hiddenColumns.size() > 0) + { + for (i = 0; i < iSize; i++) + { + StringBuffer visibleSeq = new StringBuffer(); + List regions = getListOfCols(); + + int blockStart = start, blockEnd = end; + int[] region; + int hideStart, hideEnd; + + for (int j = 0; j < regions.size(); j++) + { + region = regions.get(j); + hideStart = region[0]; + hideEnd = region[1]; + + if (hideStart < start) + { + continue; + } + + blockStart = Math.min(blockStart, hideEnd + 1); + blockEnd = Math.min(blockEnd, hideStart); + + if (blockStart > blockEnd) + { + break; + } + + visibleSeq.append(seqs[i].getSequence(blockStart, blockEnd)); + + blockStart = hideEnd + 1; + blockEnd = end; + } + + if (end > blockStart) + { + visibleSeq.append(seqs[i].getSequence(blockStart, end)); + } + + selections[i] = visibleSeq.toString(); + } + } + else + { + for (i = 0; i < iSize; i++) + { + selections[i] = seqs[i].getSequenceAsString(start, end); + } + } + + return selections; + } + + /** + * Locate the first and last position visible for this sequence. if seq isn't + * visible then return the position of the left and right of the hidden + * boundary region, and the corresponding alignment column indices for the + * extent of the sequence + * + * @param seq + * @return int[] { visible start, visible end, first seqpos, last seqpos, + * alignment index for seq start, alignment index for seq end } + */ + public int[] locateVisibleBoundsOfSequence(SequenceI seq) + { + int fpos = seq.getStart(), lpos = seq.getEnd(); + int start = 0; + + if (hiddenColumns == null || hiddenColumns.size() == 0) + { + int ifpos = seq.findIndex(fpos) - 1, ilpos = seq.findIndex(lpos) - 1; + return new int[] { ifpos, ilpos, fpos, lpos, ifpos, ilpos }; + } + + // Simply walk along the sequence whilst watching for hidden column + // boundaries + List regions = getListOfCols(); + int spos = fpos, lastvispos = -1, rcount = 0, hideStart = seq + .getLength(), hideEnd = -1; + int visPrev = 0, visNext = 0, firstP = -1, lastP = -1; + boolean foundStart = false; + for (int p = 0, pLen = seq.getLength(); spos <= seq.getEnd() + && p < pLen; p++) + { + if (!Comparison.isGap(seq.getCharAt(p))) + { + // keep track of first/last column + // containing sequence data regardless of visibility + if (firstP == -1) + { + firstP = p; + } + lastP = p; + // update hidden region start/end + while (hideEnd < p && rcount < regions.size()) + { + int[] region = regions.get(rcount++); + visPrev = visNext; + visNext += region[0] - visPrev; + hideStart = region[0]; + hideEnd = region[1]; + } + if (hideEnd < p) + { + hideStart = seq.getLength(); + } + // update visible boundary for sequence + if (p < hideStart) + { + if (!foundStart) + { + fpos = spos; + start = p; + foundStart = true; + } + lastvispos = p; + lpos = spos; + } + // look for next sequence position + spos++; + } + } + if (foundStart) + { + return new int[] { findColumnPosition(start), + findColumnPosition(lastvispos), fpos, lpos, firstP, lastP }; + } + // otherwise, sequence was completely hidden + return new int[] { visPrev, visNext, 0, 0, firstP, lastP }; + } + + /** + * delete any columns in alignmentAnnotation that are hidden (including + * sequence associated annotation). + * + * @param alignmentAnnotation + */ + public void makeVisibleAnnotation(AlignmentAnnotation alignmentAnnotation) + { + makeVisibleAnnotation(-1, -1, alignmentAnnotation); + } + + /** + * delete any columns in alignmentAnnotation that are hidden (including + * sequence associated annotation). + * + * @param start + * remove any annotation to the right of this column + * @param end + * remove any annotation to the left of this column + * @param alignmentAnnotation + * the annotation to operate on + */ + public void makeVisibleAnnotation(int start, int end, + AlignmentAnnotation alignmentAnnotation) + { + if (alignmentAnnotation.annotations == null) + { + return; + } + if (start == end && end == -1) + { + start = 0; + end = alignmentAnnotation.annotations.length; + } + if (hiddenColumns != null && hiddenColumns.size() > 0) + { + // then mangle the alignmentAnnotation annotation array + Vector annels = new Vector(); + Annotation[] els = null; + List regions = getListOfCols(); + int blockStart = start, blockEnd = end; + int[] region; + int hideStart, hideEnd, w = 0; + + for (int j = 0; j < regions.size(); j++) + { + region = regions.get(j); + hideStart = region[0]; + hideEnd = region[1]; + + if (hideStart < start) + { + continue; + } + + blockStart = Math.min(blockStart, hideEnd + 1); + blockEnd = Math.min(blockEnd, hideStart); + + if (blockStart > blockEnd) + { + break; + } + + annels.addElement(els = new Annotation[blockEnd - blockStart]); + System.arraycopy(alignmentAnnotation.annotations, blockStart, els, + 0, els.length); + w += els.length; + blockStart = hideEnd + 1; + blockEnd = end; + } + + if (end > blockStart) + { + annels.addElement(els = new Annotation[end - blockStart + 1]); + if ((els.length + blockStart) <= alignmentAnnotation.annotations.length) + { + // copy just the visible segment of the annotation row + System.arraycopy(alignmentAnnotation.annotations, blockStart, + els, 0, els.length); + } + else + { + // copy to the end of the annotation row + System.arraycopy(alignmentAnnotation.annotations, blockStart, + els, 0, + (alignmentAnnotation.annotations.length - blockStart)); + } + w += els.length; + } + if (w == 0) + { + return; + } + + alignmentAnnotation.annotations = new Annotation[w]; + w = 0; + + for (Annotation[] chnk : annels) + { + System.arraycopy(chnk, 0, alignmentAnnotation.annotations, w, + chnk.length); + w += chnk.length; + } + } + else + { + alignmentAnnotation.restrict(start, end); + } + } + + /** + * + * @return true if there are columns hidden + */ + public boolean hasHiddenColumns() + { + return hiddenColumns != null && hiddenColumns.size() > 0; + } + + /** + * + * @return true if there are more than one set of columns hidden + */ + public boolean hasManyHiddenColumns() + { + return hiddenColumns != null && hiddenColumns.size() > 1; + } + + /** + * mark the columns corresponding to gap characters as hidden in the column + * selection + * + * @param sr + */ + public void hideInsertionsFor(SequenceI sr) + { + List inserts = sr.getInsertions(); + for (int[] r : inserts) + { + hideColumns(r[0], r[1]); + } + } + + /** + * Unhides, and adds to the selection list, all hidden columns + */ + public void revealAllHiddenColumns(ColumnSelection sel) + { + if (hiddenColumns != null) + { + for (int i = 0; i < hiddenColumns.size(); i++) + { + int[] region = hiddenColumns.elementAt(i); + for (int j = region[0]; j < region[1] + 1; j++) + { + sel.addElement(j); + } + } + } + + hiddenColumns = null; + } + + /** + * Reveals, and marks as selected, the hidden column range with the given + * start column + * + * @param start + */ + public void revealHiddenColumns(int start, ColumnSelection sel) + { + for (int i = 0; i < hiddenColumns.size(); i++) + { + int[] region = hiddenColumns.elementAt(i); + if (start == region[0]) + { + for (int j = region[0]; j < region[1] + 1; j++) + { + sel.addElement(j); + } + + hiddenColumns.removeElement(region); + break; + } + } + if (hiddenColumns.size() == 0) + { + hiddenColumns = null; + } + } + + /** + * removes intersection of position,length ranges in deletions from the + * start,end regions marked in intervals. + * + * @param shifts + * @param intervals + * @return + */ + private boolean pruneIntervalVector(final List shifts, + Vector intervals) + { + boolean pruned = false; + int i = 0, j = intervals.size() - 1, s = 0, t = shifts.size() - 1; + int hr[] = intervals.elementAt(i); + int sr[] = shifts.get(s); + while (i <= j && s <= t) + { + boolean trailinghn = hr[1] >= sr[0]; + if (!trailinghn) + { + if (i < j) + { + hr = intervals.elementAt(++i); + } + else + { + i++; + } + continue; + } + int endshift = sr[0] + sr[1]; // deletion ranges - -ve means an insert + if (endshift < hr[0] || endshift < sr[0]) + { // leadinghc disjoint or not a deletion + if (s < t) + { + sr = shifts.get(++s); + } + else + { + s++; + } + continue; + } + boolean leadinghn = hr[0] >= sr[0]; + boolean leadinghc = hr[0] < endshift; + boolean trailinghc = hr[1] < endshift; + if (leadinghn) + { + if (trailinghc) + { // deleted hidden region. + intervals.removeElementAt(i); + pruned = true; + j--; + if (i <= j) + { + hr = intervals.elementAt(i); + } + continue; + } + if (leadinghc) + { + hr[0] = endshift; // clip c terminal region + leadinghn = !leadinghn; + pruned = true; + } + } + if (!leadinghn) + { + if (trailinghc) + { + if (trailinghn) + { + hr[1] = sr[0] - 1; + pruned = true; + } + } + else + { + // sr contained in hr + if (s < t) + { + sr = shifts.get(++s); + } + else + { + s++; + } + continue; + } + } + } + return pruned; // true if any interval was removed or modified by + // operations. + } + + /** + * remove any hiddenColumns or selected columns and shift remaining based on a + * series of position, range deletions. + * + * @param deletions + */ + public void pruneDeletions(List shifts) + { + // delete any intervals intersecting. + if (hiddenColumns != null) + { + pruneIntervalVector(shifts, hiddenColumns); + if (hiddenColumns != null && hiddenColumns.size() == 0) + { + hiddenColumns = null; + } + } + } + + /** + * Returns a hashCode built from selected columns and hidden column ranges + */ + public int hashCode(int hc) + { + int hashCode = hc; + if (hiddenColumns != null) + { + for (int[] hidden : hiddenColumns) + { + hashCode = 31 * hashCode + hidden[0]; + hashCode = 31 * hashCode + hidden[1]; + } + } + return hashCode; + } + +} diff --git a/src/jalview/datamodel/SeqCigar.java b/src/jalview/datamodel/SeqCigar.java index 98b0de5..9cc7b4a 100644 --- a/src/jalview/datamodel/SeqCigar.java +++ b/src/jalview/datamodel/SeqCigar.java @@ -494,18 +494,18 @@ public class SeqCigar extends CigarSimple /** * create an alignment from the given array of cigar sequences and gap * character, and marking the given segments as visible in the given - * columselection. + * hiddenColumns. * * @param alseqs * @param gapCharacter - * @param colsel - * - columnSelection where hidden regions are marked + * @param hidden + * - hiddenColumns where hidden regions are marked * @param segments * - visible regions of alignment * @return SequenceI[] */ public static SequenceI[] createAlignmentSequences(SeqCigar[] alseqs, - char gapCharacter, ColumnSelection colsel, int[] segments) + char gapCharacter, HiddenColumns hidden, int[] segments) { SequenceI[] seqs = new SequenceI[alseqs.length]; StringBuffer[] g_seqs = new StringBuffer[alseqs.length]; @@ -577,7 +577,7 @@ public class SeqCigar extends CigarSimple if (segments == null) { // add a hidden column for this deletion - colsel.hideColumns(inspos, inspos + insert.length - 1); + hidden.hideColumns(inspos, inspos + insert.length - 1); } } } @@ -598,7 +598,7 @@ public class SeqCigar extends CigarSimple { // int start=shifts.shift(segments[i]-1)+1; // int end=shifts.shift(segments[i]+segments[i+1]-1)-1; - colsel.hideColumns(segments[i + 1], segments[i + 1] + hidden.hideColumns(segments[i + 1], segments[i + 1] + segments[i + 2] - 1); } } diff --git a/src/jalview/ext/jmol/JalviewJmolBinding.java b/src/jalview/ext/jmol/JalviewJmolBinding.java index 94df99a..00fd679 100644 --- a/src/jalview/ext/jmol/JalviewJmolBinding.java +++ b/src/jalview/ext/jmol/JalviewJmolBinding.java @@ -24,7 +24,7 @@ import jalview.api.AlignmentViewPanel; import jalview.api.FeatureRenderer; import jalview.api.SequenceRenderer; import jalview.datamodel.AlignmentI; -import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceI; import jalview.io.DataSourceType; @@ -222,11 +222,11 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel * TODO */ public void superposeStructures(AlignmentI alignment, int refStructure, - ColumnSelection hiddenCols) + HiddenColumns hiddenCols) { superposeStructures(new AlignmentI[] { alignment }, new int[] { refStructure }, - new ColumnSelection[] { hiddenCols }); + new HiddenColumns[] { hiddenCols }); } /** @@ -234,7 +234,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel */ @Override public String superposeStructures(AlignmentI[] _alignment, - int[] _refStructure, ColumnSelection[] _hiddenCols) + int[] _refStructure, HiddenColumns[] _hiddenCols) { while (viewer.isScriptExecuting()) { @@ -278,7 +278,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel { int refStructure = _refStructure[a]; AlignmentI alignment = _alignment[a]; - ColumnSelection hiddenCols = _hiddenCols[a]; + HiddenColumns hiddenCols = _hiddenCols[a]; if (a > 0 && selectioncom.length() > 0 && !selectioncom.substring(selectioncom.length() - 1).equals( diff --git a/src/jalview/ext/jmol/JmolCommands.java b/src/jalview/ext/jmol/JmolCommands.java index 23e0a6f..3e7ca59 100644 --- a/src/jalview/ext/jmol/JmolCommands.java +++ b/src/jalview/ext/jmol/JmolCommands.java @@ -25,7 +25,7 @@ import jalview.api.AlignmentViewPanel; import jalview.api.FeatureRenderer; import jalview.api.SequenceRenderer; import jalview.datamodel.AlignmentI; -import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.SequenceI; import jalview.renderer.seqfeatures.FeatureColourFinder; import jalview.structure.StructureMapping; @@ -61,7 +61,7 @@ public class JmolCommands FeatureRenderer fr = viewPanel.getFeatureRenderer(); FeatureColourFinder finder = new FeatureColourFinder(fr); AlignViewportI viewport = viewPanel.getAlignViewport(); - ColumnSelection cs = viewport.getColumnSelection(); + HiddenColumns cs = viewport.getAlignment().getHiddenColumns(); AlignmentI al = viewport.getAlignment(); List cset = new ArrayList(); diff --git a/src/jalview/ext/rbvi/chimera/ChimeraCommands.java b/src/jalview/ext/rbvi/chimera/ChimeraCommands.java index 95757fd..62aaa1c 100644 --- a/src/jalview/ext/rbvi/chimera/ChimeraCommands.java +++ b/src/jalview/ext/rbvi/chimera/ChimeraCommands.java @@ -25,7 +25,7 @@ import jalview.api.AlignmentViewPanel; import jalview.api.FeatureRenderer; import jalview.api.SequenceRenderer; import jalview.datamodel.AlignmentI; -import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceI; import jalview.renderer.seqfeatures.FeatureColourFinder; @@ -194,7 +194,7 @@ public class ChimeraCommands FeatureRenderer fr = viewPanel.getFeatureRenderer(); FeatureColourFinder finder = new FeatureColourFinder(fr); AlignViewportI viewport = viewPanel.getAlignViewport(); - ColumnSelection cs = viewport.getColumnSelection(); + HiddenColumns cs = viewport.getAlignment().getHiddenColumns(); AlignmentI al = viewport.getAlignment(); Map colourMap = new LinkedHashMap(); Color lastColour = null; diff --git a/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java b/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java index fad3137..3ae7593 100644 --- a/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java +++ b/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java @@ -25,7 +25,7 @@ import jalview.api.SequenceRenderer; import jalview.api.structures.JalviewStructureDisplayI; import jalview.bin.Cache; import jalview.datamodel.AlignmentI; -import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.PDBEntry; import jalview.datamodel.SearchResultMatchI; import jalview.datamodel.SearchResultsI; @@ -339,7 +339,7 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel */ @Override public String superposeStructures(AlignmentI[] _alignment, - int[] _refStructure, ColumnSelection[] _hiddenCols) + int[] _refStructure, HiddenColumns[] _hiddenCols) { StringBuilder allComs = new StringBuilder(128); String[] files = getPdbFile(); @@ -355,7 +355,7 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel { int refStructure = _refStructure[a]; AlignmentI alignment = _alignment[a]; - ColumnSelection hiddenCols = _hiddenCols[a]; + HiddenColumns hiddenCols = _hiddenCols[a]; if (refStructure >= files.length) { diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index d4c87d8..9cb9804 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -53,6 +53,7 @@ import jalview.datamodel.AlignmentI; import jalview.datamodel.AlignmentOrder; import jalview.datamodel.AlignmentView; import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.HiddenSequences; import jalview.datamodel.PDBEntry; import jalview.datamodel.SeqCigar; @@ -232,7 +233,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param height * height of frame. */ - public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns, + public AlignFrame(AlignmentI al, HiddenColumns hiddenColumns, int width, int height) { this(al, hiddenColumns, width, height, null); @@ -249,7 +250,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param sequenceSetId * (may be null) */ - public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns, + public AlignFrame(AlignmentI al, HiddenColumns hiddenColumns, int width, int height, String sequenceSetId) { this(al, hiddenColumns, width, height, sequenceSetId, null); @@ -268,7 +269,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param viewId * (may be null) */ - public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns, + public AlignFrame(AlignmentI al, HiddenColumns hiddenColumns, int width, int height, String sequenceSetId, String viewId) { setSize(width, height); @@ -287,7 +288,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } public AlignFrame(AlignmentI al, SequenceI[] hiddenSeqs, - ColumnSelection hiddenColumns, int width, int height) + HiddenColumns hiddenColumns, int width, int height) { setSize(width, height); @@ -1183,8 +1184,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, exportData.getAlignment(), // class cast exceptions will // occur in the distant future exportData.getOmitHidden(), exportData.getStartEndPostions(), - f.getCacheSuffixDefault(format), - viewport.getColumnSelection()); + f.getCacheSuffixDefault(format), viewport.getAlignment() + .getHiddenColumns()); if (output == null) { @@ -1262,8 +1263,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, cap.setText(new FormatAdapter(alignPanel, exportData.getSettings()) .formatSequences(format, exportData.getAlignment(), exportData.getOmitHidden(), - exportData.getStartEndPostions(), - viewport.getColumnSelection())); + exportData + .getStartEndPostions(), viewport + .getAlignment().getHiddenColumns())); Desktop.addInternalFrame(cap, MessageManager.formatMessage( "label.alignment_output_command", new Object[] { e.getActionCommand() }), 600, 500); @@ -1312,8 +1314,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, alignmentToExport = viewport.getAlignment(); } alignmentStartEnd = alignmentToExport - .getVisibleStartAndEndIndex(viewport.getColumnSelection() - .getHiddenColumns()); + .getVisibleStartAndEndIndex(viewport.getAlignment() + .getHiddenColumns() + .getListOfCols()); AlignmentExportData ed = new AlignmentExportData(alignmentToExport, omitHidden, alignmentStartEnd, settings); return ed; @@ -1877,7 +1880,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, hiddenColumns = new ArrayList(); int hiddenOffset = viewport.getSelectionGroup().getStartRes(), hiddenCutoff = viewport .getSelectionGroup().getEndRes(); - for (int[] region : viewport.getColumnSelection().getHiddenColumns()) + for (int[] region : viewport.getAlignment().getHiddenColumns() + .getListOfCols()) { if (region[0] >= hiddenOffset && region[1] <= hiddenCutoff) { @@ -4780,9 +4784,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, viewport.getAlignment(), 0, false); SequenceI repseq = viewport.getAlignment().getSequenceAt(0); viewport.getAlignment().setSeqrep(repseq); - ColumnSelection cs = new ColumnSelection(); + HiddenColumns cs = new HiddenColumns(); cs.hideInsertionsFor(repseq); - viewport.setColumnSelection(cs); + viewport.getAlignment().setHiddenColumns(cs); isAnnotation = true; } // else if (IdentifyFile.FeaturesFile.equals(format)) diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index 602e3a1..d87d947 100644 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -35,6 +35,7 @@ import jalview.datamodel.AlignedCodonFrame; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentI; import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.PDBEntry; import jalview.datamodel.SearchResults; import jalview.datamodel.SearchResultsI; @@ -147,12 +148,12 @@ public class AlignViewport extends AlignmentViewport implements * @param hiddenColumns * ColumnSelection */ - public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns) + public AlignViewport(AlignmentI al, HiddenColumns hiddenColumns) { setAlignment(al); if (hiddenColumns != null) { - colSel = hiddenColumns; + al.setHiddenColumns(hiddenColumns); } init(); } @@ -165,7 +166,7 @@ public class AlignViewport extends AlignmentViewport implements * @param seqsetid * (may be null) */ - public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns, + public AlignViewport(AlignmentI al, HiddenColumns hiddenColumns, String seqsetid) { this(al, hiddenColumns, seqsetid, null); @@ -181,7 +182,7 @@ public class AlignViewport extends AlignmentViewport implements * @param viewid * (may be null) */ - public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns, + public AlignViewport(AlignmentI al, HiddenColumns hiddenColumns, String seqsetid, String viewid) { sequenceSetID = seqsetid; @@ -199,7 +200,7 @@ public class AlignViewport extends AlignmentViewport implements setAlignment(al); if (hiddenColumns != null) { - colSel = hiddenColumns; + al.setHiddenColumns(hiddenColumns); } init(); } @@ -527,7 +528,7 @@ public class AlignViewport extends AlignmentViewport implements { end = alignment.getWidth(); } - viscontigs = colSel.getVisibleContigs(start, end); + viscontigs = alignment.getHiddenColumns().getVisibleContigs(start, end); return viscontigs; } @@ -597,7 +598,9 @@ public class AlignViewport extends AlignmentViewport implements jalview.structure.StructureSelectionManager .getStructureSelectionManager(Desktop.instance).sendSelection( new SequenceGroup(getSelectionGroup()), - new ColumnSelection(getColumnSelection()), this); + new ColumnSelection(getColumnSelection()), + new HiddenColumns(getAlignment().getHiddenColumns()), + this); } /** diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index 8ade5d6..dc5f7cc 100644 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -25,6 +25,7 @@ import jalview.api.AlignViewportI; import jalview.api.AlignmentViewPanel; import jalview.bin.Cache; import jalview.datamodel.AlignmentI; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.SearchResultsI; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceGroup; @@ -395,11 +396,12 @@ public class AlignmentPanel extends GAlignmentPanel implements } if (av.hasHiddenColumns()) { - start = av.getColumnSelection().findColumnPosition(start); - end = av.getColumnSelection().findColumnPosition(end); + HiddenColumns hidden = av.getAlignment().getHiddenColumns(); + start = hidden.findColumnPosition(start); + end = hidden.findColumnPosition(end); if (start == end) { - if (!av.getColumnSelection().isVisible(r[0])) + if (!hidden.isVisible(r[0])) { // don't scroll - position isn't visible return false; @@ -704,7 +706,8 @@ public class AlignmentPanel extends GAlignmentPanel implements if (av.hasHiddenColumns()) { // reset the width to exclude hidden columns - width = av.getColumnSelection().findColumnPosition(width); + width = av.getAlignment().getHiddenColumns() + .findColumnPosition(width); } hextent = getSeqPanel().seqCanvas.getWidth() / av.getCharWidth(); @@ -917,7 +920,8 @@ public class AlignmentPanel extends GAlignmentPanel implements if (av.hasHiddenColumns()) { - maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1; + maxwidth = av.getAlignment().getHiddenColumns() + .findColumnPosition(maxwidth) - 1; } int canvasWidth = getSeqPanel().seqCanvas @@ -1205,7 +1209,8 @@ public class AlignmentPanel extends GAlignmentPanel implements int maxwidth = av.getAlignment().getWidth(); if (av.hasHiddenColumns()) { - maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1; + maxwidth = av.getAlignment().getHiddenColumns() + .findColumnPosition(maxwidth) - 1; } int resWidth = getSeqPanel().seqCanvas.getWrappedCanvasWidth(pwidth @@ -1399,7 +1404,8 @@ public class AlignmentPanel extends GAlignmentPanel implements int maxwidth = av.getAlignment().getWidth(); if (av.hasHiddenColumns()) { - maxwidth = av.getColumnSelection().findColumnPosition(maxwidth); + maxwidth = av.getAlignment().getHiddenColumns() + .findColumnPosition(maxwidth); } int height = ((av.getAlignment().getHeight() + 1) * av.getCharHeight()) @@ -1629,7 +1635,8 @@ public class AlignmentPanel extends GAlignmentPanel implements int maxwidth = av.getAlignment().getWidth(); if (av.hasHiddenColumns()) { - maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1; + maxwidth = av.getAlignment().getHiddenColumns() + .findColumnPosition(maxwidth) - 1; } int height = ((maxwidth / chunkWidth) + 1) * cHeight; diff --git a/src/jalview/gui/AnnotationColumnChooser.java b/src/jalview/gui/AnnotationColumnChooser.java index 637eb30..fa63e0d 100644 --- a/src/jalview/gui/AnnotationColumnChooser.java +++ b/src/jalview/gui/AnnotationColumnChooser.java @@ -22,7 +22,7 @@ package jalview.gui; import jalview.datamodel.AlignmentAnnotation; -import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.schemes.AnnotationColourGradient; import jalview.util.MessageManager; import jalview.viewmodel.annotationfilter.AnnotationFilterParameter; @@ -86,7 +86,7 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements private int actionOption = ACTION_OPTION_SELECT; - private ColumnSelection oldColumnSelection; + private HiddenColumns oldHiddenColumns; public AnnotationColumnChooser(AlignViewport av, final AlignmentPanel ap) { @@ -105,7 +105,7 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements { return; } - setOldColumnSelection(av.getColumnSelection()); + setOldHiddenColumns(av.getAlignment().getHiddenColumns()); adjusting = true; setAnnotations(new JComboBox(getAnnotationItems(false))); @@ -224,26 +224,26 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements @Override protected void reset() { - if (this.getOldColumnSelection() != null) + if (this.getOldHiddenColumns() != null) { av.getColumnSelection().clear(); if (av.getAnnotationColumnSelectionState() != null) { - ColumnSelection oldSelection = av + HiddenColumns oldHidden = av .getAnnotationColumnSelectionState() - .getOldColumnSelection(); - if (oldSelection != null && oldSelection.getHiddenColumns() != null - && !oldSelection.getHiddenColumns().isEmpty()) + .getOldHiddenColumns(); + if (oldHidden != null && oldHidden.getListOfCols() != null + && !oldHidden.getListOfCols().isEmpty()) { - for (Iterator itr = oldSelection.getHiddenColumns() + for (Iterator itr = oldHidden.getListOfCols() .iterator(); itr.hasNext();) { int positions[] = itr.next(); av.hideColumns(positions[0], positions[1]); } } - av.setColumnSelection(oldSelection); + av.getAlignment().setHiddenColumns(oldHidden); } ap.paintAlignment(true); } @@ -392,16 +392,16 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements ap.paintAlignment(true); } - public ColumnSelection getOldColumnSelection() + public HiddenColumns getOldHiddenColumns() { - return oldColumnSelection; + return oldHiddenColumns; } - public void setOldColumnSelection(ColumnSelection currentColumnSelection) + public void setOldHiddenColumns(HiddenColumns currentHiddenColumns) { - if (currentColumnSelection != null) + if (currentHiddenColumns != null) { - this.oldColumnSelection = new ColumnSelection(currentColumnSelection); + this.oldHiddenColumns = new HiddenColumns(currentHiddenColumns); } } diff --git a/src/jalview/gui/AnnotationLabels.java b/src/jalview/gui/AnnotationLabels.java index c9535d0..3e4ec98 100755 --- a/src/jalview/gui/AnnotationLabels.java +++ b/src/jalview/gui/AnnotationLabels.java @@ -947,12 +947,14 @@ public class AnnotationLabels extends JPanel implements MouseListener, Alignment ds = new Alignment(dseqs); if (av.hasHiddenColumns()) { - omitHidden = av.getColumnSelection().getVisibleSequenceStrings(0, + omitHidden = av.getAlignment().getHiddenColumns() + .getVisibleSequenceStrings(0, sq.getLength(), seqs); } int[] alignmentStartEnd = new int[] { 0, ds.getWidth() - 1 }; - List hiddenCols = av.getColumnSelection().getHiddenColumns(); + List hiddenCols = av.getAlignment().getHiddenColumns() + .getListOfCols(); if (hiddenCols != null) { alignmentStartEnd = av.getAlignment().getVisibleStartAndEndIndex( @@ -968,7 +970,8 @@ public class AnnotationLabels extends JPanel implements MouseListener, if (av.hasHiddenColumns()) { hiddenColumns = new ArrayList(); - for (int[] region : av.getColumnSelection().getHiddenColumns()) + for (int[] region : av.getAlignment().getHiddenColumns() + .getListOfCols()) { hiddenColumns.add(new int[] { region[0], region[1] }); } diff --git a/src/jalview/gui/AnnotationPanel.java b/src/jalview/gui/AnnotationPanel.java index 84f3e6c..919356f 100755 --- a/src/jalview/gui/AnnotationPanel.java +++ b/src/jalview/gui/AnnotationPanel.java @@ -23,6 +23,7 @@ package jalview.gui; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.Annotation; import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.SequenceI; import jalview.renderer.AnnotationRenderer; import jalview.renderer.AwtRenderPanelI; @@ -290,7 +291,7 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, { for (int index : av.getColumnSelection().getSelected()) { - if (av.getColumnSelection().isVisible(index)) + if (av.getAlignment().getHiddenColumns().isVisible(index)) { anot[index] = null; } @@ -314,7 +315,7 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, for (int index : av.getColumnSelection().getSelected()) { - if (!av.getColumnSelection().isVisible(index)) + if (!av.getAlignment().getHiddenColumns().isVisible(index)) { continue; } @@ -337,7 +338,7 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, for (int index : av.getColumnSelection().getSelected()) { - if (!av.getColumnSelection().isVisible(index)) + if (!av.getAlignment().getHiddenColumns().isVisible(index)) { continue; } @@ -397,7 +398,7 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, } for (int index : av.getColumnSelection().getSelected()) { - if (!av.getColumnSelection().isVisible(index)) + if (!av.getAlignment().getHiddenColumns().isVisible(index)) { continue; } @@ -440,6 +441,7 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, StringBuilder collatedInput = new StringBuilder(64); String last = ""; ColumnSelection viscols = av.getColumnSelection(); + HiddenColumns hidden = av.getAlignment().getHiddenColumns(); /* * the selection list (read-only view) is in selection order, not @@ -450,7 +452,7 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, for (int index : selected) { // always check for current display state - just in case - if (!viscols.isVisible(index)) + if (!hidden.isVisible(index)) { continue; } @@ -712,7 +714,8 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, if (av.hasHiddenColumns()) { - column = av.getColumnSelection().adjustForHiddenColumns(column); + column = av.getAlignment().getHiddenColumns() + .adjustForHiddenColumns(column); } AlignmentAnnotation ann = aa[row]; diff --git a/src/jalview/gui/AppVarna.java b/src/jalview/gui/AppVarna.java index f4a4f4d..a50de77 100644 --- a/src/jalview/gui/AppVarna.java +++ b/src/jalview/gui/AppVarna.java @@ -23,6 +23,7 @@ package jalview.gui; import jalview.analysis.AlignSeq; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.RnaViewerModel; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; @@ -400,7 +401,7 @@ public class AppVarna extends JInternalFrame implements SelectionListener, @Override public void selection(SequenceGroup seqsel, ColumnSelection colsel, - SelectionSource source) + HiddenColumns hidden, SelectionSource source) { if (source != ap.av) { diff --git a/src/jalview/gui/CutAndPasteTransfer.java b/src/jalview/gui/CutAndPasteTransfer.java index 7a0b0af..a5aa9eb 100644 --- a/src/jalview/gui/CutAndPasteTransfer.java +++ b/src/jalview/gui/CutAndPasteTransfer.java @@ -28,7 +28,7 @@ import jalview.api.FeaturesDisplayedI; import jalview.api.FeaturesSourceI; import jalview.bin.Jalview; import jalview.datamodel.AlignmentI; -import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.SequenceI; import jalview.io.AlignmentFileReaderI; import jalview.io.AppletFormatAdapter; @@ -284,8 +284,8 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer AlignFrame af; if (source instanceof ComplexAlignFile) { - ColumnSelection colSel = ((ComplexAlignFile) source) - .getColumnSelection(); + HiddenColumns hidden = ((ComplexAlignFile) source) + .getHiddenColumns(); SequenceI[] hiddenSeqs = ((ComplexAlignFile) source) .getHiddenSequences(); boolean showSeqFeatures = ((ComplexAlignFile) source) @@ -294,7 +294,7 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer .getGlobalColourScheme(); FeaturesDisplayedI fd = ((ComplexAlignFile) source) .getDisplayedFeatures(); - af = new AlignFrame(al, hiddenSeqs, colSel, + af = new AlignFrame(al, hiddenSeqs, hidden, AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT); af.getViewport().setShowSequenceFeatures(showSeqFeatures); af.getViewport().setFeaturesDisplayed(fd); diff --git a/src/jalview/gui/IdCanvas.java b/src/jalview/gui/IdCanvas.java index aad0776..1b79f54 100755 --- a/src/jalview/gui/IdCanvas.java +++ b/src/jalview/gui/IdCanvas.java @@ -290,7 +290,8 @@ public class IdCanvas extends JPanel if (av.hasHiddenColumns()) { - maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1; + maxwidth = av.getAlignment().getHiddenColumns() + .findColumnPosition(maxwidth) - 1; } int annotationHeight = 0; diff --git a/src/jalview/gui/Jalview2XML.java b/src/jalview/gui/Jalview2XML.java index c19f005..962dc0d 100644 --- a/src/jalview/gui/Jalview2XML.java +++ b/src/jalview/gui/Jalview2XML.java @@ -1413,17 +1413,18 @@ public class Jalview2XML if (av.hasHiddenColumns()) { - if (av.getColumnSelection() == null - || av.getColumnSelection().getHiddenColumns() == null) + jalview.datamodel.HiddenColumns hidden = av.getAlignment() + .getHiddenColumns(); + if (hidden == null || hidden.getListOfCols() == null) { warn("REPORT BUG: avoided null columnselection bug (DMAM reported). Please contact Jim about this."); } else { - for (int c = 0; c < av.getColumnSelection().getHiddenColumns() + for (int c = 0; c < hidden.getListOfCols() .size(); c++) { - int[] region = av.getColumnSelection().getHiddenColumns() + int[] region = hidden.getListOfCols() .get(c); HiddenColumns hc = new HiddenColumns(); hc.setStart(region[0]); diff --git a/src/jalview/gui/OverviewPanel.java b/src/jalview/gui/OverviewPanel.java index c530fdc..e42d25f 100755 --- a/src/jalview/gui/OverviewPanel.java +++ b/src/jalview/gui/OverviewPanel.java @@ -115,8 +115,8 @@ public class OverviewPanel extends JPanel implements Runnable if (!av.getWrapAlignment()) { od.updateViewportFromMouse(evt.getX(), evt.getY(), av - .getAlignment().getHiddenSequences(), av - .getColumnSelection(), av.getRanges()); + .getAlignment().getHiddenSequences(), av.getAlignment() + .getHiddenColumns(), av.getRanges()); ap.setScrollValues(od.getScrollCol(), od.getScrollRow()); } } @@ -130,8 +130,8 @@ public class OverviewPanel extends JPanel implements Runnable if (!av.getWrapAlignment()) { od.updateViewportFromMouse(evt.getX(), evt.getY(), av - .getAlignment().getHiddenSequences(), av - .getColumnSelection(), av.getRanges()); + .getAlignment().getHiddenSequences(), av.getAlignment() + .getHiddenColumns(), av.getRanges()); ap.setScrollValues(od.getScrollCol(), od.getScrollRow()); } } @@ -305,7 +305,7 @@ public class OverviewPanel extends JPanel implements Runnable } if (hiddenRow - || (hasHiddenCols && !av.getColumnSelection() + || (hasHiddenCols && !av.getAlignment().getHiddenColumns() .isVisible(lastcol))) { color = color.darker().darker(); @@ -322,7 +322,8 @@ public class OverviewPanel extends JPanel implements Runnable public void setBoxPosition() { od.setBoxPosition(av.getAlignment() - .getHiddenSequences(), av.getColumnSelection(), av.getRanges()); +.getHiddenSequences(), av + .getAlignment().getHiddenColumns(), av.getRanges()); repaint(); } diff --git a/src/jalview/gui/PCAPanel.java b/src/jalview/gui/PCAPanel.java index 58ed008..1f68124 100644 --- a/src/jalview/gui/PCAPanel.java +++ b/src/jalview/gui/PCAPanel.java @@ -23,7 +23,7 @@ package jalview.gui; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentI; import jalview.datamodel.AlignmentView; -import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.SeqCigar; import jalview.datamodel.SequenceI; import jalview.jbgui.GPCAPanel; @@ -399,7 +399,7 @@ public class PCAPanel extends GPCAPanel implements Runnable, } ; Object[] alAndColsel = pcaModel.getSeqtrings() - .getAlignmentAndColumnSelection(gc); + .getAlignmentAndHiddenColumns(gc); if (alAndColsel != null && alAndColsel[0] != null) { @@ -416,8 +416,8 @@ public class PCAPanel extends GPCAPanel implements Runnable, if (true) { // make a new frame! - AlignFrame af = new AlignFrame(al, - (ColumnSelection) alAndColsel[1], AlignFrame.DEFAULT_WIDTH, + AlignFrame af = new AlignFrame(al, (HiddenColumns) alAndColsel[1], + AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT); // >>>This is a fix for the moment, until a better solution is diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java index 660c651..38f409f 100644 --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -31,8 +31,8 @@ import jalview.commands.EditCommand.Action; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; import jalview.datamodel.Annotation; -import jalview.datamodel.ColumnSelection; import jalview.datamodel.DBRefEntry; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.PDBEntry; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceFeature; @@ -1445,13 +1445,21 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener { if (sequence != null) { - ColumnSelection cs = ap.av.getColumnSelection(); - if (cs == null) + /* ColumnSelection cs = ap.av.getColumnSelection(); + if (cs == null) + { + cs = new ColumnSelection(); + } + cs.hideInsertionsFor(sequence); + ap.av.setColumnSelection(cs);*/ + + HiddenColumns hidden = ap.av.getAlignment().getHiddenColumns(); + if (hidden == null) { - cs = new ColumnSelection(); + hidden = new HiddenColumns(); } - cs.hideInsertionsFor(sequence); - ap.av.setColumnSelection(cs); + hidden.hideInsertionsFor(sequence); + ap.av.getAlignment().setHiddenColumns(hidden); } refresh(); } diff --git a/src/jalview/gui/ScalePanel.java b/src/jalview/gui/ScalePanel.java index de21be6..bc59f91 100755 --- a/src/jalview/gui/ScalePanel.java +++ b/src/jalview/gui/ScalePanel.java @@ -21,6 +21,7 @@ package jalview.gui; import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.renderer.ScaleRenderer; @@ -106,7 +107,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener, if (av.hasHiddenColumns()) { - x = av.getColumnSelection().adjustForHiddenColumns(x); + x = av.getAlignment().getHiddenColumns().adjustForHiddenColumns(x); } if (x >= av.getAlignment().getWidth()) @@ -172,7 +173,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener, }); pop.add(item); - if (av.getColumnSelection().hasHiddenColumns()) + if (av.getAlignment().getHiddenColumns().hasHiddenColumns()) { item = new JMenuItem(MessageManager.getString("action.reveal_all")); item.addActionListener(new ActionListener() @@ -287,7 +288,8 @@ public class ScalePanel extends JPanel implements MouseMotionListener, if (av.hasHiddenColumns()) { - res = av.getColumnSelection().adjustForHiddenColumns(res); + res = av.getAlignment().getHiddenColumns() + .adjustForHiddenColumns(res); } if (res >= av.getAlignment().getWidth()) @@ -337,11 +339,12 @@ public class ScalePanel extends JPanel implements MouseMotionListener, { mouseDragging = true; ColumnSelection cs = av.getColumnSelection(); + HiddenColumns hidden = av.getAlignment().getHiddenColumns(); int res = (evt.getX() / av.getCharWidth()) + av.getRanges().getStartRes(); res = Math.max(0, res); - res = cs.adjustForHiddenColumns(res); + res = hidden.adjustForHiddenColumns(res); res = Math.min(res, av.getAlignment().getWidth() - 1); min = Math.min(res, min); max = Math.max(res, max); @@ -394,11 +397,12 @@ public class ScalePanel extends JPanel implements MouseMotionListener, int res = (evt.getX() / av.getCharWidth()) + av.getRanges().getStartRes(); - res = av.getColumnSelection().adjustForHiddenColumns(res); + res = av.getAlignment().getHiddenColumns().adjustForHiddenColumns(res); - if (av.getColumnSelection().getHiddenColumns() != null) + if (av.getAlignment().getHiddenColumns().getListOfCols() != null) { - for (int[] region : av.getColumnSelection().getHiddenColumns()) + for (int[] region : av.getAlignment().getHiddenColumns() + .getListOfCols()) { if (res + 1 == region[0] || res - 1 == region[1]) { @@ -446,7 +450,9 @@ public class ScalePanel extends JPanel implements MouseMotionListener, // Fill the selected columns ColumnSelection cs = av.getColumnSelection(); - int avCharWidth = av.getCharWidth(), avCharHeight = av.getCharHeight(); + HiddenColumns hidden = av.getAlignment().getHiddenColumns(); + int avCharWidth = av.getCharWidth(); + int avCharHeight = av.getCharHeight(); if (cs != null) { @@ -459,9 +465,9 @@ public class ScalePanel extends JPanel implements MouseMotionListener, if (av.hasHiddenColumns()) { - if (cs.isVisible(sel)) + if (hidden.isVisible(sel)) { - sel = cs.findColumnPosition(sel); + sel = hidden.findColumnPosition(sel); } else { @@ -488,13 +494,13 @@ public class ScalePanel extends JPanel implements MouseMotionListener, // draw any hidden column markers gg.setColor(Color.blue); int res; - if (av.getShowHiddenMarkers() - && av.getColumnSelection().getHiddenColumns() != null) + + if (av.getShowHiddenMarkers() && hidden.getListOfCols() != null) { - for (int i = 0; i < av.getColumnSelection().getHiddenColumns() + for (int i = 0; i < hidden.getListOfCols() .size(); i++) { - res = av.getColumnSelection().findHiddenRegionPosition(i) + res = hidden.findHiddenRegionPosition(i) - startx; if (res < 0 || res > widthx) diff --git a/src/jalview/gui/SeqCanvas.java b/src/jalview/gui/SeqCanvas.java index 4557819..0a1a99a 100755 --- a/src/jalview/gui/SeqCanvas.java +++ b/src/jalview/gui/SeqCanvas.java @@ -21,6 +21,7 @@ package jalview.gui; import jalview.datamodel.AlignmentI; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.SearchResultsI; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; @@ -165,14 +166,17 @@ public class SeqCanvas extends JComponent if (av.hasHiddenColumns()) { - startx = av.getColumnSelection().adjustForHiddenColumns(startx); - endx = av.getColumnSelection().adjustForHiddenColumns(endx); + startx = av.getAlignment().getHiddenColumns() + .adjustForHiddenColumns(startx); + endx = av.getAlignment().getHiddenColumns() + .adjustForHiddenColumns(endx); } int maxwidth = av.getAlignment().getWidth(); if (av.hasHiddenColumns()) { - maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1; + maxwidth = av.getAlignment().getHiddenColumns() + .findColumnPosition(maxwidth) - 1; } // WEST SCALE @@ -224,7 +228,8 @@ public class SeqCanvas extends JComponent if (av.hasHiddenColumns()) { - endx = av.getColumnSelection().adjustForHiddenColumns(endx); + endx = av.getAlignment().getHiddenColumns() + .adjustForHiddenColumns(endx); } SequenceI seq; @@ -515,7 +520,8 @@ public class SeqCanvas extends JComponent if (av.hasHiddenColumns()) { - maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1; + maxwidth = av.getAlignment().getHiddenColumns() + .findColumnPosition(maxwidth) - 1; } while ((ypos <= canvasHeight) && (startRes < maxwidth)) @@ -553,11 +559,10 @@ public class SeqCanvas extends JComponent { g.setColor(Color.blue); int res; - for (int i = 0; i < av.getColumnSelection().getHiddenColumns() - .size(); i++) + HiddenColumns hidden = av.getAlignment().getHiddenColumns(); + for (int i = 0; i < hidden.getListOfCols().size(); i++) { - res = av.getColumnSelection().findHiddenRegionPosition(i) - - startRes; + res = hidden.findHiddenRegionPosition(i) - startRes; if (res < 0 || res > endx - startRes) { @@ -654,7 +659,8 @@ public class SeqCanvas extends JComponent } else { - List regions = av.getColumnSelection().getHiddenColumns(); + List regions = av.getAlignment().getHiddenColumns() + .getListOfCols(); int screenY = 0; int blockStart = startRes; diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index db7aa36..282e826 100644 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -27,6 +27,7 @@ import jalview.commands.EditCommand.Action; import jalview.commands.EditCommand.Edit; import jalview.datamodel.AlignmentI; import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.SearchResultMatchI; import jalview.datamodel.SearchResults; import jalview.datamodel.SearchResultsI; @@ -232,7 +233,8 @@ public class SeqPanel extends JPanel implements MouseListener, if (av.hasHiddenColumns()) { - res = av.getColumnSelection().adjustForHiddenColumns(res); + res = av.getAlignment().getHiddenColumns() + .adjustForHiddenColumns(res); } return res; @@ -338,20 +340,23 @@ public class SeqPanel extends JPanel implements MouseListener, { seqCanvas.cursorX += dx; seqCanvas.cursorY += dy; + + HiddenColumns hidden = av.getAlignment().getHiddenColumns(); + if (av.hasHiddenColumns() - && !av.getColumnSelection().isVisible(seqCanvas.cursorX)) + && !hidden.isVisible(seqCanvas.cursorX)) { int original = seqCanvas.cursorX - dx; int maxWidth = av.getAlignment().getWidth(); - while (!av.getColumnSelection().isVisible(seqCanvas.cursorX) + while (!hidden.isVisible(seqCanvas.cursorX) && seqCanvas.cursorX < maxWidth && seqCanvas.cursorX > 0) { seqCanvas.cursorX += dx; } if (seqCanvas.cursorX >= maxWidth - || !av.getColumnSelection().isVisible(seqCanvas.cursorX)) + || !hidden.isVisible(seqCanvas.cursorX)) { seqCanvas.cursorX = original; } @@ -397,16 +402,17 @@ public class SeqPanel extends JPanel implements MouseListener, } if (!av.getWrapAlignment()) { - while (seqCanvas.cursorX < av.getColumnSelection() - .adjustForHiddenColumns(av.getRanges().getStartRes())) + HiddenColumns hidden = av.getAlignment().getHiddenColumns(); + while (seqCanvas.cursorX < hidden.adjustForHiddenColumns(av + .getRanges().getStartRes())) { if (!ap.scrollRight(false)) { break; } } - while (seqCanvas.cursorX > av.getColumnSelection() - .adjustForHiddenColumns(av.getRanges().getEndRes())) + while (seqCanvas.cursorX > hidden.adjustForHiddenColumns(av + .getRanges().getEndRes())) { if (!ap.scrollRight(true)) { @@ -1143,8 +1149,10 @@ public class SeqPanel extends JPanel implements MouseListener, if (av.hasHiddenColumns()) { fixedColumns = true; - int y1 = av.getColumnSelection().getHiddenBoundaryLeft(startres); - int y2 = av.getColumnSelection().getHiddenBoundaryRight(startres); + int y1 = av.getAlignment().getHiddenColumns() + .getHiddenBoundaryLeft(startres); + int y2 = av.getAlignment().getHiddenColumns() + .getHiddenBoundaryRight(startres); if ((insertGap && startres > y1 && lastres < y1) || (!insertGap && startres < y2 && lastres > y2)) @@ -1219,8 +1227,8 @@ public class SeqPanel extends JPanel implements MouseListener, { if (sg.getSize() == av.getAlignment().getHeight()) { - if ((av.hasHiddenColumns() && startres < av - .getColumnSelection().getHiddenBoundaryRight(startres))) + if ((av.hasHiddenColumns() && startres < av.getAlignment() + .getHiddenColumns().getHiddenBoundaryRight(startres))) { endEditing(); return; @@ -1948,6 +1956,7 @@ public class SeqPanel extends JPanel implements MouseListener, */ @Override public void selection(SequenceGroup seqsel, ColumnSelection colsel, + HiddenColumns hidden, SelectionSource source) { // TODO: fix this hack - source of messages is align viewport, but SeqPanel @@ -2045,8 +2054,8 @@ public class SeqPanel extends JPanel implements MouseListener, if (copycolsel && av.hasHiddenColumns() - && (av.getColumnSelection() == null || av.getColumnSelection() - .getHiddenColumns() == null)) + && (av.getAlignment().getHiddenColumns() == null || av + .getAlignment().getHiddenColumns().getListOfCols() == null)) { System.err.println("Bad things"); } diff --git a/src/jalview/gui/StructureViewerBase.java b/src/jalview/gui/StructureViewerBase.java index d7f7c31..e37627d 100644 --- a/src/jalview/gui/StructureViewerBase.java +++ b/src/jalview/gui/StructureViewerBase.java @@ -23,7 +23,7 @@ package jalview.gui; import jalview.bin.Cache; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentI; -import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceI; import jalview.gui.StructureViewer.ViewerType; @@ -812,7 +812,7 @@ public abstract class StructureViewerBase extends GStructureViewer try { AlignmentI[] als = new Alignment[_alignwith.size()]; - ColumnSelection[] alc = new ColumnSelection[_alignwith.size()]; + HiddenColumns[] alc = new HiddenColumns[_alignwith.size()]; int[] alm = new int[_alignwith.size()]; int a = 0; @@ -820,7 +820,7 @@ public abstract class StructureViewerBase extends GStructureViewer { als[a] = ap.av.getAlignment(); alm[a] = -1; - alc[a++] = ap.av.getColumnSelection(); + alc[a++] = ap.av.getAlignment().getHiddenColumns(); } reply = getBinding().superposeStructures(als, alm, alc); if (reply != null) diff --git a/src/jalview/gui/TreePanel.java b/src/jalview/gui/TreePanel.java index 25f4c1b..96d0746 100755 --- a/src/jalview/gui/TreePanel.java +++ b/src/jalview/gui/TreePanel.java @@ -31,8 +31,8 @@ import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentI; import jalview.datamodel.AlignmentView; import jalview.datamodel.BinaryNode; -import jalview.datamodel.ColumnSelection; import jalview.datamodel.DBRefEntry; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.NodeTransformI; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceI; @@ -515,7 +515,7 @@ public class TreePanel extends GTreePanel { } ; - Object[] alAndColsel = tree.seqData.getAlignmentAndColumnSelection(gc); + Object[] alAndColsel = tree.seqData.getAlignmentAndHiddenColumns(gc); if (alAndColsel != null && alAndColsel[0] != null) { @@ -532,8 +532,8 @@ public class TreePanel extends GTreePanel if (true) { // make a new frame! - AlignFrame af = new AlignFrame(al, - (ColumnSelection) alAndColsel[1], AlignFrame.DEFAULT_WIDTH, + AlignFrame af = new AlignFrame(al, (HiddenColumns) alAndColsel[1], + AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT); // >>>This is a fix for the moment, until a better solution is diff --git a/src/jalview/gui/VamsasApplication.java b/src/jalview/gui/VamsasApplication.java index 75ddba5..d58cb5a 100644 --- a/src/jalview/gui/VamsasApplication.java +++ b/src/jalview/gui/VamsasApplication.java @@ -23,6 +23,7 @@ package jalview.gui; import jalview.bin.Cache; import jalview.datamodel.AlignmentI; import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.io.VamsasAppDatastore; @@ -43,7 +44,6 @@ import java.util.IdentityHashMap; import java.util.Iterator; import javax.swing.JInternalFrame; -import javax.swing.JOptionPane; import uk.ac.vamsas.client.ClientHandle; import uk.ac.vamsas.client.IClient; @@ -821,7 +821,7 @@ public class VamsasApplication implements SelectionSource, VamsasSource { // TODO: rationalise : can only clear a selection over a // referred to object - ssm.sendSelection(null, null, me); + ssm.sendSelection(null, null, null, me); return; } Class type = null; @@ -955,7 +955,7 @@ public class VamsasApplication implements SelectionSource, VamsasSource } if (send) { - ssm.sendSelection(jselection, colsel, me); + ssm.sendSelection(jselection, colsel, null, me); } // discard message. for (int c = 0; c < jvobjs.length; c++) @@ -1004,7 +1004,8 @@ public class VamsasApplication implements SelectionSource, VamsasSource @Override public void selection(SequenceGroup seqsel, - ColumnSelection colsel, SelectionSource source) + ColumnSelection colsel, HiddenColumns hidden, + SelectionSource source) { if (vobj2jv == null) { @@ -1079,7 +1080,9 @@ public class VamsasApplication implements SelectionSource, VamsasSource } else { - int[] intervals = colsel.getVisibleContigs( + // int[] intervals = colsel.getVisibleContigs( + // seqsel.getStartRes(), seqsel.getEndRes() + 1); + int[] intervals = hidden.getVisibleContigs( seqsel.getStartRes(), seqsel.getEndRes() + 1); for (int iv = 0; iv < intervals.length; iv += 2) { diff --git a/src/jalview/io/AnnotationFile.java b/src/jalview/io/AnnotationFile.java index 9a4071d..31aeffa 100755 --- a/src/jalview/io/AnnotationFile.java +++ b/src/jalview/io/AnnotationFile.java @@ -27,6 +27,7 @@ import jalview.datamodel.AlignmentI; import jalview.datamodel.Annotation; import jalview.datamodel.ColumnSelection; import jalview.datamodel.GraphLine; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.HiddenSequences; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; @@ -113,14 +114,14 @@ public class AnnotationFile public HiddenSequences hidseqs; - public ColumnSelection hiddencols; + public HiddenColumns hiddencols; public Vector visibleGroups; public Hashtable hiddenRepSeqs; public ViewDef(String viewname, HiddenSequences hidseqs, - ColumnSelection hiddencols, Hashtable hiddenRepSeqs) + HiddenColumns hiddencols, Hashtable hiddenRepSeqs) { this.viewname = viewname; this.hidseqs = hidseqs; @@ -141,7 +142,8 @@ public class AnnotationFile */ public String printAnnotations(AlignmentAnnotation[] annotations, List list, Hashtable properties, - ColumnSelection cs, AlignmentI al, ViewDef view) + HiddenColumns cs, + AlignmentI al, ViewDef view) { if (view != null) { @@ -170,7 +172,7 @@ public class AnnotationFile if (cs != null && cs.hasHiddenColumns()) { text.append("VIEW_HIDECOLS\t"); - List hc = cs.getHiddenColumns(); + List hc = cs.getListOfCols(); boolean comma = false; for (int[] r : hc) { @@ -664,15 +666,21 @@ public class AnnotationFile String file, DataSourceType protocol) { ColumnSelection colSel = viewport.getColumnSelection(); + HiddenColumns hidden = viewport.getAlignment().getHiddenColumns(); if (colSel == null) { colSel = new ColumnSelection(); } - boolean rslt = readAnnotationFile(viewport.getAlignment(), colSel, + if (hidden == null) + { + hidden = new HiddenColumns(); + } + boolean rslt = readAnnotationFile(viewport.getAlignment(), hidden, file, protocol); - if (rslt && (colSel.hasSelectedColumns() || colSel.hasHiddenColumns())) + if (rslt && (colSel.hasSelectedColumns() || hidden.hasHiddenColumns())) { viewport.setColumnSelection(colSel); + viewport.getAlignment().setHiddenColumns(hidden); } return rslt; @@ -684,7 +692,7 @@ public class AnnotationFile return readAnnotationFile(al, null, file, sourceType); } - public boolean readAnnotationFile(AlignmentI al, ColumnSelection colSel, + public boolean readAnnotationFile(AlignmentI al, HiddenColumns hidden, String file, DataSourceType sourceType) { BufferedReader in = null; @@ -713,7 +721,7 @@ public class AnnotationFile } if (in != null) { - return parseAnnotationFrom(al, colSel, in); + return parseAnnotationFrom(al, hidden, in); } } catch (Exception ex) @@ -736,7 +744,7 @@ public class AnnotationFile private static String GRAPHLINE = "GRAPHLINE", COMBINE = "COMBINE"; - public boolean parseAnnotationFrom(AlignmentI al, ColumnSelection colSel, + public boolean parseAnnotationFrom(AlignmentI al, HiddenColumns hidden, BufferedReader in) throws Exception { nlinesread = 0; @@ -947,11 +955,11 @@ public class AnnotationFile { if (st.hasMoreTokens()) { - if (colSel == null) + if (hidden == null) { - colSel = new ColumnSelection(); + hidden = new HiddenColumns(); } - parseHideCols(colSel, st.nextToken()); + parseHideCols(hidden, st.nextToken()); } modified = true; continue; @@ -965,7 +973,7 @@ public class AnnotationFile } if (sr != null) { - if (colSel == null) + if (hidden == null) { System.err .println("Cannot process HIDE_INSERTIONS without an alignment view: Ignoring line: " @@ -974,7 +982,7 @@ public class AnnotationFile else { // consider deferring this till after the file has been parsed ? - colSel.hideInsertionsFor(sr); + hidden.hideInsertionsFor(sr); } } modified = true; @@ -1180,7 +1188,7 @@ public class AnnotationFile return modified; } - private void parseHideCols(ColumnSelection colSel, String nextToken) + private void parseHideCols(HiddenColumns hidden, String nextToken) { StringTokenizer inval = new StringTokenizer(nextToken, ","); while (inval.hasMoreTokens()) @@ -1192,7 +1200,7 @@ public class AnnotationFile from = to = Integer.parseInt(range); if (from >= 0) { - colSel.hideColumns(from, to); + hidden.hideColumns(from, to); } } else @@ -1208,7 +1216,7 @@ public class AnnotationFile } if (from > 0 && to >= from) { - colSel.hideColumns(from, to); + hidden.hideColumns(from, to); } } } @@ -1787,7 +1795,7 @@ public class AnnotationFile return printAnnotations(viewport.isShowAnnotation() ? viewport .getAlignment().getAlignmentAnnotation() : null, viewport .getAlignment().getGroups(), viewport.getAlignment() - .getProperties(), viewport.getColumnSelection(), + .getProperties(), viewport.getAlignment().getHiddenColumns(), viewport.getAlignment(), null); } diff --git a/src/jalview/io/FileLoader.java b/src/jalview/io/FileLoader.java index 4f83ab1..7c6d181 100755 --- a/src/jalview/io/FileLoader.java +++ b/src/jalview/io/FileLoader.java @@ -27,7 +27,7 @@ import jalview.api.FeaturesSourceI; import jalview.bin.Cache; import jalview.bin.Jalview; import jalview.datamodel.AlignmentI; -import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceI; import jalview.gui.AlignFrame; @@ -372,8 +372,8 @@ public class FileLoader implements Runnable if (source instanceof ComplexAlignFile) { - ColumnSelection colSel = ((ComplexAlignFile) source) - .getColumnSelection(); + HiddenColumns colSel = ((ComplexAlignFile) source) + .getHiddenColumns(); SequenceI[] hiddenSeqs = ((ComplexAlignFile) source) .getHiddenSequences(); String colourSchemeName = ((ComplexAlignFile) source) diff --git a/src/jalview/io/FormatAdapter.java b/src/jalview/io/FormatAdapter.java index d9dd79d..f09e8a0 100755 --- a/src/jalview/io/FormatAdapter.java +++ b/src/jalview/io/FormatAdapter.java @@ -26,7 +26,7 @@ import jalview.bin.Cache; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; -import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; @@ -165,14 +165,14 @@ public class FormatAdapter extends AppletFormatAdapter } public String formatSequences(FileFormatI format, AlignmentI alignment, - String[] omitHidden, int[] exportRange, ColumnSelection colSel) + String[] omitHidden, int[] exportRange, HiddenColumns hidden) { return formatSequences(format, alignment, omitHidden, exportRange, - getCacheSuffixDefault(format), colSel, null); + getCacheSuffixDefault(format), hidden, null); } /** - * hack function to replace seuqences with visible sequence strings before + * hack function to replace sequences with visible sequence strings before * generating a string of the alignment in the given format. * * @param format @@ -185,15 +185,15 @@ public class FormatAdapter extends AppletFormatAdapter */ public String formatSequences(FileFormatI format, AlignmentI alignment, String[] omitHidden, int[] exportRange, boolean suffix, - ColumnSelection colSel) + HiddenColumns hidden) { return formatSequences(format, alignment, omitHidden, exportRange, - suffix, colSel, null); + suffix, hidden, null); } public String formatSequences(FileFormatI format, AlignmentI alignment, String[] omitHidden, int[] exportRange, boolean suffix, - ColumnSelection colSel, SequenceGroup selgp) + HiddenColumns hidden, SequenceGroup selgp) { if (omitHidden != null) { @@ -211,12 +211,12 @@ public class FormatAdapter extends AppletFormatAdapter AlignmentAnnotation na = new AlignmentAnnotation(ala[i]); if (selgp != null) { - colSel.makeVisibleAnnotation(selgp.getStartRes(), + hidden.makeVisibleAnnotation(selgp.getStartRes(), selgp.getEndRes(), na); } else { - colSel.makeVisibleAnnotation(na); + hidden.makeVisibleAnnotation(na); } alv.addAnnotation(na); } diff --git a/src/jalview/io/HTMLOutput.java b/src/jalview/io/HTMLOutput.java index 68f3e2c..77006db 100755 --- a/src/jalview/io/HTMLOutput.java +++ b/src/jalview/io/HTMLOutput.java @@ -91,8 +91,8 @@ public abstract class HTMLOutput implements Runnable String bioJSON = new FormatAdapter(ap, exportData.getSettings()) .formatSequences(FileFormat.Json, exportData.getAlignment(), exportData.getOmitHidden(), exportData - .getStartEndPostions(), ap.getAlignViewport() - .getColumnSelection()); +.getStartEndPostions(), ap.getAlignViewport() + .getAlignment().getHiddenColumns()); return bioJSON; } diff --git a/src/jalview/io/HtmlFile.java b/src/jalview/io/HtmlFile.java index af3fb5d..9256278 100644 --- a/src/jalview/io/HtmlFile.java +++ b/src/jalview/io/HtmlFile.java @@ -24,7 +24,7 @@ package jalview.io; import jalview.api.ComplexAlignFile; import jalview.api.FeatureSettingsModelI; import jalview.api.FeaturesDisplayedI; -import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.SequenceI; import java.io.IOException; @@ -44,7 +44,7 @@ public class HtmlFile extends AlignFile implements ComplexAlignFile private boolean showSeqFeatures; - private ColumnSelection columnSelection; + private HiddenColumns hiddenColumns; private SequenceI[] hiddenSequences; @@ -111,7 +111,7 @@ public class HtmlFile extends AlignFile implements ComplexAlignFile this.showSeqFeatures = jsonFile.isShowSeqFeatures(); this.globalColourScheme = jsonFile.getGlobalColourScheme(); this.hiddenSequences = jsonFile.getHiddenSequences(); - this.columnSelection = jsonFile.getColumnSelection(); + this.hiddenColumns = jsonFile.getHiddenColumns(); this.displayedFeatures = jsonFile.getDisplayedFeatures(); } catch (Exception e) { @@ -149,14 +149,14 @@ public class HtmlFile extends AlignFile implements ComplexAlignFile } @Override - public ColumnSelection getColumnSelection() + public HiddenColumns getHiddenColumns() { - return columnSelection; + return hiddenColumns; } - public void setColumnSelection(ColumnSelection columnSelection) + public void setHiddenColumns(HiddenColumns hidden) { - this.columnSelection = columnSelection; + this.hiddenColumns = hidden; } @Override diff --git a/src/jalview/io/JSONFile.java b/src/jalview/io/JSONFile.java index 053a65e..dcf0f5d 100644 --- a/src/jalview/io/JSONFile.java +++ b/src/jalview/io/JSONFile.java @@ -32,7 +32,7 @@ import jalview.bin.BuildDetails; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; import jalview.datamodel.Annotation; -import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.HiddenSequences; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceFeature; @@ -83,9 +83,9 @@ public class JSONFile extends AlignFile implements ComplexAlignFile private FeatureRenderer fr; - private List hiddenColumns; + private List hiddenColumnsList; - private ColumnSelection columnSelection; + private HiddenColumns hiddenColumns; private List hiddenSeqRefs; @@ -280,8 +280,9 @@ public class JSONFile extends AlignFile implements ComplexAlignFile // hidden column business if (getViewport().hasHiddenColumns()) { - List hiddenCols = getViewport().getColumnSelection() - .getHiddenColumns(); + List hiddenCols = getViewport().getAlignment() + .getHiddenColumns() + .getListOfCols(); StringBuilder hiddenColsBuilder = new StringBuilder(); for (int[] range : hiddenCols) { @@ -666,12 +667,12 @@ public class JSONFile extends AlignFile implements ComplexAlignFile String hiddenCols = (String) jvSettingsJson.get("hiddenCols"); if (hiddenCols != null && !hiddenCols.isEmpty()) { - columnSelection = new ColumnSelection(); + HiddenColumns hidden = new HiddenColumns(); String[] rangeStrings = hiddenCols.split(";"); for (String rangeString : rangeStrings) { String[] range = rangeString.split("-"); - columnSelection.hideColumns(Integer.valueOf(range[0]), + hidden.hideColumns(Integer.valueOf(range[0]), Integer.valueOf(range[1])); } } @@ -789,20 +790,15 @@ public class JSONFile extends AlignFile implements ComplexAlignFile return annotations; } - public List getHiddenColumns() - { - return hiddenColumns; - } - @Override - public ColumnSelection getColumnSelection() + public HiddenColumns getHiddenColumns() { - return columnSelection; + return hiddenColumns; } - public void setColumnSelection(ColumnSelection columnSelection) + public void setHiddenColumns(HiddenColumns hidden) { - this.columnSelection = columnSelection; + this.hiddenColumns = hidden; } @Override diff --git a/src/jalview/javascript/JsSelectionSender.java b/src/jalview/javascript/JsSelectionSender.java index dc08b59..fdf8b58 100644 --- a/src/jalview/javascript/JsSelectionSender.java +++ b/src/jalview/javascript/JsSelectionSender.java @@ -23,6 +23,7 @@ package jalview.javascript; import jalview.appletgui.AlignFrame; import jalview.bin.JalviewLite; import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.SequenceGroup; import jalview.structure.SelectionSource; @@ -44,7 +45,7 @@ public class JsSelectionSender extends JSFunctionExec implements @Override public void selection(SequenceGroup seqsel, ColumnSelection colsel, - SelectionSource source) + HiddenColumns hidden, SelectionSource source) { // System.err.println("Testing selection event relay to jsfunction:"+_listener); try diff --git a/src/jalview/renderer/AnnotationRenderer.java b/src/jalview/renderer/AnnotationRenderer.java index 3a27c7d..518c179 100644 --- a/src/jalview/renderer/AnnotationRenderer.java +++ b/src/jalview/renderer/AnnotationRenderer.java @@ -28,6 +28,7 @@ import jalview.api.AlignViewportI; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.Annotation; import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.ProfilesI; import jalview.schemes.ColourSchemeI; import jalview.schemes.NucleotideColourScheme; @@ -75,6 +76,8 @@ public class AnnotationRenderer ResidueShaderI profcolour = null; private ColumnSelection columnSelection; + + private HiddenColumns hiddenColumns; private ProfilesI hconsensus; @@ -327,6 +330,7 @@ public class AnnotationRenderer profcolour = new ResidueShader(col); } columnSelection = av.getColumnSelection(); + hiddenColumns = av.getAlignment().getHiddenColumns(); hconsensus = av.getSequenceConsensusHash(); complementConsensus = av.getComplementConsensusHash(); hStrucConsensus = av.getRnaStructureConsensusHash(); @@ -589,7 +593,7 @@ hconsensus.get(column), { if (hasHiddenColumns) { - column = columnSelection.adjustForHiddenColumns(startRes + x); + column = hiddenColumns.adjustForHiddenColumns(startRes + x); if (column > row_annotations.length - 1) { break; @@ -1231,7 +1235,7 @@ hconsensus.get(column), column = sRes + x; if (hasHiddenColumns) { - column = columnSelection.adjustForHiddenColumns(column); + column = hiddenColumns.adjustForHiddenColumns(column); } if (column > aaMax) @@ -1310,7 +1314,7 @@ hconsensus.get(column), column = sRes + x; if (hasHiddenColumns) { - column = columnSelection.adjustForHiddenColumns(column); + column = hiddenColumns.adjustForHiddenColumns(column); } if (column > aaMax) diff --git a/src/jalview/renderer/ScaleRenderer.java b/src/jalview/renderer/ScaleRenderer.java index 82536d4..9fec256 100644 --- a/src/jalview/renderer/ScaleRenderer.java +++ b/src/jalview/renderer/ScaleRenderer.java @@ -73,7 +73,7 @@ public class ScaleRenderer { // find bounds and set origin appopriately // locate first visible position for this sequence - int[] refbounds = av.getColumnSelection() + int[] refbounds = av.getAlignment().getHiddenColumns() .locateVisibleBoundsOfSequence(refSeq); refSp = refbounds[0]; @@ -96,12 +96,14 @@ public class ScaleRenderer { if (refSeq == null) { - iadj = av.getColumnSelection().adjustForHiddenColumns(i - 1) + 1; + iadj = av.getAlignment().getHiddenColumns() + .adjustForHiddenColumns(i - 1) + 1; string = String.valueOf(iadj); } else { - iadj = av.getColumnSelection().adjustForHiddenColumns(i - 1); + iadj = av.getAlignment().getHiddenColumns() + .adjustForHiddenColumns(i - 1); refN = refSeq.findPosition(iadj); // TODO show bounds if position is a gap // - ie L--R -> "1L|2R" for diff --git a/src/jalview/structure/SelectionListener.java b/src/jalview/structure/SelectionListener.java index 2877d46..fe878ce 100644 --- a/src/jalview/structure/SelectionListener.java +++ b/src/jalview/structure/SelectionListener.java @@ -38,5 +38,7 @@ public interface SelectionListener * - source of the selection event */ public void selection(jalview.datamodel.SequenceGroup seqsel, - jalview.datamodel.ColumnSelection colsel, SelectionSource source); + jalview.datamodel.ColumnSelection colsel, + jalview.datamodel.HiddenColumns hidden, + SelectionSource source); } diff --git a/src/jalview/structure/StructureSelectionManager.java b/src/jalview/structure/StructureSelectionManager.java index 3ab642f..0acb786 100644 --- a/src/jalview/structure/StructureSelectionManager.java +++ b/src/jalview/structure/StructureSelectionManager.java @@ -29,6 +29,7 @@ import jalview.datamodel.AlignedCodonFrame; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; import jalview.datamodel.Annotation; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.PDBEntry; import jalview.datamodel.SearchResults; import jalview.datamodel.SearchResultsI; @@ -1201,13 +1202,14 @@ public class StructureSelectionManager public synchronized void sendSelection( jalview.datamodel.SequenceGroup selection, - jalview.datamodel.ColumnSelection colsel, SelectionSource source) + jalview.datamodel.ColumnSelection colsel, HiddenColumns hidden, + SelectionSource source) { for (SelectionListener slis : sel_listeners) { if (slis != source) { - slis.selection(selection, colsel, source); + slis.selection(selection, colsel, hidden, source); } } } diff --git a/src/jalview/structures/models/AAStructureBindingModel.java b/src/jalview/structures/models/AAStructureBindingModel.java index 84475fe..b336e45 100644 --- a/src/jalview/structures/models/AAStructureBindingModel.java +++ b/src/jalview/structures/models/AAStructureBindingModel.java @@ -25,7 +25,7 @@ import jalview.api.SequenceRenderer; import jalview.api.StructureSelectionManagerProvider; import jalview.api.structures.JalviewStructureDisplayI; import jalview.datamodel.AlignmentI; -import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceI; import jalview.io.DataSourceType; @@ -716,8 +716,8 @@ public abstract class AAStructureBindingModel extends * an array of corresponding hidden columns for each alignment * @return */ - public abstract String superposeStructures(AlignmentI[] alignments, int[] structureIndices, - ColumnSelection[] hiddenCols); + public abstract String superposeStructures(AlignmentI[] alignments, + int[] structureIndices, HiddenColumns[] hiddenCols); public abstract void setBackgroundColour(Color col); diff --git a/src/jalview/util/MappingUtils.java b/src/jalview/util/MappingUtils.java index 2e30132..44a55ec 100644 --- a/src/jalview/util/MappingUtils.java +++ b/src/jalview/util/MappingUtils.java @@ -31,6 +31,7 @@ import jalview.datamodel.AlignedCodonFrame; import jalview.datamodel.AlignmentI; import jalview.datamodel.AlignmentOrder; import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.SearchResultMatchI; import jalview.datamodel.SearchResults; import jalview.datamodel.SearchResultsI; @@ -537,7 +538,7 @@ public final class MappingUtils toSequences, fromGapChar); } - for (int[] hidden : colsel.getHiddenColumns()) + for (int[] hidden : colsel.getListOfCols()) { mapHiddenColumns(hidden, codonFrames, mappedColumns, fromSequences, toSequences, fromGapChar); @@ -557,7 +558,7 @@ public final class MappingUtils * @param fromGapChar */ protected static void mapHiddenColumns(int[] hidden, - List mappings, ColumnSelection mappedColumns, + List mappings, HiddenColumns mappedColumns, List fromSequences, List toSequences, char fromGapChar) { diff --git a/src/jalview/viewmodel/AlignmentViewport.java b/src/jalview/viewmodel/AlignmentViewport.java index 47dceec..a70e382 100644 --- a/src/jalview/viewmodel/AlignmentViewport.java +++ b/src/jalview/viewmodel/AlignmentViewport.java @@ -20,17 +20,6 @@ */ package jalview.viewmodel; -import java.awt.Color; -import java.beans.PropertyChangeSupport; -import java.util.ArrayDeque; -import java.util.ArrayList; -import java.util.BitSet; -import java.util.Deque; -import java.util.HashMap; -import java.util.Hashtable; -import java.util.List; -import java.util.Map; - import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder; import jalview.analysis.Conservation; import jalview.api.AlignCalcManagerI; @@ -46,6 +35,7 @@ import jalview.datamodel.AlignmentView; import jalview.datamodel.Annotation; import jalview.datamodel.CigarArray; import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.HiddenSequences; import jalview.datamodel.ProfilesI; import jalview.datamodel.SearchResultsI; @@ -68,6 +58,17 @@ import jalview.workers.ComplementConsensusThread; import jalview.workers.ConsensusThread; import jalview.workers.StrucConsensusThread; +import java.awt.Color; +import java.beans.PropertyChangeSupport; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.BitSet; +import java.util.Deque; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.List; +import java.util.Map; + /** * base class holding visualization and analysis attributes and common logic for * an active alignment view displayed in the GUI @@ -1100,9 +1101,10 @@ public abstract class AlignmentViewport implements AlignViewportI, } } - public void setHiddenColumns(ColumnSelection colsel) + public void setHiddenColumns(HiddenColumns hidden) { - this.colSel = colsel; + this.alignment.setHiddenColumns(hidden); + // this.colSel = colsel; } @Override @@ -1149,7 +1151,8 @@ public abstract class AlignmentViewport implements AlignViewportI, @Override public boolean hasHiddenColumns() { - return colSel != null && colSel.hasHiddenColumns(); + return colSel != null + && alignment.getHiddenColumns().hasHiddenColumns(); } public void updateHiddenColumns() @@ -1344,7 +1347,7 @@ public abstract class AlignmentViewport implements AlignViewportI, return; } - colSel.hideSelectedColumns(); + colSel.hideSelectedColumns(alignment); setSelectionGroup(null); isColSelChanged(true); } @@ -1353,24 +1356,24 @@ public abstract class AlignmentViewport implements AlignViewportI, { if (start == end) { - colSel.hideColumns(start); + colSel.hideSelectedColumns(start, alignment); } else { - colSel.hideColumns(start, end); + alignment.getHiddenColumns().hideColumns(start, end); } isColSelChanged(true); } public void showColumn(int col) { - colSel.revealHiddenColumns(col); + alignment.getHiddenColumns().revealHiddenColumns(col, colSel); isColSelChanged(true); } public void showAllHiddenColumns() { - colSel.revealAllHiddenColumns(); + alignment.getHiddenColumns().revealAllHiddenColumns(colSel); isColSelChanged(true); } @@ -1592,7 +1595,7 @@ public abstract class AlignmentViewport implements AlignViewportI, @Override public void invertColumnSelection() { - colSel.invertColumnSelection(0, alignment.getWidth()); + colSel.invertColumnSelection(0, alignment.getWidth(), alignment); } @Override @@ -1640,7 +1643,7 @@ public abstract class AlignmentViewport implements AlignViewportI, @Override public CigarArray getViewAsCigars(boolean selectedRegionOnly) { - return new CigarArray(alignment, colSel, + return new CigarArray(alignment, alignment.getHiddenColumns(), (selectedRegionOnly ? selectionGroup : null)); } @@ -1655,8 +1658,10 @@ public abstract class AlignmentViewport implements AlignViewportI, public jalview.datamodel.AlignmentView getAlignmentView( boolean selectedOnly, boolean markGroups) { - return new AlignmentView(alignment, colSel, selectionGroup, - colSel != null && colSel.hasHiddenColumns(), selectedOnly, + return new AlignmentView(alignment, alignment.getHiddenColumns(), + selectionGroup, alignment.getHiddenColumns() != null + && alignment.getHiddenColumns().hasHiddenColumns(), + selectedOnly, markGroups); } @@ -1700,9 +1705,11 @@ public abstract class AlignmentViewport implements AlignViewportI, } selection = new String[iSize]; - if (colSel != null && colSel.hasHiddenColumns()) + if (alignment.getHiddenColumns() != null + && alignment.getHiddenColumns().hasHiddenColumns()) { - selection = colSel.getVisibleSequenceStrings(start, end, seqs); + selection = alignment.getHiddenColumns().getVisibleSequenceStrings( + start, end, seqs); } else { @@ -1724,14 +1731,15 @@ public abstract class AlignmentViewport implements AlignViewportI, do { - if (colSel != null && colSel.hasHiddenColumns()) + HiddenColumns hidden = alignment.getHiddenColumns(); + if (hidden != null && hidden.hasHiddenColumns()) { if (start == 0) { - start = colSel.adjustForHiddenColumns(start); + start = hidden.adjustForHiddenColumns(start); } - end = colSel.getHiddenBoundaryRight(start); + end = hidden.getHiddenBoundaryRight(start); if (start == end) { end = max; @@ -1744,10 +1752,10 @@ public abstract class AlignmentViewport implements AlignViewportI, regions.add(new int[] { start, end }); - if (colSel != null && colSel.hasHiddenColumns()) + if (hidden != null && hidden.hasHiddenColumns()) { - start = colSel.adjustForHiddenColumns(end); - start = colSel.getHiddenBoundaryLeft(start) + 1; + start = hidden.adjustForHiddenColumns(end); + start = hidden.getHiddenBoundaryLeft(start) + 1; } } while (end < max); @@ -1769,12 +1777,13 @@ public abstract class AlignmentViewport implements AlignViewportI, AlignmentAnnotation clone = new AlignmentAnnotation(annot); if (selectedOnly && selectionGroup != null) { - colSel.makeVisibleAnnotation(selectionGroup.getStartRes(), + alignment.getHiddenColumns().makeVisibleAnnotation( + selectionGroup.getStartRes(), selectionGroup.getEndRes(), clone); } else { - colSel.makeVisibleAnnotation(clone); + alignment.getHiddenColumns().makeVisibleAnnotation(clone); } ala.add(clone); } diff --git a/src/jalview/viewmodel/OverviewDimensions.java b/src/jalview/viewmodel/OverviewDimensions.java index 43680b5..db82aa5 100644 --- a/src/jalview/viewmodel/OverviewDimensions.java +++ b/src/jalview/viewmodel/OverviewDimensions.java @@ -20,7 +20,7 @@ */ package jalview.viewmodel; -import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.HiddenSequences; import java.awt.Graphics; @@ -125,7 +125,7 @@ public class OverviewDimensions * viewport position properties */ public void updateViewportFromMouse(int mousex, int mousey, - HiddenSequences hiddenSeqs, ColumnSelection hiddenCols, + HiddenSequences hiddenSeqs, HiddenColumns hiddenCols, ViewportRanges ranges) { int x = mousex; @@ -235,7 +235,7 @@ public class OverviewDimensions * viewport position properties */ public void setBoxPosition(HiddenSequences hiddenSeqs, - ColumnSelection hiddenCols, ViewportRanges ranges) + HiddenColumns hiddenCols, ViewportRanges ranges) { int alwidth = ranges.getAbsoluteAlignmentWidth(); int alheight = ranges.getAbsoluteAlignmentHeight(); diff --git a/src/jalview/ws/jws1/JPredThread.java b/src/jalview/ws/jws1/JPredThread.java index e685d00..078f189 100644 --- a/src/jalview/ws/jws1/JPredThread.java +++ b/src/jalview/ws/jws1/JPredThread.java @@ -28,6 +28,7 @@ import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; import jalview.datamodel.AlignmentView; import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.SequenceI; import jalview.gui.AlignFrame; import jalview.gui.Desktop; @@ -141,7 +142,7 @@ class JPredThread extends JWS1Thread implements WSClientI if (predMap != null) { Object[] alandcolsel = input - .getAlignmentAndColumnSelection(getGapChar()); + .getAlignmentAndHiddenColumns(getGapChar()); sqs = (SequenceI[]) alandcolsel[0]; al = new Alignment(sqs); alcsel = (ColumnSelection) alandcolsel[1]; @@ -192,7 +193,7 @@ class JPredThread extends JWS1Thread implements WSClientI { char gc = getGapChar(); SequenceI[] sqs = (SequenceI[]) input - .getAlignmentAndColumnSelection(gc)[0]; + .getAlignmentAndHiddenColumns(gc)[0]; if (this.msaIndex >= sqs.length) { throw new Error( @@ -625,7 +626,7 @@ class JPredThread extends JWS1Thread implements WSClientI if (res[1] != null) { af = new AlignFrame((Alignment) res[0], - (ColumnSelection) res[1], AlignFrame.DEFAULT_WIDTH, + (HiddenColumns) res[1], AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT); } else @@ -651,7 +652,8 @@ class JPredThread extends JWS1Thread implements WSClientI */ af = new AlignFrame((Alignment) res[0], - (ColumnSelection) res[1], AlignFrame.DEFAULT_WIDTH, + (HiddenColumns) res[1], + AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT); } Desktop.addInternalFrame(af, altitle, AlignFrame.DEFAULT_WIDTH, diff --git a/src/jalview/ws/jws1/MsaWSThread.java b/src/jalview/ws/jws1/MsaWSThread.java index e4247f7..72d41c9 100644 --- a/src/jalview/ws/jws1/MsaWSThread.java +++ b/src/jalview/ws/jws1/MsaWSThread.java @@ -26,7 +26,7 @@ import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentI; import jalview.datamodel.AlignmentOrder; import jalview.datamodel.AlignmentView; -import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.SequenceI; import jalview.gui.AlignFrame; import jalview.gui.Desktop; @@ -632,7 +632,7 @@ class MsaWSThread extends JWS1Thread implements WSClientI orders[j] = null; } SequenceI[] alignment = (SequenceI[]) newview[0]; - ColumnSelection columnselection = (ColumnSelection) newview[1]; + HiddenColumns hidden = (HiddenColumns) newview[1]; Alignment al = new Alignment(alignment); // TODO: add 'provenance' property to alignment from the method notes // accompanying each subjob @@ -646,7 +646,7 @@ class MsaWSThread extends JWS1Thread implements WSClientI if (newFrame) { - AlignFrame af = new AlignFrame(al, columnselection, + AlignFrame af = new AlignFrame(al, hidden, AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT); // initialise with same renderer settings as in parent alignframe. diff --git a/src/jalview/ws/jws2/MsaWSThread.java b/src/jalview/ws/jws2/MsaWSThread.java index e425624..2187f46 100644 --- a/src/jalview/ws/jws2/MsaWSThread.java +++ b/src/jalview/ws/jws2/MsaWSThread.java @@ -26,7 +26,7 @@ import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentI; import jalview.datamodel.AlignmentOrder; import jalview.datamodel.AlignmentView; -import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceI; import jalview.gui.AlignFrame; @@ -961,7 +961,7 @@ class MsaWSThread extends AWS2Thread implements WSClientI orders[j] = null; } SequenceI[] alignment = (SequenceI[]) newview[0]; - ColumnSelection columnselection = (ColumnSelection) newview[1]; + HiddenColumns hidden = (HiddenColumns) newview[1]; Alignment al = new Alignment(alignment); // TODO: add 'provenance' property to alignment from the method notes if (lastProgram != null) @@ -979,7 +979,7 @@ class MsaWSThread extends AWS2Thread implements WSClientI if (newFrame) { - displayInNewFrame(al, alorders, columnselection); + displayInNewFrame(al, alorders, hidden); } else @@ -1000,9 +1000,9 @@ class MsaWSThread extends AWS2Thread implements WSClientI * @param columnselection */ protected void displayInNewFrame(AlignmentI al, - List alorders, ColumnSelection columnselection) + List alorders, HiddenColumns hidden) { - AlignFrame af = new AlignFrame(al, columnselection, + AlignFrame af = new AlignFrame(al, hidden, AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT); // initialise with same renderer settings as in parent alignframe. diff --git a/src/jalview/ws/rest/RestClient.java b/src/jalview/ws/rest/RestClient.java index 7fbae89..27f5271 100644 --- a/src/jalview/ws/rest/RestClient.java +++ b/src/jalview/ws/rest/RestClient.java @@ -259,7 +259,8 @@ public class RestClient extends WSClient implements WSClientI, { // intersect groups with selected region _input = new AlignmentView(av.getAlignment(), - av.getColumnSelection(), av.getSelectionGroup(), + av.getAlignment() + .getHiddenColumns(), av.getSelectionGroup(), av.hasHiddenColumns(), true, true); viewTitle = MessageManager.formatMessage( "label.select_visible_region_of", @@ -272,7 +273,8 @@ public class RestClient extends WSClient implements WSClientI, { // use selected region to partition alignment _input = new AlignmentView(av.getAlignment(), - av.getColumnSelection(), av.getSelectionGroup(), + av.getAlignment() + .getHiddenColumns(), av.getSelectionGroup(), av.hasHiddenColumns(), false, true); } viewTitle = MessageManager.formatMessage( @@ -286,7 +288,8 @@ public class RestClient extends WSClient implements WSClientI, { // just take selected region intersection _input = new AlignmentView(av.getAlignment(), - av.getColumnSelection(), av.getSelectionGroup(), + av.getAlignment() + .getHiddenColumns(), av.getSelectionGroup(), av.hasHiddenColumns(), true, true); viewTitle = MessageManager.formatMessage( "label.select_visible_region_of", @@ -300,7 +303,8 @@ public class RestClient extends WSClient implements WSClientI, { // standard alignment view without selection present _input = new AlignmentView(av.getAlignment(), - av.getColumnSelection(), null, av.hasHiddenColumns(), false, + av.getAlignment() + .getHiddenColumns(), null, av.hasHiddenColumns(), false, true); viewTitle = "" + (av.hasHiddenColumns() ? (new StringBuffer(" ") diff --git a/src/jalview/ws/rest/RestJobThread.java b/src/jalview/ws/rest/RestJobThread.java index 75d2cd4..0592426 100644 --- a/src/jalview/ws/rest/RestJobThread.java +++ b/src/jalview/ws/rest/RestJobThread.java @@ -26,7 +26,7 @@ import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; import jalview.datamodel.AlignmentOrder; import jalview.datamodel.Annotation; -import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.gui.AlignFrame; @@ -173,9 +173,13 @@ public class RestJobThread extends AWSThread private String getStage(Stage stg) { if (stg == Stage.SUBMIT) + { return "submitting "; + } if (stg == Stage.POLL) + { return "checking status of "; + } return (" being confused about "); } @@ -609,7 +613,7 @@ public class RestJobThread extends AWSThread // total number of distinct alignment sets generated by job set. int numAlSets = 0, als = 0; List destAls = new ArrayList(); - List destColsel = new ArrayList(); + List destColsel = new ArrayList(); List> trees = new ArrayList>(); do @@ -715,7 +719,7 @@ public class RestJobThread extends AWSThread RestJob rj = (RestJob) jobs[nrj]; int contigs[] = input.getVisibleContigs(); AlignmentI destAl = null; - jalview.datamodel.ColumnSelection destCs = null; + jalview.datamodel.HiddenColumns destHCs = null; // Resolve destAl for this data. if (als == 0 && rj.isInputContextModified()) { @@ -731,7 +735,7 @@ public class RestJobThread extends AWSThread if (!restClient.isAlignmentModified() && merge) { destAl = restClient.av.getAlignment(); - destCs = restClient.av.getColumnSelection(); + destHCs = restClient.av.getAlignment().getHiddenColumns(); resultDest .add(restClient.isShowResultsInNewView() ? AddDataTo.newView : AddDataTo.currentView); @@ -742,15 +746,15 @@ public class RestJobThread extends AWSThread newAlignment = true; // recreate the input alignment data Object[] idat = input - .getAlignmentAndColumnSelection(gapCharacter); + .getAlignmentAndHiddenColumns(gapCharacter); destAl = new Alignment((SequenceI[]) idat[0]); - destCs = (ColumnSelection) idat[1]; + destHCs = (HiddenColumns) idat[1]; resultDest.add(AddDataTo.newAlignment); // but do not add to the alignment panel list - since we need to // create a whole new alignFrame set. } destAls.add(destAl); - destColsel.add(destCs); + destColsel.add(destHCs); } } else @@ -769,7 +773,7 @@ public class RestJobThread extends AWSThread // recover reference to last alignment created for this rest frame // ready for extension destAl = destAls.get(als); - destCs = destColsel.get(als); + destHCs = destColsel.get(als); } else { @@ -798,12 +802,12 @@ public class RestJobThread extends AWSThread newview = input.getUpdatedView(rseqs, orders, gapCharacter); } destAl = new Alignment((SequenceI[]) newview[0]); - destCs = (ColumnSelection) newview[1]; + destHCs = (HiddenColumns) newview[1]; newAlignment = true; // TODO create alignment from result data with propagated // references. destAls.add(destAl); - destColsel.add(destCs); + destColsel.add(destHCs); resultDest.add(AddDataTo.newAlignment); throw new Error( MessageManager @@ -1043,7 +1047,7 @@ public class RestJobThread extends AWSThread for (AddDataTo action : resultDest) { AlignmentI destal; - ColumnSelection destcs; + HiddenColumns destcs; String alTitle = MessageManager.formatMessage( "label.webservice_job_title_on", new String[] { restClient.service.details.Action, diff --git a/test/jalview/analysis/DnaTest.java b/test/jalview/analysis/DnaTest.java index 2e21d9c..d2fa99a 100644 --- a/test/jalview/analysis/DnaTest.java +++ b/test/jalview/analysis/DnaTest.java @@ -28,7 +28,7 @@ import jalview.api.AlignViewportI; import jalview.datamodel.AlignedCodon; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentI; -import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceI; import jalview.gui.AlignViewport; @@ -133,7 +133,7 @@ public class DnaTest AlignmentI alf = new FormatAdapter().readFile( JAL_1312_example_align_fasta, DataSourceType.PASTE, FileFormat.Fasta); - ColumnSelection cs = new ColumnSelection(); + HiddenColumns cs = new HiddenColumns(); AlignViewportI av = new AlignViewport(alf, cs); Dna dna = new Dna(av, new int[] { 0, alf.getWidth() - 1 }); AlignmentI translated = dna.translateCdna(); @@ -157,7 +157,7 @@ public class DnaTest int vwidth = 15; for (int ipos = 0; ipos + vwidth < alf.getWidth(); ipos += vwidth) { - ColumnSelection cs = new ColumnSelection(); + HiddenColumns cs = new HiddenColumns(); if (ipos > 0) { cs.hideColumns(0, ipos - 1); @@ -188,7 +188,7 @@ public class DnaTest { AlignmentI alf = new FormatAdapter().readFile(fasta, DataSourceType.PASTE, FileFormat.Fasta); - ColumnSelection cs = new ColumnSelection(); + HiddenColumns cs = new HiddenColumns(); AlignViewportI av = new AlignViewport(alf, cs); Dna dna = new Dna(av, new int[] { 0, alf.getWidth() - 1 }); AlignmentI translated = dna.translateCdna(); @@ -208,7 +208,7 @@ public class DnaTest { AlignmentI alf = new FormatAdapter().readFile(fasta, DataSourceType.PASTE, FileFormat.Fasta); - ColumnSelection cs = new ColumnSelection(); + HiddenColumns cs = new HiddenColumns(); cs.hideColumns(6, 14); // hide codons 3/4/5 cs.hideColumns(24, 35); // hide codons 9-12 cs.hideColumns(177, 191); // hide codons 60-64 @@ -296,7 +296,7 @@ public class DnaTest */ AlignmentI cdna = new AlignmentGenerator(true) .generate(12, 8, 97, 5, 5); - ColumnSelection cs = new ColumnSelection(); + HiddenColumns cs = new HiddenColumns(); AlignViewportI av = new AlignViewport(cdna, cs); Dna dna = new Dna(av, new int[] { 0, cdna.getWidth() - 1 }); AlignmentI translated = dna.translateCdna(); @@ -542,7 +542,7 @@ public class DnaTest assertEquals(seqDs, al.getSequenceAt(0).getDatasetSequence() .getSequenceAsString()); - ColumnSelection cs = new ColumnSelection(); + HiddenColumns cs = new HiddenColumns(); AlignViewportI av = new AlignViewport(al, cs); Dna testee = new Dna(av, new int[] { 0, al.getWidth() - 1 }); AlignmentI reversed = testee.reverseCdna(false); diff --git a/test/jalview/datamodel/ColumnSelectionTest.java b/test/jalview/datamodel/ColumnSelectionTest.java index 4d3f611..6debd87 100644 --- a/test/jalview/datamodel/ColumnSelectionTest.java +++ b/test/jalview/datamodel/ColumnSelectionTest.java @@ -22,10 +22,10 @@ package jalview.datamodel; 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.AssertJUnit.fail; +import jalview.analysis.AlignmentGenerator; import jalview.gui.JvOptionPane; import java.util.Arrays; @@ -88,264 +88,6 @@ public class ColumnSelectionTest } /** - * Test the method that finds the visible column position of an alignment - * column, allowing for hidden columns. - */ - @Test(groups = { "Functional" }) - public void testFindColumnPosition() - { - ColumnSelection cs = new ColumnSelection(); - assertEquals(5, cs.findColumnPosition(5)); - - // hiding column 6 makes no difference - cs.hideColumns(6, 6); - assertEquals(5, cs.findColumnPosition(5)); - - // hiding column 4 moves column 5 to column 4 - cs.hideColumns(4, 4); - assertEquals(4, cs.findColumnPosition(5)); - - // hiding column 4 moves column 4 to position 3 - assertEquals(3, cs.findColumnPosition(4)); - - // hiding columns 1 and 2 moves column 5 to column 2 - cs.hideColumns(1, 2); - assertEquals(2, cs.findColumnPosition(5)); - - // check with > 1 hidden column regions - // where some columns are in the hidden regions - ColumnSelection cs2 = new ColumnSelection(); - cs2.hideColumns(5, 10); - cs2.hideColumns(20, 27); - cs2.hideColumns(40, 44); - - // hiding columns 5-10 and 20-27 moves column 8 to column 4 - assertEquals(4, cs2.findColumnPosition(8)); - - // and moves column 24 to 13 - assertEquals(13, cs2.findColumnPosition(24)); - - // and moves column 28 to 14 - assertEquals(14, cs2.findColumnPosition(28)); - - // and moves column 40 to 25 - assertEquals(25, cs2.findColumnPosition(40)); - - // check when hidden columns start at 0 that the visible column - // is returned as 0 - ColumnSelection cs3 = new ColumnSelection(); - cs3.hideColumns(0, 4); - assertEquals(0, cs3.findColumnPosition(2)); - - } - - /** - * Test the method that finds the visible column position a given distance - * before another column - */ - @Test(groups = { "Functional" }) - public void testFindColumnNToLeft() - { - ColumnSelection cs = new ColumnSelection(); - - // test that without hidden columns, findColumnNToLeft returns - // position n to left of provided position - int pos = cs.subtractVisibleColumns(3, 10); - assertEquals(7, pos); - - // 0 returns same position - pos = cs.subtractVisibleColumns(0, 10); - assertEquals(10, pos); - - // overflow to left returns negative number - pos = cs.subtractVisibleColumns(3, 0); - assertEquals(-3, pos); - - // test that with hidden columns to left of result column - // behaviour is the same as above - cs.hideColumns(1, 3); - - // position n to left of provided position - pos = cs.subtractVisibleColumns(3, 10); - assertEquals(7, pos); - - // 0 returns same position - pos = cs.subtractVisibleColumns(0, 10); - assertEquals(10, pos); - - // test with one set of hidden columns between start and required position - cs.hideColumns(12, 15); - pos = cs.subtractVisibleColumns(8, 17); - assertEquals(5, pos); - - // test with two sets of hidden columns between start and required position - cs.hideColumns(20, 21); - pos = cs.subtractVisibleColumns(8, 23); - assertEquals(9, pos); - - // repeat last 2 tests with no hidden columns to left of required position - cs.revealAllHiddenColumns(); - - // test with one set of hidden columns between start and required position - cs.hideColumns(12, 15); - pos = cs.subtractVisibleColumns(8, 17); - assertEquals(5, pos); - - // test with two sets of hidden columns between start and required position - cs.hideColumns(20, 21); - pos = cs.subtractVisibleColumns(8, 23); - assertEquals(9, pos); - - } - - /** - * Test the code used to locate the reference sequence ruler origin - */ - @Test(groups = { "Functional" }) - public void testLocateVisibleBoundsofSequence() - { - ColumnSelection cs = new ColumnSelection(); - SequenceI seq = new Sequence("RefSeq", "-A-SD-ASD--E---"); - assertEquals(2, seq.findIndex(seq.getStart())); - - // no hidden columns - assertEquals( - Arrays.toString(new int[] { seq.findIndex(seq.getStart()) - 1, - seq.findIndex(seq.getEnd()) - 1, seq.getStart(), - seq.getEnd(), seq.findIndex(seq.getStart()) - 1, - seq.findIndex(seq.getEnd()) - 1 }), - Arrays.toString(cs.locateVisibleBoundsOfSequence(seq))); - - // hidden column on gap after end of sequence - should not affect bounds - cs.hideColumns(13); - assertEquals( - Arrays.toString(new int[] { seq.findIndex(seq.getStart()) - 1, - seq.findIndex(seq.getEnd()) - 1, seq.getStart(), - seq.getEnd(), seq.findIndex(seq.getStart()) - 1, - seq.findIndex(seq.getEnd()) - 1 }), - Arrays.toString(cs.locateVisibleBoundsOfSequence(seq))); - - cs.revealAllHiddenColumns(); - // hidden column on gap before beginning of sequence - should vis bounds by - // one - cs.hideColumns(0); - assertEquals( - Arrays.toString(new int[] { seq.findIndex(seq.getStart()) - 2, - seq.findIndex(seq.getEnd()) - 2, seq.getStart(), - seq.getEnd(), seq.findIndex(seq.getStart()) - 1, - seq.findIndex(seq.getEnd()) - 1 }), - Arrays.toString(cs.locateVisibleBoundsOfSequence(seq))); - - cs.revealAllHiddenColumns(); - // hide columns around most of sequence - leave one residue remaining - cs.hideColumns(1, 3); - cs.hideColumns(6, 11); - assertEquals("-D", - cs.getVisibleSequenceStrings(0, 5, new SequenceI[] { seq })[0]); - assertEquals( - Arrays.toString(new int[] { 1, 1, 3, 3, - seq.findIndex(seq.getStart()) - 1, - seq.findIndex(seq.getEnd()) - 1 }), - Arrays.toString(cs.locateVisibleBoundsOfSequence(seq))); - cs.revealAllHiddenColumns(); - - // hide whole sequence - should just get location of hidden region - // containing sequence - cs.hideColumns(1, 11); - assertEquals( - Arrays.toString(new int[] { 0, 1, 0, 0, - seq.findIndex(seq.getStart()) - 1, - seq.findIndex(seq.getEnd()) - 1 }), - Arrays.toString(cs.locateVisibleBoundsOfSequence(seq))); - - } - - @Test(groups = { "Functional" }) - public void testLocateVisibleBoundsPathologicals() - { - // test some pathological cases we missed - AlignmentI al = new Alignment(new SequenceI[] { new Sequence( - "refseqGaptest", "KTDVTI----------NFI-----G----L") }); - ColumnSelection cs = new ColumnSelection(); - cs.hideInsertionsFor(al.getSequenceAt(0)); - assertEquals( - "G", - "" - + al.getSequenceAt(0).getCharAt( - cs.adjustForHiddenColumns(9))); - - } - - @Test(groups = { "Functional" }) - public void testHideColumns() - { - ColumnSelection cs = new ColumnSelection(); - cs.hideColumns(5); - List hidden = cs.getHiddenColumns(); - assertEquals(1, hidden.size()); - assertEquals("[5, 5]", Arrays.toString(hidden.get(0))); - - cs.hideColumns(3); - assertEquals(2, hidden.size()); - // two hidden ranges, in order: - assertSame(hidden, cs.getHiddenColumns()); - assertEquals("[3, 3]", Arrays.toString(hidden.get(0))); - assertEquals("[5, 5]", Arrays.toString(hidden.get(1))); - - // hiding column 4 expands [3, 3] to [3, 4] - // and merges to [5, 5] to make [3, 5] - cs.hideColumns(4); - hidden = cs.getHiddenColumns(); - assertEquals(1, hidden.size()); - assertEquals("[3, 5]", Arrays.toString(hidden.get(0))); - - // clear hidden columns (note they are added to selected) - cs.revealAllHiddenColumns(); - // it is now actually null but getter returns an empty list - assertTrue(cs.getHiddenColumns().isEmpty()); - - cs.hideColumns(3, 6); - hidden = cs.getHiddenColumns(); - int[] firstHiddenRange = hidden.get(0); - assertEquals("[3, 6]", Arrays.toString(firstHiddenRange)); - - // adding a subrange of already hidden should do nothing - cs.hideColumns(4, 5); - assertEquals(1, hidden.size()); - assertSame(firstHiddenRange, cs.getHiddenColumns().get(0)); - cs.hideColumns(3, 5); - assertEquals(1, hidden.size()); - assertSame(firstHiddenRange, cs.getHiddenColumns().get(0)); - cs.hideColumns(4, 6); - assertEquals(1, hidden.size()); - assertSame(firstHiddenRange, cs.getHiddenColumns().get(0)); - cs.hideColumns(3, 6); - assertEquals(1, hidden.size()); - assertSame(firstHiddenRange, cs.getHiddenColumns().get(0)); - - cs.revealAllHiddenColumns(); - cs.hideColumns(2, 4); - hidden = cs.getHiddenColumns(); - assertEquals(1, hidden.size()); - assertEquals("[2, 4]", Arrays.toString(hidden.get(0))); - - // extend contiguous with 2 positions overlap - cs.hideColumns(3, 5); - assertEquals(1, hidden.size()); - assertEquals("[2, 5]", Arrays.toString(hidden.get(0))); - - // extend contiguous with 1 position overlap - cs.hideColumns(5, 6); - assertEquals(1, hidden.size()); - assertEquals("[2, 6]", Arrays.toString(hidden.get(0))); - - // extend contiguous with overlap both ends: - cs.hideColumns(1, 7); - assertEquals(1, hidden.size()); - assertEquals("[1, 7]", Arrays.toString(hidden.get(0))); - } - - /** * Test the method that hides a specified column including any adjacent * selected columns. This is a convenience method for the case where multiple * column regions are selected and then hidden using menu option View | Hide | @@ -354,48 +96,55 @@ public class ColumnSelectionTest @Test(groups = { "Functional" }) public void testHideColumns_withSelection() { + // create random alignment + AlignmentGenerator gen = new AlignmentGenerator(false); + AlignmentI al = gen.generate(50, 20, 123, 5, 5); + ColumnSelection cs = new ColumnSelection(); // select columns 4-6 cs.addElement(4); cs.addElement(5); cs.addElement(6); // hide column 5 (and adjacent): - cs.hideColumns(5); + cs.hideSelectedColumns(5, al); // 4,5,6 now hidden: - List hidden = cs.getHiddenColumns(); + List hidden = al.getHiddenColumns().getListOfCols(); assertEquals(1, hidden.size()); assertEquals("[4, 6]", Arrays.toString(hidden.get(0))); // none now selected: assertTrue(cs.getSelected().isEmpty()); // repeat, hiding column 4 (5 and 6) + al = gen.generate(50, 20, 123, 5, 5); cs = new ColumnSelection(); cs.addElement(4); cs.addElement(5); cs.addElement(6); - cs.hideColumns(4); - hidden = cs.getHiddenColumns(); + cs.hideSelectedColumns(4, al); + hidden = al.getHiddenColumns().getListOfCols(); assertEquals(1, hidden.size()); assertEquals("[4, 6]", Arrays.toString(hidden.get(0))); assertTrue(cs.getSelected().isEmpty()); // repeat, hiding column (4, 5 and) 6 + al = gen.generate(50, 20, 123, 5, 5); cs = new ColumnSelection(); cs.addElement(4); cs.addElement(5); cs.addElement(6); - cs.hideColumns(6); - hidden = cs.getHiddenColumns(); + cs.hideSelectedColumns(6, al); + hidden = al.getHiddenColumns().getListOfCols(); assertEquals(1, hidden.size()); assertEquals("[4, 6]", Arrays.toString(hidden.get(0))); assertTrue(cs.getSelected().isEmpty()); // repeat, with _only_ adjacent columns selected + al = gen.generate(50, 20, 123, 5, 5); cs = new ColumnSelection(); cs.addElement(4); cs.addElement(6); - cs.hideColumns(5); - hidden = cs.getHiddenColumns(); + cs.hideSelectedColumns(5, al); + hidden = al.getHiddenColumns().getListOfCols(); assertEquals(1, hidden.size()); assertEquals("[4, 6]", Arrays.toString(hidden.get(0))); assertTrue(cs.getSelected().isEmpty()); @@ -407,17 +156,23 @@ public class ColumnSelectionTest @Test(groups = { "Functional" }) public void testHideSelectedColumns() { + // create random alignment + AlignmentGenerator gen = new AlignmentGenerator(false); + AlignmentI al = gen.generate(50, 20, 123, 5, 5); + ColumnSelection cs = new ColumnSelection(); int[] sel = { 2, 3, 4, 7, 8, 9, 20, 21, 22 }; for (int col : sel) { cs.addElement(col); } - cs.hideColumns(15, 18); - cs.hideSelectedColumns(); + HiddenColumns cols = al.getHiddenColumns(); + cols.hideColumns(15, 18); + + cs.hideSelectedColumns(al); assertTrue(cs.getSelected().isEmpty()); - List hidden = cs.getHiddenColumns(); + List hidden = cols.getListOfCols(); assertEquals(4, hidden.size()); assertEquals("[2, 4]", Arrays.toString(hidden.get(0))); assertEquals("[7, 9]", Arrays.toString(hidden.get(1))); @@ -455,104 +210,27 @@ public class ColumnSelectionTest assertEquals("[0, 4]", Arrays.toString(range.get(0))); } - /** - * Test the method that reveals a range of hidden columns given the start - * column of the range - */ - @Test(groups = { "Functional" }) - public void testRevealHiddenColumns() - { - ColumnSelection cs = new ColumnSelection(); - cs.hideColumns(5, 8); - cs.addElement(10); - cs.revealHiddenColumns(5); - // hidden columns list now null but getter returns empty list: - assertTrue(cs.getHiddenColumns().isEmpty()); - // revealed columns are marked as selected (added to selection): - assertEquals("[10, 5, 6, 7, 8]", cs.getSelected().toString()); - - // calling with a column other than the range start does nothing: - cs = new ColumnSelection(); - cs.hideColumns(5, 8); - List hidden = cs.getHiddenColumns(); - cs.revealHiddenColumns(6); - assertSame(hidden, cs.getHiddenColumns()); - assertTrue(cs.getSelected().isEmpty()); - } - - @Test(groups = { "Functional" }) - public void testRevealAllHiddenColumns() - { - ColumnSelection cs = new ColumnSelection(); - cs.hideColumns(5, 8); - cs.hideColumns(2, 3); - cs.addElement(11); - cs.addElement(1); - cs.revealAllHiddenColumns(); - - /* - * revealing hidden columns adds them (in order) to the (unordered) - * selection list - */ - assertTrue(cs.getHiddenColumns().isEmpty()); - assertEquals("[11, 1, 2, 3, 5, 6, 7, 8]", cs.getSelected().toString()); - } - - @Test(groups = { "Functional" }) - public void testIsVisible() - { - ColumnSelection cs = new ColumnSelection(); - cs.hideColumns(2, 4); - cs.hideColumns(6, 7); - assertTrue(cs.isVisible(0)); - assertTrue(cs.isVisible(-99)); - assertTrue(cs.isVisible(1)); - assertFalse(cs.isVisible(2)); - assertFalse(cs.isVisible(3)); - assertFalse(cs.isVisible(4)); - assertTrue(cs.isVisible(5)); - assertFalse(cs.isVisible(6)); - assertFalse(cs.isVisible(7)); - } - - @Test(groups = { "Functional" }) - public void testGetVisibleContigs() - { - ColumnSelection cs = new ColumnSelection(); - cs.hideColumns(3, 6); - cs.hideColumns(8, 9); - cs.hideColumns(12, 12); - - // start position is inclusive, end position exclusive: - int[] visible = cs.getVisibleContigs(1, 13); - assertEquals("[1, 2, 7, 7, 10, 11]", Arrays.toString(visible)); - - visible = cs.getVisibleContigs(4, 14); - assertEquals("[7, 7, 10, 11, 13, 13]", Arrays.toString(visible)); - - visible = cs.getVisibleContigs(3, 10); - assertEquals("[7, 7]", Arrays.toString(visible)); - - visible = cs.getVisibleContigs(4, 6); - assertEquals("[]", Arrays.toString(visible)); - } - @Test(groups = { "Functional" }) public void testInvertColumnSelection() { + // create random alignment + AlignmentGenerator gen = new AlignmentGenerator(false); + AlignmentI al = gen.generate(50, 20, 123, 5, 5); + ColumnSelection cs = new ColumnSelection(); cs.addElement(4); cs.addElement(6); cs.addElement(8); - cs.hideColumns(3, 3); - cs.hideColumns(6, 6); + + HiddenColumns cols = al.getHiddenColumns(); + cols.hideColumns(3, 3); + cols.hideColumns(6, 6); // invert selection from start (inclusive) to end (exclusive) - // hidden columns are _not_ changed - cs.invertColumnSelection(2, 9); + cs.invertColumnSelection(2, 9, al); assertEquals("[2, 5, 7]", cs.getSelected().toString()); - cs.invertColumnSelection(1, 9); + cs.invertColumnSelection(1, 9, al); assertEquals("[1, 4, 8]", cs.getSelected().toString()); } @@ -595,9 +273,6 @@ public class ColumnSelectionTest cs.addElement(0); cs.addElement(513); cs.addElement(1); - cs.hideColumns(3); - cs.hideColumns(7); - cs.hideColumns(5, 9); // same selections added in a different order ColumnSelection cs2 = new ColumnSelection(); @@ -605,15 +280,6 @@ public class ColumnSelectionTest cs2.addElement(513); cs2.addElement(0); - // with no hidden columns - assertFalse(cs.equals(cs2)); - assertFalse(cs2.equals(cs)); - - // with hidden columns added in a different order - cs2.hideColumns(6, 9); - cs2.hideColumns(5, 8); - cs2.hideColumns(3); - assertTrue(cs.equals(cs2)); assertTrue(cs.equals(cs)); assertTrue(cs2.equals(cs)); @@ -625,18 +291,20 @@ public class ColumnSelectionTest cs2.removeElement(12); assertTrue(cs.equals(cs2)); - - cs2.hideColumns(88); - assertFalse(cs.equals(cs2)); - /* - * unhiding a column adds it to selection! - */ - cs2.revealHiddenColumns(88); - assertFalse(cs.equals(cs2)); - cs.addElement(88); - assertTrue(cs.equals(cs2)); } + /* + cs2.hideSelectedColumns(88); + assertFalse(cs.equals(cs2)); + /* + * unhiding a column adds it to selection! + */ + /* cs2.revealHiddenColumns(88); + assertFalse(cs.equals(cs2)); + cs.addElement(88); + assertTrue(cs.equals(cs2)); + */ + /** * Test the method that returns selected columns, in the order in which they * were added @@ -834,75 +502,14 @@ public class ColumnSelectionTest ColumnSelection cs = new ColumnSelection(); cs.addElement(3); cs.addElement(1); - cs.hideColumns(10, 11); - cs.hideColumns(5, 7); - assertEquals("[5, 7]", Arrays.toString(cs.getHiddenColumns().get(0))); ColumnSelection cs2 = new ColumnSelection(cs); assertTrue(cs2.hasSelectedColumns()); - assertTrue(cs2.hasHiddenColumns()); + // order of column selection is preserved assertEquals("[3, 1]", cs2.getSelected().toString()); - assertEquals(2, cs2.getHiddenColumns().size()); - // hidden columns are held in column order - assertEquals("[5, 7]", Arrays.toString(cs2.getHiddenColumns().get(0))); - assertEquals("[10, 11]", Arrays.toString(cs2.getHiddenColumns().get(1))); } - /** - * Test for the case when a hidden range encloses more one already hidden - * range - */ - @Test(groups = { "Functional" }) - public void testHideColumns_subsumingHidden() - { - /* - * JAL-2370 bug scenario: - * two hidden ranges subsumed by a third - */ - ColumnSelection cs = new ColumnSelection(); - cs.hideColumns(49, 59); - cs.hideColumns(69, 79); - List hidden = cs.getHiddenColumns(); - assertEquals(2, hidden.size()); - assertEquals("[49, 59]", Arrays.toString(hidden.get(0))); - assertEquals("[69, 79]", Arrays.toString(hidden.get(1))); - - cs.hideColumns(48, 80); - hidden = cs.getHiddenColumns(); - assertEquals(1, hidden.size()); - assertEquals("[48, 80]", Arrays.toString(hidden.get(0))); - - /* - * another...joining hidden ranges - */ - cs = new ColumnSelection(); - cs.hideColumns(10, 20); - cs.hideColumns(30, 40); - cs.hideColumns(50, 60); - // hiding 21-49 should merge to one range - cs.hideColumns(21, 49); - hidden = cs.getHiddenColumns(); - assertEquals(1, hidden.size()); - assertEquals("[10, 60]", Arrays.toString(hidden.get(0))); - - /* - * another...lef overlap, subsumption, right overlap, - * no overlap of existing hidden ranges - */ - cs = new ColumnSelection(); - cs.hideColumns(10, 20); - cs.hideColumns(10, 20); - cs.hideColumns(30, 35); - cs.hideColumns(40, 50); - cs.hideColumns(60, 70); - - cs.hideColumns(15, 45); - hidden = cs.getHiddenColumns(); - assertEquals(2, hidden.size()); - assertEquals("[10, 50]", Arrays.toString(hidden.get(0))); - assertEquals("[60, 70]", Arrays.toString(hidden.get(1))); - } @Test(groups = { "Functional" }) public void testStretchGroup_expand() diff --git a/test/jalview/datamodel/HiddenColumnsTest.java b/test/jalview/datamodel/HiddenColumnsTest.java new file mode 100644 index 0000000..be658d5 --- /dev/null +++ b/test/jalview/datamodel/HiddenColumnsTest.java @@ -0,0 +1,497 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ 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.assertFalse; +import static org.testng.AssertJUnit.assertSame; +import static org.testng.AssertJUnit.assertTrue; + +import jalview.analysis.AlignmentGenerator; +import jalview.gui.JvOptionPane; + +import java.util.Arrays; +import java.util.List; + +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class HiddenColumnsTest +{ + + @BeforeClass(alwaysRun = true) + public void setUpJvOptionPane() + { + JvOptionPane.setInteractiveMode(false); + JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); + } + + /** + * Test the method that finds the visible column position of an alignment + * column, allowing for hidden columns. + */ + @Test(groups = { "Functional" }) + public void testFindColumnPosition() + { + HiddenColumns cs = new HiddenColumns(); + assertEquals(5, cs.findColumnPosition(5)); + + // hiding column 6 makes no difference + cs.hideColumns(6, 6); + assertEquals(5, cs.findColumnPosition(5)); + + // hiding column 4 moves column 5 to column 4 + cs.hideColumns(4, 4); + assertEquals(4, cs.findColumnPosition(5)); + + // hiding column 4 moves column 4 to position 3 + assertEquals(3, cs.findColumnPosition(4)); + + // hiding columns 1 and 2 moves column 5 to column 2 + cs.hideColumns(1, 2); + assertEquals(2, cs.findColumnPosition(5)); + + // check with > 1 hidden column regions + // where some columns are in the hidden regions + HiddenColumns cs2 = new HiddenColumns(); + cs2.hideColumns(5, 10); + cs2.hideColumns(20, 27); + cs2.hideColumns(40, 44); + + // hiding columns 5-10 and 20-27 moves column 8 to column 4 + assertEquals(4, cs2.findColumnPosition(8)); + + // and moves column 24 to 13 + assertEquals(13, cs2.findColumnPosition(24)); + + // and moves column 28 to 14 + assertEquals(14, cs2.findColumnPosition(28)); + + // and moves column 40 to 25 + assertEquals(25, cs2.findColumnPosition(40)); + + // check when hidden columns start at 0 that the visible column + // is returned as 0 + HiddenColumns cs3 = new HiddenColumns(); + cs3.hideColumns(0, 4); + assertEquals(0, cs3.findColumnPosition(2)); + + } + + /** + * Test the method that finds the visible column position a given distance + * before another column + */ + @Test(groups = { "Functional" }) + public void testFindColumnNToLeft() + { + HiddenColumns cs = new HiddenColumns(); + + // test that without hidden columns, findColumnNToLeft returns + // position n to left of provided position + int pos = cs.subtractVisibleColumns(3, 10); + assertEquals(7, pos); + + // 0 returns same position + pos = cs.subtractVisibleColumns(0, 10); + assertEquals(10, pos); + + // overflow to left returns negative number + pos = cs.subtractVisibleColumns(3, 0); + assertEquals(-3, pos); + + // test that with hidden columns to left of result column + // behaviour is the same as above + cs.hideColumns(1, 3); + + // position n to left of provided position + pos = cs.subtractVisibleColumns(3, 10); + assertEquals(7, pos); + + // 0 returns same position + pos = cs.subtractVisibleColumns(0, 10); + assertEquals(10, pos); + + // test with one set of hidden columns between start and required position + cs.hideColumns(12, 15); + pos = cs.subtractVisibleColumns(8, 17); + assertEquals(5, pos); + + // test with two sets of hidden columns between start and required position + cs.hideColumns(20, 21); + pos = cs.subtractVisibleColumns(8, 23); + assertEquals(9, pos); + + // repeat last 2 tests with no hidden columns to left of required position + ColumnSelection colsel = new ColumnSelection(); + cs.revealAllHiddenColumns(colsel); + + // test with one set of hidden columns between start and required position + cs.hideColumns(12, 15); + pos = cs.subtractVisibleColumns(8, 17); + assertEquals(5, pos); + + // test with two sets of hidden columns between start and required position + cs.hideColumns(20, 21); + pos = cs.subtractVisibleColumns(8, 23); + assertEquals(9, pos); + + } + + @Test(groups = { "Functional" }) + public void testGetVisibleContigs() + { + HiddenColumns cs = new HiddenColumns(); + cs.hideColumns(3, 6); + cs.hideColumns(8, 9); + cs.hideColumns(12, 12); + + // start position is inclusive, end position exclusive: + int[] visible = cs.getVisibleContigs(1, 13); + assertEquals("[1, 2, 7, 7, 10, 11]", Arrays.toString(visible)); + + visible = cs.getVisibleContigs(4, 14); + assertEquals("[7, 7, 10, 11, 13, 13]", Arrays.toString(visible)); + + visible = cs.getVisibleContigs(3, 10); + assertEquals("[7, 7]", Arrays.toString(visible)); + + visible = cs.getVisibleContigs(4, 6); + assertEquals("[]", Arrays.toString(visible)); + } + + @Test(groups = { "Functional" }) + public void testEquals() + { + HiddenColumns cs = new HiddenColumns(); + cs.hideColumns(5, 9); + + // a different set of hidden columns + HiddenColumns cs2 = new HiddenColumns(); + + // with no hidden columns + assertFalse(cs.equals(cs2)); + assertFalse(cs2.equals(cs)); + + // with hidden columns added in a different order + cs2.hideColumns(6, 9); + cs2.hideColumns(5, 8); + + assertTrue(cs.equals(cs2)); + assertTrue(cs.equals(cs)); + assertTrue(cs2.equals(cs)); + assertTrue(cs2.equals(cs2)); + } + + @Test(groups = "Functional") + public void testCopyConstructor() + { + HiddenColumns cs = new HiddenColumns(); + cs.hideColumns(10, 11); + cs.hideColumns(5, 7); + assertEquals("[5, 7]", Arrays.toString(cs.getListOfCols().get(0))); + + HiddenColumns cs2 = new HiddenColumns(cs); + assertTrue(cs2.hasHiddenColumns()); + assertEquals(2, cs2.getListOfCols().size()); + // hidden columns are held in column order + assertEquals("[5, 7]", Arrays.toString(cs2.getListOfCols().get(0))); + assertEquals("[10, 11]", Arrays.toString(cs2.getListOfCols().get(1))); + } + + /** + * Test the code used to locate the reference sequence ruler origin + */ + @Test(groups = { "Functional" }) + public void testLocateVisibleBoundsofSequence() + { + // create random alignment + AlignmentGenerator gen = new AlignmentGenerator(false); + AlignmentI al = gen.generate(50, 20, 123, 5, 5); + + HiddenColumns cs = al.getHiddenColumns(); + ColumnSelection colsel = new ColumnSelection(); + + SequenceI seq = new Sequence("RefSeq", "-A-SD-ASD--E---"); + assertEquals(2, seq.findIndex(seq.getStart())); + + // no hidden columns + assertEquals( + Arrays.toString(new int[] { seq.findIndex(seq.getStart()) - 1, + seq.findIndex(seq.getEnd()) - 1, seq.getStart(), + seq.getEnd(), seq.findIndex(seq.getStart()) - 1, + seq.findIndex(seq.getEnd()) - 1 }), + Arrays.toString(cs.locateVisibleBoundsOfSequence(seq))); + + // hidden column on gap after end of sequence - should not affect bounds + colsel.hideSelectedColumns(13, al); + assertEquals( + Arrays.toString(new int[] { seq.findIndex(seq.getStart()) - 1, + seq.findIndex(seq.getEnd()) - 1, seq.getStart(), + seq.getEnd(), seq.findIndex(seq.getStart()) - 1, + seq.findIndex(seq.getEnd()) - 1 }), + Arrays.toString(cs.locateVisibleBoundsOfSequence(seq))); + + cs.revealAllHiddenColumns(colsel); + // hidden column on gap before beginning of sequence - should vis bounds by + // one + colsel.hideSelectedColumns(0, al); + assertEquals( + Arrays.toString(new int[] { seq.findIndex(seq.getStart()) - 2, + seq.findIndex(seq.getEnd()) - 2, seq.getStart(), + seq.getEnd(), seq.findIndex(seq.getStart()) - 1, + seq.findIndex(seq.getEnd()) - 1 }), + Arrays.toString(cs.locateVisibleBoundsOfSequence(seq))); + + cs.revealAllHiddenColumns(colsel); + // hide columns around most of sequence - leave one residue remaining + cs.hideColumns(1, 3); + cs.hideColumns(6, 11); + assertEquals("-D", + cs.getVisibleSequenceStrings(0, 5, new SequenceI[] { seq })[0]); + assertEquals( + Arrays.toString(new int[] { 1, 1, 3, 3, + seq.findIndex(seq.getStart()) - 1, + seq.findIndex(seq.getEnd()) - 1 }), + Arrays.toString(cs.locateVisibleBoundsOfSequence(seq))); + cs.revealAllHiddenColumns(colsel); + + // hide whole sequence - should just get location of hidden region + // containing sequence + cs.hideColumns(1, 11); + assertEquals( + Arrays.toString(new int[] { 0, 1, 0, 0, + seq.findIndex(seq.getStart()) - 1, + seq.findIndex(seq.getEnd()) - 1 }), + Arrays.toString(cs.locateVisibleBoundsOfSequence(seq))); + + } + + @Test(groups = { "Functional" }) + public void testLocateVisibleBoundsPathologicals() + { + // test some pathological cases we missed + AlignmentI al = new Alignment(new SequenceI[] { new Sequence( + "refseqGaptest", "KTDVTI----------NFI-----G----L") }); + HiddenColumns cs = new HiddenColumns(); + cs.hideInsertionsFor(al.getSequenceAt(0)); + assertEquals( + "G", + "" + + al.getSequenceAt(0).getCharAt( + cs.adjustForHiddenColumns(9))); + + } + + @Test(groups = { "Functional" }) + public void testHideColumns() + { + // create random alignment + AlignmentGenerator gen = new AlignmentGenerator(false); + AlignmentI al = gen.generate(50, 20, 123, 5, 5); + + ColumnSelection colsel = new ColumnSelection(); + HiddenColumns cs = al.getHiddenColumns(); + colsel.hideSelectedColumns(5, al); + List hidden = cs.getListOfCols(); + assertEquals(1, hidden.size()); + assertEquals("[5, 5]", Arrays.toString(hidden.get(0))); + + colsel.hideSelectedColumns(3, al); + assertEquals(2, hidden.size()); + // two hidden ranges, in order: + assertSame(hidden, cs.getListOfCols()); + assertEquals("[3, 3]", Arrays.toString(hidden.get(0))); + assertEquals("[5, 5]", Arrays.toString(hidden.get(1))); + + // hiding column 4 expands [3, 3] to [3, 4] + // and merges to [5, 5] to make [3, 5] + colsel.hideSelectedColumns(4, al); + hidden = cs.getListOfCols(); + assertEquals(1, hidden.size()); + assertEquals("[3, 5]", Arrays.toString(hidden.get(0))); + + // clear hidden columns (note they are added to selected) + cs.revealAllHiddenColumns(colsel); + // it is now actually null but getter returns an empty list + assertTrue(cs.getListOfCols().isEmpty()); + + cs.hideColumns(3, 6); + hidden = cs.getListOfCols(); + int[] firstHiddenRange = hidden.get(0); + assertEquals("[3, 6]", Arrays.toString(firstHiddenRange)); + + // adding a subrange of already hidden should do nothing + cs.hideColumns(4, 5); + assertEquals(1, hidden.size()); + assertSame(firstHiddenRange, cs.getListOfCols().get(0)); + cs.hideColumns(3, 5); + assertEquals(1, hidden.size()); + assertSame(firstHiddenRange, cs.getListOfCols().get(0)); + cs.hideColumns(4, 6); + assertEquals(1, hidden.size()); + assertSame(firstHiddenRange, cs.getListOfCols().get(0)); + cs.hideColumns(3, 6); + assertEquals(1, hidden.size()); + assertSame(firstHiddenRange, cs.getListOfCols().get(0)); + + cs.revealAllHiddenColumns(colsel); + cs.hideColumns(2, 4); + hidden = cs.getListOfCols(); + assertEquals(1, hidden.size()); + assertEquals("[2, 4]", Arrays.toString(hidden.get(0))); + + // extend contiguous with 2 positions overlap + cs.hideColumns(3, 5); + assertEquals(1, hidden.size()); + assertEquals("[2, 5]", Arrays.toString(hidden.get(0))); + + // extend contiguous with 1 position overlap + cs.hideColumns(5, 6); + assertEquals(1, hidden.size()); + assertEquals("[2, 6]", Arrays.toString(hidden.get(0))); + + // extend contiguous with overlap both ends: + cs.hideColumns(1, 7); + assertEquals(1, hidden.size()); + assertEquals("[1, 7]", Arrays.toString(hidden.get(0))); + } + + /** + * Test the method that reveals a range of hidden columns given the start + * column of the range + */ + @Test(groups = { "Functional" }) + public void testRevealHiddenColumns() + { + ColumnSelection colsel = new ColumnSelection(); + HiddenColumns cs = new HiddenColumns(); + cs.hideColumns(5, 8); + colsel.addElement(10); + cs.revealHiddenColumns(5, colsel); + // hidden columns list now null but getter returns empty list: + assertTrue(cs.getListOfCols().isEmpty()); + // revealed columns are marked as selected (added to selection): + assertEquals("[10, 5, 6, 7, 8]", colsel.getSelected().toString()); + + // calling with a column other than the range start does nothing: + colsel = new ColumnSelection(); + cs = new HiddenColumns(); + cs.hideColumns(5, 8); + List hidden = cs.getListOfCols(); + cs.revealHiddenColumns(6, colsel); + assertSame(hidden, cs.getListOfCols()); + assertTrue(colsel.getSelected().isEmpty()); + } + + @Test(groups = { "Functional" }) + public void testRevealAllHiddenColumns() + { + HiddenColumns cs = new HiddenColumns(); + ColumnSelection colsel = new ColumnSelection(); + cs.hideColumns(5, 8); + cs.hideColumns(2, 3); + colsel.addElement(11); + colsel.addElement(1); + cs.revealAllHiddenColumns(colsel); + + /* + * revealing hidden columns adds them (in order) to the (unordered) + * selection list + */ + assertTrue(cs.getListOfCols().isEmpty()); + assertEquals("[11, 1, 2, 3, 5, 6, 7, 8]", colsel.getSelected() + .toString()); + } + + @Test(groups = { "Functional" }) + public void testIsVisible() + { + HiddenColumns cs = new HiddenColumns(); + cs.hideColumns(2, 4); + cs.hideColumns(6, 7); + assertTrue(cs.isVisible(0)); + assertTrue(cs.isVisible(-99)); + assertTrue(cs.isVisible(1)); + assertFalse(cs.isVisible(2)); + assertFalse(cs.isVisible(3)); + assertFalse(cs.isVisible(4)); + assertTrue(cs.isVisible(5)); + assertFalse(cs.isVisible(6)); + assertFalse(cs.isVisible(7)); + } + + /** + * Test for the case when a hidden range encloses more one already hidden + * range + */ + @Test(groups = { "Functional" }) + public void testHideColumns_subsumingHidden() + { + /* + * JAL-2370 bug scenario: + * two hidden ranges subsumed by a third + */ + HiddenColumns cs = new HiddenColumns(); + cs.hideColumns(49, 59); + cs.hideColumns(69, 79); + List hidden = cs.getListOfCols(); + assertEquals(2, hidden.size()); + assertEquals("[49, 59]", Arrays.toString(hidden.get(0))); + assertEquals("[69, 79]", Arrays.toString(hidden.get(1))); + + cs.hideColumns(48, 80); + hidden = cs.getListOfCols(); + assertEquals(1, hidden.size()); + assertEquals("[48, 80]", Arrays.toString(hidden.get(0))); + + /* + * another...joining hidden ranges + */ + cs = new HiddenColumns(); + cs.hideColumns(10, 20); + cs.hideColumns(30, 40); + cs.hideColumns(50, 60); + // hiding 21-49 should merge to one range + cs.hideColumns(21, 49); + hidden = cs.getListOfCols(); + assertEquals(1, hidden.size()); + assertEquals("[10, 60]", Arrays.toString(hidden.get(0))); + + /* + * another...left overlap, subsumption, right overlap, + * no overlap of existing hidden ranges + */ + cs = new HiddenColumns(); + cs.hideColumns(10, 20); + cs.hideColumns(10, 20); + cs.hideColumns(30, 35); + cs.hideColumns(40, 50); + cs.hideColumns(60, 70); + + cs.hideColumns(15, 45); + hidden = cs.getListOfCols(); + assertEquals(2, hidden.size()); + assertEquals("[10, 50]", Arrays.toString(hidden.get(0))); + assertEquals("[60, 70]", Arrays.toString(hidden.get(1))); + } + +} diff --git a/test/jalview/gui/AlignFrameTest.java b/test/jalview/gui/AlignFrameTest.java index 2ea94a4..bd6b68f 100644 --- a/test/jalview/gui/AlignFrameTest.java +++ b/test/jalview/gui/AlignFrameTest.java @@ -85,11 +85,13 @@ public class AlignFrameTest */ assertFalse(alignFrame.hideFeatureColumns("exon", true)); assertTrue(alignFrame.getViewport().getColumnSelection().isEmpty()); - assertTrue(alignFrame.getViewport().getColumnSelection().getHiddenColumns() + assertTrue(alignFrame.getViewport().getAlignment().getHiddenColumns() + .getListOfCols() .isEmpty()); assertFalse(alignFrame.hideFeatureColumns("exon", false)); assertTrue(alignFrame.getViewport().getColumnSelection().isEmpty()); - assertTrue(alignFrame.getViewport().getColumnSelection().getHiddenColumns() + assertTrue(alignFrame.getViewport().getAlignment().getHiddenColumns() + .getListOfCols() .isEmpty()); /* @@ -97,8 +99,9 @@ public class AlignFrameTest */ assertFalse(alignFrame.hideFeatureColumns("Metal", true)); assertTrue(alignFrame.getViewport().getColumnSelection().isEmpty()); - List hidden = alignFrame.getViewport().getColumnSelection() - .getHiddenColumns(); + List hidden = alignFrame.getViewport().getAlignment() + .getHiddenColumns() + .getListOfCols(); assertTrue(hidden.isEmpty()); /* @@ -107,7 +110,8 @@ public class AlignFrameTest * [1-3], [6-8] base zero */ assertTrue(alignFrame.hideFeatureColumns("Turn", true)); - hidden = alignFrame.getViewport().getColumnSelection().getHiddenColumns(); + hidden = alignFrame.getViewport().getAlignment().getHiddenColumns() + .getListOfCols(); assertEquals(hidden.size(), 2); assertEquals(hidden.get(0)[0], 1); assertEquals(hidden.get(0)[1], 3); diff --git a/test/jalview/io/AnnotationFileIOTest.java b/test/jalview/io/AnnotationFileIOTest.java index 885c673..c3a1801 100644 --- a/test/jalview/io/AnnotationFileIOTest.java +++ b/test/jalview/io/AnnotationFileIOTest.java @@ -24,7 +24,7 @@ import static org.testng.AssertJUnit.assertNotNull; import static org.testng.AssertJUnit.assertTrue; import jalview.datamodel.AlignmentI; -import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.gui.JvOptionPane; import jalview.io.AnnotationFile.ViewDef; @@ -115,7 +115,7 @@ public class AnnotationFileIOTest try { AlignmentI al = readAlignmentFile(f); - ColumnSelection cs = new ColumnSelection(); + HiddenColumns cs = new HiddenColumns(); assertTrue( "Test " + testname diff --git a/test/jalview/io/JSONFileTest.java b/test/jalview/io/JSONFileTest.java index a8611cc..957343b 100644 --- a/test/jalview/io/JSONFileTest.java +++ b/test/jalview/io/JSONFileTest.java @@ -27,7 +27,7 @@ import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; import jalview.datamodel.Annotation; -import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceGroup; @@ -78,7 +78,7 @@ public class JSONFileTest private HashMap expectedGrps = new HashMap(); - private ColumnSelection expectedColSel = new ColumnSelection(); + private HiddenColumns expectedColSel = new HiddenColumns(); private SequenceI[] expectedHiddenSeqs = new SequenceI[1]; @@ -191,7 +191,7 @@ public class JSONFileTest TEST_SEQ_HEIGHT = expectedSeqs.size(); TEST_GRP_HEIGHT = expectedGrps.size(); TEST_ANOT_HEIGHT = expectedAnnots.size(); - TEST_CS_HEIGHT = expectedColSel.getHiddenColumns().size(); + TEST_CS_HEIGHT = expectedColSel.getListOfCols().size(); AlignExportSettingI exportSettings = new AlignExportSettingI() { @@ -240,7 +240,7 @@ public class JSONFileTest jf = (JSONFile) formatAdapter.getAlignFile(); AlignFrame af = new AlignFrame(alignment, jf.getHiddenSequences(), - jf.getColumnSelection(), AlignFrame.DEFAULT_WIDTH, + jf.getHiddenColumns(), AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT); af.getViewport().setShowSequenceFeatures(jf.isShowSeqFeatures()); String colourSchemeName = jf.getGlobalColourScheme(); @@ -309,13 +309,13 @@ public class JSONFileTest @Test(groups = { "Functional" }) public void hiddenColsTest() { - ColumnSelection cs = testJsonFile.getColumnSelection(); + HiddenColumns cs = testJsonFile.getHiddenColumns(); Assert.assertNotNull(cs); - Assert.assertNotNull(cs.getHiddenColumns()); - List hiddenCols = cs.getHiddenColumns(); + Assert.assertNotNull(cs.getListOfCols()); + List hiddenCols = cs.getListOfCols(); Assert.assertEquals(hiddenCols.size(), TEST_CS_HEIGHT); Assert.assertEquals(hiddenCols.get(0), expectedColSel - .getHiddenColumns().get(0), + .getListOfCols().get(0), "Mismatched hidden columns!"); } diff --git a/test/jalview/structures/models/AAStructureBindingModelTest.java b/test/jalview/structures/models/AAStructureBindingModelTest.java index 7ba22b4..a7e483e 100644 --- a/test/jalview/structures/models/AAStructureBindingModelTest.java +++ b/test/jalview/structures/models/AAStructureBindingModelTest.java @@ -29,7 +29,7 @@ import jalview.api.FeatureRenderer; import jalview.api.SequenceRenderer; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentI; -import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.PDBEntry; import jalview.datamodel.PDBEntry.Type; import jalview.datamodel.Sequence; @@ -171,7 +171,7 @@ public class AAStructureBindingModelTest @Override public String superposeStructures(AlignmentI[] als, int[] alm, - ColumnSelection[] alc) + HiddenColumns[] alc) { return null; } diff --git a/test/jalview/util/MappingUtilsTest.java b/test/jalview/util/MappingUtilsTest.java index b84e770..78a867e 100644 --- a/test/jalview/util/MappingUtilsTest.java +++ b/test/jalview/util/MappingUtilsTest.java @@ -887,11 +887,11 @@ public class MappingUtilsTest * 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); + proteinSelection.hideSelectedColumns(0); ColumnSelection dnaSelection = MappingUtils.mapColumnSelection( proteinSelection, proteinView, dnaView); assertEquals("[]", dnaSelection.getSelected().toString()); - List hidden = dnaSelection.getHiddenColumns(); + List hidden = dnaSelection.getListOfCols(); assertEquals(1, hidden.size()); assertEquals("[0, 4]", Arrays.toString(hidden.get(0))); @@ -903,10 +903,10 @@ public class MappingUtilsTest assertEquals("[0]", proteinSelection.getSelected().toString()); // deselect these or hideColumns will be expanded to include 0 proteinSelection.clear(); - proteinSelection.hideColumns(1); + proteinSelection.hideSelectedColumns(1); dnaSelection = MappingUtils.mapColumnSelection(proteinSelection, proteinView, dnaView); - hidden = dnaSelection.getHiddenColumns(); + hidden = dnaSelection.getListOfCols(); assertEquals(1, hidden.size()); assertEquals("[0, 3]", Arrays.toString(hidden.get(0))); @@ -915,10 +915,10 @@ public class MappingUtilsTest */ proteinSelection.revealAllHiddenColumns(); proteinSelection.clear(); - proteinSelection.hideColumns(2); + proteinSelection.hideSelectedColumns(2); dnaSelection = MappingUtils.mapColumnSelection(proteinSelection, proteinView, dnaView); - assertTrue(dnaSelection.getHiddenColumns().isEmpty()); + assertTrue(dnaSelection.getListOfCols().isEmpty()); /* * Column 3 in protein picks up Seq1/P, Seq2/Q, Seq3/S which map to columns @@ -926,12 +926,12 @@ public class MappingUtilsTest */ proteinSelection.revealAllHiddenColumns(); proteinSelection.clear(); - proteinSelection.hideColumns(3); // 5-10 hidden in dna + proteinSelection.hideSelectedColumns(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(); + hidden = dnaSelection.getListOfCols(); assertEquals(1, hidden.size()); assertEquals("[5, 10]", Arrays.toString(hidden.get(0))); @@ -940,11 +940,11 @@ public class MappingUtilsTest */ proteinSelection.revealAllHiddenColumns(); proteinSelection.clear(); - proteinSelection.hideColumns(1); - proteinSelection.hideColumns(3); + proteinSelection.hideSelectedColumns(1); + proteinSelection.hideSelectedColumns(3); dnaSelection = MappingUtils.mapColumnSelection(proteinSelection, proteinView, dnaView); - hidden = dnaSelection.getHiddenColumns(); + hidden = dnaSelection.getListOfCols(); assertEquals(2, hidden.size()); assertEquals("[0, 3]", Arrays.toString(hidden.get(0))); assertEquals("[5, 10]", Arrays.toString(hidden.get(1))); diff --git a/test/jalview/viewmodel/OverviewDimensionsTest.java b/test/jalview/viewmodel/OverviewDimensionsTest.java index 398fec3..57aa60b 100644 --- a/test/jalview/viewmodel/OverviewDimensionsTest.java +++ b/test/jalview/viewmodel/OverviewDimensionsTest.java @@ -26,6 +26,7 @@ import jalview.analysis.AlignmentGenerator; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentI; import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceCollectionI; import jalview.datamodel.SequenceGroup; @@ -56,7 +57,7 @@ public class OverviewDimensionsTest Hashtable hiddenRepSequences = new Hashtable(); - ColumnSelection hiddenCols = new ColumnSelection(); + HiddenColumns hiddenCols = new HiddenColumns(); @BeforeClass(alwaysRun = true) public void setUpJvOptionPane() @@ -73,7 +74,8 @@ public class OverviewDimensionsTest { al.getHiddenSequences().showAll(hiddenRepSequences); } - hiddenCols.revealAllHiddenColumns(); + ColumnSelection colsel = new ColumnSelection(); + hiddenCols.revealAllHiddenColumns(colsel); vpranges = new ViewportRanges(al); vpranges.setStartRes(0); @@ -84,7 +86,7 @@ public class OverviewDimensionsTest viewHeight = vpranges.getEndSeq() - vpranges.getStartSeq() + 1; viewWidth = vpranges.getEndRes() - vpranges.getStartRes() + 1; - ColumnSelection hiddenCols = new ColumnSelection(); + HiddenColumns hiddenCols = new HiddenColumns(); od = new OverviewDimensions(vpranges, true); // Initial box sizing - default path through code -- 1.7.10.2