/** * Resets statistics before reading from the underlying iterator. */ @Override protected void readFromUnderlyingIterator(final List<SAMRecord> recs, final Set<String> names, final int templatesToRead) { // Reset the stats on the underlying iterator ((ConstantMemoryDownsamplingIterator) getUnderlyingIterator()).resetStatistics(); // Read from the underlying iterator super.readFromUnderlyingIterator(recs, names, templatesToRead); }
/** * Resets statistics before reading from the underlying iterator. */ @Override protected void readFromUnderlyingIterator(final List<SAMRecord> recs, final Set<String> names, final int templatesToRead) { // Reset the stats on the underlying iterator ((ConstantMemoryDownsamplingIterator) getUnderlyingIterator()).resetStatistics(); // Read from the underlying iterator super.readFromUnderlyingIterator(recs, names, templatesToRead); }
@Override protected int calculateTemplatesToKeep(final int templatesRead, final double overallProportion) { // Calculate an adjusted proportion to keep, knowing what proportion the underlying iterator discarded final ConstantMemoryDownsamplingIterator iter = (ConstantMemoryDownsamplingIterator) getUnderlyingIterator(); final double priorProportion = iter.getAcceptedFraction(); final double p = Math.max(0, Math.min(1, overallProportion / priorProportion)); final int retval = super.calculateTemplatesToKeep(templatesRead, p); // Record all the discarded records to keep the overall statistics accurate, but do it after // the call to super() so it doesn't affect the proportion calculation. recordDiscardRecords(iter.getDiscardedCount()); return retval; } }
@Override protected int calculateTemplatesToKeep(final int templatesRead, final double overallProportion) { // Calculate an adjusted proportion to keep, knowing what proportion the underlying iterator discarded final ConstantMemoryDownsamplingIterator iter = (ConstantMemoryDownsamplingIterator) getUnderlyingIterator(); final double priorProportion = iter.getAcceptedFraction(); final double p = Math.max(0, Math.min(1, overallProportion / priorProportion)); final int retval = super.calculateTemplatesToKeep(templatesRead, p); // Record all the discarded records to keep the overall statistics accurate, but do it after // the call to super() so it doesn't affect the proportion calculation. recordDiscardRecords(iter.getDiscardedCount()); return retval; } }
/** * Constructs a chained iterator that will read from the provided iterator and attempt to downsampling to the provided proportion. */ ChainedDownsamplingIterator(final Iterator<SAMRecord> iterator, final double proportion, final int seed) { super(new ConstantMemoryDownsamplingIterator(iterator, adjustProportion(proportion), seed), proportion, seed); // Deal with the fact that the iterator will advance and discard some reads at construction final long discarded = ((ConstantMemoryDownsamplingIterator) getUnderlyingIterator()).getDiscardedCount(); recordDiscardRecords(discarded); }
/** * Constructs a chained iterator that will read from the provided iterator and attempt to downsampling to the provided proportion. */ ChainedDownsamplingIterator(final Iterator<SAMRecord> iterator, final double proportion, final int seed) { super(new ConstantMemoryDownsamplingIterator(iterator, adjustProportion(proportion), seed), proportion, seed); // Deal with the fact that the iterator will advance and discard some reads at construction final long discarded = ((ConstantMemoryDownsamplingIterator) getUnderlyingIterator()).getDiscardedCount(); recordDiscardRecords(discarded); }