From: kiramt Date: Fri, 21 Apr 2017 09:03:37 +0000 (+0100) Subject: JAL-2388 Alignment col and row collections with iterators X-Git-Tag: Release_2_10_2~3^2~92^2~18 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=7dfc6aec87248b15f6a01c5eb1584f39f21d4233;p=jalview.git JAL-2388 Alignment col and row collections with iterators --- diff --git a/src/jalview/api/AlignmentColsCollectionI.java b/src/jalview/api/AlignmentColsCollectionI.java new file mode 100644 index 0000000..603da98 --- /dev/null +++ b/src/jalview/api/AlignmentColsCollectionI.java @@ -0,0 +1,13 @@ +package jalview.api; + +public interface AlignmentColsCollectionI extends Iterable +{ + /** + * Answers if the column at the given position is hidden. + * + * @param c + * the column index to check + * @return true if the column at the position is hidden + */ + public boolean isHidden(int c); +} diff --git a/src/jalview/api/AlignmentRowsCollectionI.java b/src/jalview/api/AlignmentRowsCollectionI.java new file mode 100644 index 0000000..09b039d --- /dev/null +++ b/src/jalview/api/AlignmentRowsCollectionI.java @@ -0,0 +1,24 @@ +package jalview.api; + +import jalview.datamodel.SequenceI; + +public interface AlignmentRowsCollectionI extends Iterable +{ + /** + * Answers if the sequence at the given position is hidden. + * + * @param r + * the row index to check + * @return true if the sequence at r is hidden + */ + public boolean isHidden(int r); + + /** + * Answers the sequence at the given position in the alignment + * + * @param r + * the row index to locate + * @return the sequence + */ + public SequenceI getSequence(int r); +} diff --git a/src/jalview/datamodel/AlignmentColsCollection.java b/src/jalview/datamodel/AllColsCollection.java similarity index 84% rename from src/jalview/datamodel/AlignmentColsCollection.java rename to src/jalview/datamodel/AllColsCollection.java index 3a9f598..1b1a5dd 100644 --- a/src/jalview/datamodel/AlignmentColsCollection.java +++ b/src/jalview/datamodel/AllColsCollection.java @@ -20,15 +20,17 @@ */ package jalview.datamodel; +import jalview.api.AlignmentColsCollectionI; + import java.util.Iterator; -public class AlignmentColsCollection implements Iterable +public class AllColsCollection implements AlignmentColsCollectionI { int start; int end; ColumnSelection hidden; - public AlignmentColsCollection(int s, int e, ColumnSelection colsel) + public AllColsCollection(int s, int e, ColumnSelection colsel) { start = s; end = e; @@ -40,10 +42,8 @@ public class AlignmentColsCollection implements Iterable { return new AllColsIterator(start,end,hidden); } - - /** - * Answers if the column at the the current position is hidden. - */ + + @Override public boolean isHidden(int c) { return !hidden.isVisible(c); diff --git a/src/jalview/datamodel/AllColsIterator.java b/src/jalview/datamodel/AllColsIterator.java index 4e1ff2e..67d7ba5 100644 --- a/src/jalview/datamodel/AllColsIterator.java +++ b/src/jalview/datamodel/AllColsIterator.java @@ -38,15 +38,12 @@ public class AllColsIterator implements Iterator private int current; - ColumnSelection hidden; - public AllColsIterator(int firstcol, int lastcol, ColumnSelection hiddenCols) { last = lastcol; next = firstcol; current = firstcol; - hidden = hiddenCols; } @Override diff --git a/src/jalview/datamodel/AlignmentRowsCollection.java b/src/jalview/datamodel/AllRowsCollection.java similarity index 87% rename from src/jalview/datamodel/AlignmentRowsCollection.java rename to src/jalview/datamodel/AllRowsCollection.java index e22d8fc..502ace4 100644 --- a/src/jalview/datamodel/AlignmentRowsCollection.java +++ b/src/jalview/datamodel/AllRowsCollection.java @@ -20,9 +20,11 @@ */ package jalview.datamodel; +import jalview.api.AlignmentRowsCollectionI; + import java.util.Iterator; -public class AlignmentRowsCollection implements Iterable +public class AllRowsCollection implements AlignmentRowsCollectionI { int start; @@ -32,7 +34,7 @@ public class AlignmentRowsCollection implements Iterable HiddenSequences hidden; - public AlignmentRowsCollection(int s, int e, AlignmentI al) + public AllRowsCollection(int s, int e, AlignmentI al) { start = s; end = e; @@ -46,14 +48,13 @@ public class AlignmentRowsCollection implements Iterable return new AllRowsIterator(start, end, alignment); } - /** - * Answers if the sequence at the position is hidden. - */ + @Override public boolean isHidden(int seq) { return hidden.isHidden(seq); } + @Override public SequenceI getSequence(int seq) { return alignment.getSequenceAtAbsoluteIndex(seq); diff --git a/src/jalview/datamodel/VisibleColsCollection.java b/src/jalview/datamodel/VisibleColsCollection.java new file mode 100644 index 0000000..aabd603 --- /dev/null +++ b/src/jalview/datamodel/VisibleColsCollection.java @@ -0,0 +1,53 @@ +/* + * 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 jalview.api.AlignmentColsCollectionI; + +import java.util.Iterator; + +public class VisibleColsCollection implements AlignmentColsCollectionI +{ + int start; + int end; + + ColumnSelection hidden; + + public VisibleColsCollection(int s, int e, ColumnSelection colsel) + { + start = s; + end = e; + hidden = colsel; + } + + @Override + public Iterator iterator() + { + return new VisibleColsIterator(start, end, hidden); + } + + @Override + public boolean isHidden(int c) + { + return false; + } + +} diff --git a/src/jalview/datamodel/VisibleRowsCollection.java b/src/jalview/datamodel/VisibleRowsCollection.java new file mode 100644 index 0000000..98153f9 --- /dev/null +++ b/src/jalview/datamodel/VisibleRowsCollection.java @@ -0,0 +1,60 @@ +/* + * 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 jalview.api.AlignmentRowsCollectionI; + +import java.util.Iterator; + +public class VisibleRowsCollection implements AlignmentRowsCollectionI +{ + int start; + + int end; + + AlignmentI alignment; + + public VisibleRowsCollection(int s, int e, AlignmentI al) + { + start = s; + end = e; + alignment = al; + } + + @Override + public Iterator iterator() + { + return new VisibleRowsIterator(start, end, alignment); + } + + @Override + public boolean isHidden(int seq) + { + return false; + } + + @Override + public SequenceI getSequence(int seq) + { + return alignment.getSequenceAt(seq); + } +} + diff --git a/src/jalview/gui/OverviewRenderer.java b/src/jalview/gui/OverviewRenderer.java index 87937ba..566846a 100644 --- a/src/jalview/gui/OverviewRenderer.java +++ b/src/jalview/gui/OverviewRenderer.java @@ -20,9 +20,9 @@ */ package jalview.gui; +import jalview.api.AlignmentColsCollectionI; +import jalview.api.AlignmentRowsCollectionI; import jalview.datamodel.AlignmentAnnotation; -import jalview.datamodel.AlignmentColsCollection; -import jalview.datamodel.AlignmentRowsCollection; import jalview.datamodel.Annotation; import jalview.datamodel.SequenceI; import jalview.renderer.seqfeatures.FeatureColourFinder; @@ -68,8 +68,8 @@ public class OverviewRenderer * Iterator over columns to be drawn * @return image containing the drawing */ - public BufferedImage draw(AlignmentRowsCollection rows, - AlignmentColsCollection cols) + public BufferedImage draw(AlignmentRowsCollectionI rows, + AlignmentColsCollectionI cols) { int rgbcolor = Color.white.getRGB(); int seqIndex = 0; @@ -137,7 +137,7 @@ public class OverviewRenderer } public void drawGraph(Graphics g, AlignmentAnnotation _aa, int charWidth, - int y, AlignmentColsCollection cols) + int y, AlignmentColsCollectionI cols) { Annotation[] aa_annotations = _aa.annotations; g.setColor(Color.white); diff --git a/src/jalview/viewmodel/OverviewDimensions.java b/src/jalview/viewmodel/OverviewDimensions.java index 50e1210..59ee5c7 100644 --- a/src/jalview/viewmodel/OverviewDimensions.java +++ b/src/jalview/viewmodel/OverviewDimensions.java @@ -1,8 +1,8 @@ package jalview.viewmodel; -import jalview.datamodel.AlignmentColsCollection; +import jalview.api.AlignmentColsCollectionI; +import jalview.api.AlignmentRowsCollectionI; import jalview.datamodel.AlignmentI; -import jalview.datamodel.AlignmentRowsCollection; import jalview.datamodel.ColumnSelection; import jalview.datamodel.HiddenSequences; @@ -141,10 +141,10 @@ public abstract class OverviewDimensions public abstract void setBoxPosition(HiddenSequences hiddenSeqs, ColumnSelection hiddenCols, ViewportRanges ranges); - public abstract AlignmentColsCollection getColumns( + public abstract AlignmentColsCollectionI getColumns( ViewportRanges ranges, ColumnSelection hiddenCols); - public abstract AlignmentRowsCollection getRows( + public abstract AlignmentRowsCollectionI getRows( ViewportRanges ranges, AlignmentI al); public abstract float getPixelsPerCol(); diff --git a/src/jalview/viewmodel/OverviewDimensionsAllVisible.java b/src/jalview/viewmodel/OverviewDimensionsAllVisible.java index 21f0be6..02f3e17 100644 --- a/src/jalview/viewmodel/OverviewDimensionsAllVisible.java +++ b/src/jalview/viewmodel/OverviewDimensionsAllVisible.java @@ -1,8 +1,10 @@ package jalview.viewmodel; -import jalview.datamodel.AlignmentColsCollection; +import jalview.api.AlignmentColsCollectionI; +import jalview.api.AlignmentRowsCollectionI; import jalview.datamodel.AlignmentI; -import jalview.datamodel.AlignmentRowsCollection; +import jalview.datamodel.AllColsCollection; +import jalview.datamodel.AllRowsCollection; import jalview.datamodel.ColumnSelection; import jalview.datamodel.HiddenSequences; @@ -136,18 +138,18 @@ public class OverviewDimensionsAllVisible extends OverviewDimensions } @Override - public AlignmentColsCollection getColumns(ViewportRanges ranges, + public AlignmentColsCollectionI getColumns(ViewportRanges ranges, ColumnSelection hiddenCols) { - return new AlignmentColsCollection(0, + return new AllColsCollection(0, ranges.getVisibleAlignmentWidth() - 1, hiddenCols); } @Override - public AlignmentRowsCollection getRows(ViewportRanges ranges, + public AlignmentRowsCollectionI getRows(ViewportRanges ranges, AlignmentI al) { - return new AlignmentRowsCollection(0, + return new AllRowsCollection(0, ranges.getVisibleAlignmentHeight() - 1, al); } diff --git a/src/jalview/viewmodel/OverviewDimensionsWithHidden.java b/src/jalview/viewmodel/OverviewDimensionsWithHidden.java index 575167a..63172bf 100644 --- a/src/jalview/viewmodel/OverviewDimensionsWithHidden.java +++ b/src/jalview/viewmodel/OverviewDimensionsWithHidden.java @@ -20,9 +20,11 @@ */ package jalview.viewmodel; -import jalview.datamodel.AlignmentColsCollection; +import jalview.api.AlignmentColsCollectionI; +import jalview.api.AlignmentRowsCollectionI; import jalview.datamodel.AlignmentI; -import jalview.datamodel.AlignmentRowsCollection; +import jalview.datamodel.AllColsCollection; +import jalview.datamodel.AllRowsCollection; import jalview.datamodel.ColumnSelection; import jalview.datamodel.HiddenSequences; @@ -208,19 +210,19 @@ public class OverviewDimensionsWithHidden extends OverviewDimensions } @Override - public AlignmentColsCollection getColumns(ViewportRanges ranges, + public AlignmentColsCollectionI getColumns(ViewportRanges ranges, ColumnSelection hiddenCols) { - return new AlignmentColsCollection(0, + return new AllColsCollection(0, ranges.getAbsoluteAlignmentWidth() - 1, hiddenCols); } @Override - public AlignmentRowsCollection getRows(ViewportRanges ranges, + public AlignmentRowsCollectionI getRows(ViewportRanges ranges, AlignmentI al) { - return new AlignmentRowsCollection(0, + return new AllRowsCollection(0, ranges.getAbsoluteAlignmentHeight() - 1, al); } diff --git a/test/jalview/datamodel/VisibleColsIteratorTest.java b/test/jalview/datamodel/VisibleColsIteratorTest.java index c07b3c9..d908b78 100644 --- a/test/jalview/datamodel/VisibleColsIteratorTest.java +++ b/test/jalview/datamodel/VisibleColsIteratorTest.java @@ -33,7 +33,7 @@ public class VisibleColsIteratorTest ColumnSelection hiddenColsAtStart; - @BeforeClass + @BeforeClass(groups = { "Functional" }) public void setup() { hiddenCols = new ColumnSelection(); diff --git a/test/jalview/datamodel/VisibleRowsIteratorTest.java b/test/jalview/datamodel/VisibleRowsIteratorTest.java index da93dab..4a021c5 100644 --- a/test/jalview/datamodel/VisibleRowsIteratorTest.java +++ b/test/jalview/datamodel/VisibleRowsIteratorTest.java @@ -42,7 +42,7 @@ public class VisibleRowsIteratorTest Hashtable hiddenRepSequences2 = new Hashtable(); - @BeforeClass + @BeforeClass(groups = { "Functional" }) public void setup() { // create random alignment