// take the set of hidden columns, and the set of gaps in origseq,
// and remove all the hidden gaps from hiddenColumns
- // first get the gaps as a Bitset
+ // first get the non-gaps as a Bitset
+ // then calculate hidden ^ not(gap)
BitSet gaps = origseq.gapBitset();
-
- // now calculate hidden ^ not(gap)
- BitSet hidden = new BitSet();
- markHiddenRegions(hidden);
- hidden.andNot(gaps);
- hiddenColumns.clear();
- this.hideColumns(hidden);
+ this.andNot(gaps);
// for each sequence in the alignment, except the profile sequence,
// insert gaps corresponding to each hidden region but where each hidden
clearHiddenColumnsInRange(start, end);
// make sure only bits between start and end are set
- tohide.clear(0, start - 1);
- tohide.clear(Math.min(end + 1, tohide.length() - 1),
- tohide.length() - 1);
+ if (!tohide.isEmpty())
+ {
+ tohide.clear(0, start - 1);
+ tohide.clear(Math.min(end + 1, tohide.length() - 1),
+ tohide.length() - 1);
+ }
hideColumns(tohide);
}
* @param inserts
* BitSet where hidden columns will be marked
*/
- public void markHiddenRegions(BitSet inserts)
+ private void andNot(BitSet updates)
{
try
{
LOCK.readLock().lock();
+ BitSet hiddenBitSet = new BitSet();
for (int[] range : hiddenColumns)
{
- inserts.set(range[0], range[1] + 1);
+ hiddenBitSet.set(range[0], range[1] + 1);
}
+ hiddenBitSet.andNot(updates);
+ hiddenColumns.clear();
+ hideColumns(hiddenBitSet);
} finally
{
LOCK.readLock().unlock();
import java.util.Arrays;
import java.util.BitSet;
import java.util.Iterator;
-import java.util.Random;
import org.testng.annotations.Test;
}
@Test(groups = { "Functional" })
- public void testMarkHiddenRegions()
+ public void hideColumns_BitSetAndRange()
{
- BitSet toMark, fromMark;
- long seed = -3241532;
- Random number = new Random(seed);
- for (int n = 0; n < 1000; n++)
- {
- // create a random bitfield
- toMark = BitSet
- .valueOf(new long[]
- { number.nextLong(), number.nextLong(), number.nextLong() });
- toMark.set(n * number.nextInt(10), n * (25 + number.nextInt(25)));
- HiddenColumns hc = new HiddenColumns();
-
- if (n == 0)
- {
- hc.markHiddenRegions(fromMark = new BitSet());
- assertTrue(fromMark.isEmpty());
- }
-
- hc.hideColumns(toMark);
-
- // see if we can recover bitfield
- hc.markHiddenRegions(fromMark = new BitSet());
- assertEquals(toMark, fromMark);
- }
+ HiddenColumns hc = new HiddenColumns();
+ hc.hideColumns(3, 5);
+ hc.hideColumns(15, 20);
+ hc.hideColumns(45, 60);
+
+ BitSet tohide = new BitSet();
+
+ // all unhidden if tohide is empty and range covers hidden
+ hc.hideColumns(tohide, 1, 70);
+ assertTrue(!hc.hasHiddenColumns());
+
+ hc.hideColumns(3, 5);
+ hc.hideColumns(15, 20);
+ hc.hideColumns(45, 60);
+
+ // but not if range does not cover hidden
+ hc.hideColumns(tohide, 23, 40);
+ assertTrue(hc.hasHiddenColumns());
+
+ // and partial unhide if range partially covers
+ hc.hideColumns(tohide, 1, 17);
+ Iterator<int[]> it = hc.iterator();
+ assertTrue(it.hasNext());
+ int[] region = it.next();
+
+ assertEquals(18, region[0]);
+ assertEquals(20, region[1]);
+
+ assertTrue(it.hasNext());
+ region = it.next();
+
+ assertEquals(45, region[0]);
+ assertEquals(60, region[1]);
+
+ assertFalse(it.hasNext());
}
@Test(groups = { "Functional" })
}
@Test(groups = "Functional")
- public void testHideMarkedBits()
+ public void testHideColumns_BitSet()
{
HiddenColumns h = new HiddenColumns();
HiddenColumns h2 = new HiddenColumns();