From: kiramt Date: Tue, 21 Nov 2017 10:28:27 +0000 (+0000) Subject: JAL-2759 Remove getVisibleBlocksIterator call X-Git-Tag: Release_2_10_4~55^2~1^2~59 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=39267ff67b3f5cabdf20ea468b9e86739223adf5;p=jalview.git JAL-2759 Remove getVisibleBlocksIterator call --- diff --git a/src/jalview/appletgui/SeqCanvas.java b/src/jalview/appletgui/SeqCanvas.java index 2c90047..076b0a3 100755 --- a/src/jalview/appletgui/SeqCanvas.java +++ b/src/jalview/appletgui/SeqCanvas.java @@ -566,7 +566,7 @@ public class SeqCanvas extends Panel implements ViewportListenerI HiddenColumns hidden = av.getAlignment().getHiddenColumns(); VisibleContigsIterator regions = (VisibleContigsIterator) hidden - .getVisibleBlocksIterator(startRes, endRes, true); + .getVisContigsIterator(startRes, endRes, true); while (regions.hasNext()) { diff --git a/src/jalview/datamodel/HiddenColumns.java b/src/jalview/datamodel/HiddenColumns.java index a81d3bd..5ac0abb 100644 --- a/src/jalview/datamodel/HiddenColumns.java +++ b/src/jalview/datamodel/HiddenColumns.java @@ -26,6 +26,28 @@ import java.util.Iterator; import java.util.List; import java.util.concurrent.locks.ReentrantReadWriteLock; +/** + * This class manages the collection of hidden columns associated with an + * alignment. To iterate over the collection, or over visible columns/regions, + * use an iterator obtained from one of: + * + * - getBoundedIterator: iterate over the hidden regions, within some bounds + * + * - getBoundedStartIterator: iterate over the start positions of hidden + * regions, within some bounds + * + * - getVisContigsIterator: iterate over visible regions in a range, returning + * absolute positions + * + * - getVisibleBlocksIterator + * + * - getVisibleColsIterator: iterate over the visible *columns* + * + * For performance reasons, provide bounds where possible. + * + * @author kmourao + * + */ public class HiddenColumns { private static final int HASH_MULTIPLIER = 31; @@ -1466,35 +1488,14 @@ public class HiddenColumns * boundaries * * @param start - * first column, inclusive from 0, absolute value + * first column, inclusive from 0 * @param end - * last column - not inclusive, absolute value - */ - public Iterator getVisContigsIterator(int start, int end) - { - try - { - LOCK.readLock().lock(); - return new VisibleContigsIterator(start, end, hiddenColumns); - } finally - { - LOCK.readLock().unlock(); - } - } - - /** - * return an iterator over visible segments between the given start and end - * boundaries - * - * @param start - * (first column - inclusive from 0) - * @param end - * (last column - inclusive) + * last column - not inclusive * @param useVisibleCoords * if true, start and end are visible column positions, not absolute - * positions + * positions* */ - public Iterator getVisibleBlocksIterator(int start, int end, + public Iterator getVisContigsIterator(int start, int end, boolean useVisibleCoords) { int adjstart = start; @@ -1508,9 +1509,7 @@ public class HiddenColumns try { LOCK.readLock().lock(); - - return new VisibleContigsIterator(adjstart, adjend + 1, - hiddenColumns); + return new VisibleContigsIterator(adjstart, adjend, hiddenColumns); } finally { LOCK.readLock().unlock(); diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index 0e93da9..7e77bec 100644 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -463,7 +463,8 @@ public class AlignViewport extends AlignmentViewport { end = alignment.getWidth(); } - return (alignment.getHiddenColumns().getVisContigsIterator(start, end)); + return (alignment.getHiddenColumns().getVisContigsIterator(start, end, + false)); } /** diff --git a/src/jalview/gui/SeqCanvas.java b/src/jalview/gui/SeqCanvas.java index 10c60c1..5c5fbbe 100755 --- a/src/jalview/gui/SeqCanvas.java +++ b/src/jalview/gui/SeqCanvas.java @@ -1031,7 +1031,7 @@ public class SeqCanvas extends JComponent implements ViewportListenerI HiddenColumns hidden = av.getAlignment().getHiddenColumns(); VisibleContigsIterator regions = (VisibleContigsIterator) hidden - .getVisibleBlocksIterator(startRes, endRes, true); + .getVisContigsIterator(startRes, endRes, true); while (regions.hasNext()) { @@ -1365,7 +1365,7 @@ public class SeqCanvas extends JComponent implements ViewportListenerI HiddenColumns hidden = av.getAlignment().getHiddenColumns(); VisibleContigsIterator regions = (VisibleContigsIterator) hidden - .getVisibleBlocksIterator(startRes, endRes, true); + .getVisContigsIterator(startRes, endRes, true); while (regions.hasNext()) { int[] region = regions.next(); diff --git a/src/jalview/gui/VamsasApplication.java b/src/jalview/gui/VamsasApplication.java index ac72e93..973cfe8 100644 --- a/src/jalview/gui/VamsasApplication.java +++ b/src/jalview/gui/VamsasApplication.java @@ -1076,7 +1076,7 @@ public class VamsasApplication implements SelectionSource, VamsasSource { Iterator intervals = hidden .getVisContigsIterator(seqsel.getStartRes(), - seqsel.getEndRes() + 1); + seqsel.getEndRes() + 1, false); while (intervals.hasNext()) { int[] region = intervals.next(); diff --git a/test/jalview/analysis/DnaTest.java b/test/jalview/analysis/DnaTest.java index 1ed846a..6a31b31 100644 --- a/test/jalview/analysis/DnaTest.java +++ b/test/jalview/analysis/DnaTest.java @@ -136,7 +136,8 @@ public class DnaTest FileFormat.Fasta); HiddenColumns cs = new HiddenColumns(); AlignViewportI av = new AlignViewport(alf, cs); - Iterator contigs = cs.getVisContigsIterator(0, alf.getWidth()); + Iterator contigs = cs.getVisContigsIterator(0, alf.getWidth(), + false); Dna dna = new Dna(av, contigs); AlignmentI translated = dna.translateCdna(); assertNotNull("Couldn't do a full width translation of test data.", @@ -166,7 +167,7 @@ public class DnaTest } cs.hideColumns(ipos + vwidth, alf.getWidth()); Iterator vcontigs = cs.getVisContigsIterator(0, - alf.getWidth()); + alf.getWidth(), false); AlignViewportI av = new AlignViewport(alf, cs); Dna dna = new Dna(av, vcontigs); AlignmentI transAlf = dna.translateCdna(); @@ -193,7 +194,8 @@ public class DnaTest DataSourceType.PASTE, FileFormat.Fasta); HiddenColumns cs = new HiddenColumns(); AlignViewportI av = new AlignViewport(alf, cs); - Iterator contigs = cs.getVisContigsIterator(0, alf.getWidth()); + Iterator contigs = cs.getVisContigsIterator(0, alf.getWidth(), + false); Dna dna = new Dna(av, contigs); AlignmentI translated = dna.translateCdna(); String aa = translated.getSequenceAt(0).getSequenceAsString(); @@ -217,7 +219,8 @@ public class DnaTest cs.hideColumns(24, 35); // hide codons 9-12 cs.hideColumns(177, 191); // hide codons 60-64 AlignViewportI av = new AlignViewport(alf, cs); - Iterator contigs = cs.getVisContigsIterator(0, alf.getWidth()); + Iterator contigs = cs.getVisContigsIterator(0, alf.getWidth(), + false); Dna dna = new Dna(av, contigs); AlignmentI translated = dna.translateCdna(); String aa = translated.getSequenceAt(0).getSequenceAsString(); @@ -303,7 +306,8 @@ public class DnaTest .generate(12, 8, 97, 5, 5); HiddenColumns cs = new HiddenColumns(); AlignViewportI av = new AlignViewport(cdna, cs); - Iterator contigs = cs.getVisContigsIterator(0, cdna.getWidth()); + Iterator contigs = cs.getVisContigsIterator(0, cdna.getWidth(), + false); Dna dna = new Dna(av, contigs); AlignmentI translated = dna.translateCdna(); @@ -319,7 +323,7 @@ public class DnaTest } AlignmentI cdnaReordered = new Alignment(sorted); av = new AlignViewport(cdnaReordered, cs); - contigs = cs.getVisContigsIterator(0, cdna.getWidth()); + contigs = cs.getVisContigsIterator(0, cdna.getWidth(), false); dna = new Dna(av, contigs); AlignmentI translated2 = dna.translateCdna(); @@ -551,7 +555,8 @@ public class DnaTest HiddenColumns cs = new HiddenColumns(); AlignViewportI av = new AlignViewport(al, cs); - Iterator contigs = cs.getVisContigsIterator(0, al.getWidth()); + Iterator contigs = cs.getVisContigsIterator(0, al.getWidth(), + false); Dna testee = new Dna(av, contigs); AlignmentI reversed = testee.reverseCdna(false); assertEquals(1, reversed.getHeight()); diff --git a/test/jalview/datamodel/HiddenColumnsTest.java b/test/jalview/datamodel/HiddenColumnsTest.java index 57d716d..e66367b 100644 --- a/test/jalview/datamodel/HiddenColumnsTest.java +++ b/test/jalview/datamodel/HiddenColumnsTest.java @@ -119,7 +119,7 @@ public class HiddenColumnsTest { HiddenColumns cs = new HiddenColumns(); - Iterator visible = cs.getVisContigsIterator(3, 10); + Iterator visible = cs.getVisContigsIterator(3, 10, false); int[] region = visible.next(); assertEquals("[3, 9]", Arrays.toString(region)); assertFalse(visible.hasNext()); @@ -131,7 +131,7 @@ public class HiddenColumnsTest // Test both ends visible region // start position is inclusive, end position exclusive - visible = cs.getVisContigsIterator(1, 13); + visible = cs.getVisContigsIterator(1, 13, false); region = visible.next(); assertEquals("[1, 2]", Arrays.toString(region)); region = visible.next(); @@ -141,7 +141,7 @@ public class HiddenColumnsTest assertFalse(visible.hasNext()); // Test start hidden, end visible - visible = cs.getVisContigsIterator(4, 14); + visible = cs.getVisContigsIterator(4, 14, false); region = visible.next(); assertEquals("[7, 7]", Arrays.toString(region)); region = visible.next(); @@ -151,13 +151,13 @@ public class HiddenColumnsTest assertFalse(visible.hasNext()); // Test start hidden, end hidden - visible = cs.getVisContigsIterator(3, 10); + visible = cs.getVisContigsIterator(3, 10, false); region = visible.next(); assertEquals("[7, 7]", Arrays.toString(region)); assertFalse(visible.hasNext()); // Test start visible, end hidden - visible = cs.getVisContigsIterator(0, 13); + visible = cs.getVisContigsIterator(0, 13, false); region = visible.next(); assertEquals("[0, 2]", Arrays.toString(region)); region = visible.next(); @@ -167,7 +167,7 @@ public class HiddenColumnsTest assertFalse(visible.hasNext()); // Test empty result - visible = cs.getVisContigsIterator(4, 6); + visible = cs.getVisContigsIterator(4, 6, false); assertFalse(visible.hasNext()); } @@ -796,7 +796,7 @@ public class HiddenColumnsTest false); // confirm that original contigs are as expected - Iterator visible = hidden.getVisContigsIterator(0, 25); + Iterator visible = hidden.getVisContigsIterator(0, 25, false); int[] region = visible.next(); assertEquals("[0, 14]", Arrays.toString(region)); region = visible.next(); @@ -807,7 +807,7 @@ public class HiddenColumnsTest view); // confirm that the contigs have changed to account for the gaps - visible = result.getVisContigsIterator(0, 25); + visible = result.getVisContigsIterator(0, 25, false); region = visible.next(); assertEquals("[0, 10]", Arrays.toString(region)); region = visible.next(); @@ -854,7 +854,7 @@ public class HiddenColumnsTest false); // confirm that original contigs are as expected - Iterator visible = hidden.getVisContigsIterator(0, 20); + Iterator visible = hidden.getVisContigsIterator(0, 20, false); int[] region = visible.next(); assertEquals("[0, 6]", Arrays.toString(region)); region = visible.next(); @@ -866,7 +866,7 @@ public class HiddenColumnsTest view); // confirm that the contigs have changed to account for the gaps - visible = result.getVisContigsIterator(0, 20); + visible = result.getVisContigsIterator(0, 20, false); region = visible.next(); assertEquals("[0, 4]", Arrays.toString(region)); region = visible.next(); @@ -1322,7 +1322,7 @@ public class HiddenColumnsTest public void testVisibleBlocksVisBoundsIterator() { HiddenColumns h = new HiddenColumns(); - Iterator regions = h.getVisibleBlocksIterator(0, 30, true); + Iterator regions = h.getVisContigsIterator(0, 30, true); // only 1 visible region spanning 0-30 if nothing is hidden assertTrue(regions.hasNext()); @@ -1335,7 +1335,7 @@ public class HiddenColumnsTest // 2 regions one on either side // second region boundary accounts for hidden columns h.hideColumns(10, 15); - regions = h.getVisibleBlocksIterator(0, 30, true); + regions = h.getVisContigsIterator(0, 30, true); assertTrue(regions.hasNext()); region = regions.next(); @@ -1349,7 +1349,7 @@ public class HiddenColumnsTest // single hidden region at left h = new HiddenColumns(); h.hideColumns(0, 5); - regions = h.getVisibleBlocksIterator(0, 30, true); + regions = h.getVisContigsIterator(0, 30, true); assertTrue(regions.hasNext()); region = regions.next(); @@ -1360,7 +1360,7 @@ public class HiddenColumnsTest // single hidden region at right h = new HiddenColumns(); h.hideColumns(27, 30); - regions = h.getVisibleBlocksIterator(0, 30, true); + regions = h.getVisContigsIterator(0, 30, true); assertTrue(regions.hasNext()); region = regions.next(); @@ -1375,7 +1375,7 @@ public class HiddenColumnsTest h = new HiddenColumns(); h.hideColumns(0, 5); h.hideColumns(23, 25); - regions = h.getVisibleBlocksIterator(0, 30, true); + regions = h.getVisContigsIterator(0, 30, true); assertTrue(regions.hasNext()); region = regions.next(); @@ -1390,7 +1390,7 @@ public class HiddenColumnsTest h = new HiddenColumns(); h.hideColumns(27, 30); h.hideColumns(11, 14); - regions = h.getVisibleBlocksIterator(0, 30, true); + regions = h.getVisContigsIterator(0, 30, true); assertTrue(regions.hasNext()); region = regions.next(); @@ -1408,7 +1408,7 @@ public class HiddenColumnsTest h = new HiddenColumns(); h.hideColumns(27, 35); h.hideColumns(0, 4); - regions = h.getVisibleBlocksIterator(0, 30, true); + regions = h.getVisContigsIterator(0, 30, true); assertTrue(regions.hasNext()); region = regions.next(); @@ -1426,7 +1426,7 @@ public class HiddenColumnsTest h.hideColumns(9, 11); h.hideColumns(22, 26); - regions = h.getVisibleBlocksIterator(0, 30, true); + regions = h.getVisContigsIterator(0, 30, true); assertTrue(regions.hasNext()); region = regions.next();