Add size() method to Downsampler interface
-- This method provides client with the current number of elements, without having to retreive the underlying list<T>. Added unit tests for LevelingDownsampler and ReservoirDownsampler as these are the only two complex ones. All of the others are trivially obviously correct.
This commit is contained in:
parent
0c2f795fa5
commit
317dc4c323
|
|
@ -94,6 +94,17 @@ public interface Downsampler<T> {
|
|||
*/
|
||||
public T peekPending();
|
||||
|
||||
/**
|
||||
* Get the current number of items in this downsampler
|
||||
*
|
||||
* This should be the best estimate of the total number of elements that will come out of the downsampler
|
||||
* were consumeFinalizedItems() to be called immediately after this call. In other words it should
|
||||
* be number of finalized items + estimate of number of pending items that will ultimately be included as well.
|
||||
*
|
||||
* @return a positive integer
|
||||
*/
|
||||
public int size();
|
||||
|
||||
/**
|
||||
* Returns the number of items discarded (so far) during the downsampling process
|
||||
*
|
||||
|
|
|
|||
|
|
@ -109,6 +109,11 @@ public class FractionalDownsampler<T extends SAMRecord> implements ReadsDownsamp
|
|||
return numDiscardedItems;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return selectedReads.size();
|
||||
}
|
||||
|
||||
public void signalEndOfInput() {
|
||||
// NO-OP
|
||||
}
|
||||
|
|
|
|||
|
|
@ -128,6 +128,15 @@ public class LevelingDownsampler<T extends List<E>, E> implements Downsampler<T>
|
|||
return numDiscardedItems;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
int s = 0;
|
||||
for ( final List<E> l : groups ) {
|
||||
s += l.size();
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
public void signalEndOfInput() {
|
||||
levelGroups();
|
||||
groupsAreFinalized = true;
|
||||
|
|
|
|||
|
|
@ -89,6 +89,11 @@ public class PassThroughDownsampler<T extends SAMRecord> implements ReadsDownsam
|
|||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return selectedReads.size();
|
||||
}
|
||||
|
||||
public void signalEndOfInput() {
|
||||
// NO-OP
|
||||
}
|
||||
|
|
|
|||
|
|
@ -156,6 +156,11 @@ public class ReservoirDownsampler<T extends SAMRecord> implements ReadsDownsampl
|
|||
return numDiscardedItems;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return reservoir.size();
|
||||
}
|
||||
|
||||
public void signalEndOfInput() {
|
||||
// NO-OP
|
||||
}
|
||||
|
|
|
|||
|
|
@ -112,6 +112,11 @@ public class SimplePositionalDownsampler<T extends SAMRecord> implements ReadsDo
|
|||
return numDiscardedItems;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return finalizedReads.size() + reservoir.size();
|
||||
}
|
||||
|
||||
public void signalEndOfInput() {
|
||||
finalizeReservoir();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -139,6 +139,7 @@ public class LevelingDownsamplerUnitTest extends BaseTest {
|
|||
Assert.assertTrue(downsampler.peekFinalized() == null && downsampler.peekPending() == null);
|
||||
}
|
||||
|
||||
final int sizeFromDownsampler = downsampler.size();
|
||||
List<List<Object>> downsampledStacks = downsampler.consumeFinalizedItems();
|
||||
Assert.assertFalse(downsampler.hasFinalizedItems() || downsampler.hasPendingItems());
|
||||
Assert.assertTrue(downsampler.peekFinalized() == null && downsampler.peekPending() == null);
|
||||
|
|
@ -151,6 +152,7 @@ public class LevelingDownsamplerUnitTest extends BaseTest {
|
|||
totalRemainingItems += stack.size();
|
||||
}
|
||||
|
||||
Assert.assertEquals(sizeFromDownsampler, totalRemainingItems);
|
||||
int numItemsReportedDiscarded = downsampler.getNumberOfDiscardedItems();
|
||||
int numItemsActuallyDiscarded = test.numStacks * test.stackSize - totalRemainingItems;
|
||||
|
||||
|
|
|
|||
|
|
@ -115,6 +115,7 @@ public class ReservoirDownsamplerUnitTest extends BaseTest {
|
|||
Assert.assertTrue(downsampler.peekFinalized() == null && downsampler.peekPending() == null);
|
||||
}
|
||||
|
||||
Assert.assertEquals(downsampler.size(), test.expectedNumReadsAfterDownsampling);
|
||||
List<SAMRecord> downsampledReads = downsampler.consumeFinalizedItems();
|
||||
Assert.assertFalse(downsampler.hasFinalizedItems() || downsampler.hasPendingItems());
|
||||
Assert.assertTrue(downsampler.peekFinalized() == null && downsampler.peekPending() == null);
|
||||
|
|
|
|||
Loading…
Reference in New Issue