HiddenColumns hidden = av.getAlignment().getHiddenColumns();
VisibleContigsIterator regions = (VisibleContigsIterator) hidden
- .getVisibleBlocksIterator(startRes, endRes, true);
+ .getVisContigsIterator(startRes, endRes, true);
while (regions.hasNext())
{
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;
* 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<int[]> 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<int[]> getVisibleBlocksIterator(int start, int end,
+ public Iterator<int[]> getVisContigsIterator(int start, int end,
boolean useVisibleCoords)
{
int adjstart = start;
try
{
LOCK.readLock().lock();
-
- return new VisibleContigsIterator(adjstart, adjend + 1,
- hiddenColumns);
+ return new VisibleContigsIterator(adjstart, adjend, hiddenColumns);
} finally
{
LOCK.readLock().unlock();
{
end = alignment.getWidth();
}
- return (alignment.getHiddenColumns().getVisContigsIterator(start, end));
+ return (alignment.getHiddenColumns().getVisContigsIterator(start, end,
+ false));
}
/**
HiddenColumns hidden = av.getAlignment().getHiddenColumns();
VisibleContigsIterator regions = (VisibleContigsIterator) hidden
- .getVisibleBlocksIterator(startRes, endRes, true);
+ .getVisContigsIterator(startRes, endRes, true);
while (regions.hasNext())
{
HiddenColumns hidden = av.getAlignment().getHiddenColumns();
VisibleContigsIterator regions = (VisibleContigsIterator) hidden
- .getVisibleBlocksIterator(startRes, endRes, true);
+ .getVisContigsIterator(startRes, endRes, true);
while (regions.hasNext())
{
int[] region = regions.next();
{
Iterator<int[]> intervals = hidden
.getVisContigsIterator(seqsel.getStartRes(),
- seqsel.getEndRes() + 1);
+ seqsel.getEndRes() + 1, false);
while (intervals.hasNext())
{
int[] region = intervals.next();
FileFormat.Fasta);
HiddenColumns cs = new HiddenColumns();
AlignViewportI av = new AlignViewport(alf, cs);
- Iterator<int[]> contigs = cs.getVisContigsIterator(0, alf.getWidth());
+ Iterator<int[]> 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.",
}
cs.hideColumns(ipos + vwidth, alf.getWidth());
Iterator<int[]> 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();
DataSourceType.PASTE, FileFormat.Fasta);
HiddenColumns cs = new HiddenColumns();
AlignViewportI av = new AlignViewport(alf, cs);
- Iterator<int[]> contigs = cs.getVisContigsIterator(0, alf.getWidth());
+ Iterator<int[]> contigs = cs.getVisContigsIterator(0, alf.getWidth(),
+ false);
Dna dna = new Dna(av, contigs);
AlignmentI translated = dna.translateCdna();
String aa = translated.getSequenceAt(0).getSequenceAsString();
cs.hideColumns(24, 35); // hide codons 9-12
cs.hideColumns(177, 191); // hide codons 60-64
AlignViewportI av = new AlignViewport(alf, cs);
- Iterator<int[]> contigs = cs.getVisContigsIterator(0, alf.getWidth());
+ Iterator<int[]> contigs = cs.getVisContigsIterator(0, alf.getWidth(),
+ false);
Dna dna = new Dna(av, contigs);
AlignmentI translated = dna.translateCdna();
String aa = translated.getSequenceAt(0).getSequenceAsString();
.generate(12, 8, 97, 5, 5);
HiddenColumns cs = new HiddenColumns();
AlignViewportI av = new AlignViewport(cdna, cs);
- Iterator<int[]> contigs = cs.getVisContigsIterator(0, cdna.getWidth());
+ Iterator<int[]> contigs = cs.getVisContigsIterator(0, cdna.getWidth(),
+ false);
Dna dna = new Dna(av, contigs);
AlignmentI translated = dna.translateCdna();
}
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();
HiddenColumns cs = new HiddenColumns();
AlignViewportI av = new AlignViewport(al, cs);
- Iterator<int[]> contigs = cs.getVisContigsIterator(0, al.getWidth());
+ Iterator<int[]> contigs = cs.getVisContigsIterator(0, al.getWidth(),
+ false);
Dna testee = new Dna(av, contigs);
AlignmentI reversed = testee.reverseCdna(false);
assertEquals(1, reversed.getHeight());
{
HiddenColumns cs = new HiddenColumns();
- Iterator<int[]> visible = cs.getVisContigsIterator(3, 10);
+ Iterator<int[]> visible = cs.getVisContigsIterator(3, 10, false);
int[] region = visible.next();
assertEquals("[3, 9]", Arrays.toString(region));
assertFalse(visible.hasNext());
// 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();
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();
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();
assertFalse(visible.hasNext());
// Test empty result
- visible = cs.getVisContigsIterator(4, 6);
+ visible = cs.getVisContigsIterator(4, 6, false);
assertFalse(visible.hasNext());
}
false);
// confirm that original contigs are as expected
- Iterator<int[]> visible = hidden.getVisContigsIterator(0, 25);
+ Iterator<int[]> visible = hidden.getVisContigsIterator(0, 25, false);
int[] region = visible.next();
assertEquals("[0, 14]", Arrays.toString(region));
region = visible.next();
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();
false);
// confirm that original contigs are as expected
- Iterator<int[]> visible = hidden.getVisContigsIterator(0, 20);
+ Iterator<int[]> visible = hidden.getVisContigsIterator(0, 20, false);
int[] region = visible.next();
assertEquals("[0, 6]", Arrays.toString(region));
region = visible.next();
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();
public void testVisibleBlocksVisBoundsIterator()
{
HiddenColumns h = new HiddenColumns();
- Iterator<int[]> regions = h.getVisibleBlocksIterator(0, 30, true);
+ Iterator<int[]> regions = h.getVisContigsIterator(0, 30, true);
// only 1 visible region spanning 0-30 if nothing is hidden
assertTrue(regions.hasNext());
// 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();
// 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();
// 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();
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();
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();
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();
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();