diff --git a/java/src/org/broadinstitute/sting/gatk/iterators/LocusIteratorByState.java b/java/src/org/broadinstitute/sting/gatk/iterators/LocusIteratorByState.java index 386648c44..06c58eeaa 100755 --- a/java/src/org/broadinstitute/sting/gatk/iterators/LocusIteratorByState.java +++ b/java/src/org/broadinstitute/sting/gatk/iterators/LocusIteratorByState.java @@ -309,7 +309,7 @@ public class LocusIteratorByState extends LocusIterator { public void printState() { for(Sample sample: samples) { - Iterator iterator = readStates.iteratorForSample(sample); + Iterator iterator = readStates.iterator(sample); while(iterator.hasNext()) { SAMRecordState state = iterator.next(); logger.debug(String.format("printState():")); @@ -367,9 +367,9 @@ public class LocusIteratorByState extends LocusIterator { boolean hasBeenSampled = false; for(Sample sample: samples) { - ReadStateManager.PerSampleReadStateManager psrsm = readStates.readStatesBySample.get(sample); - ArrayList indelPile = new ArrayList(psrsm.size()); - hasBeenSampled |= loc.getStart() <= psrsm.getDownsamplingExtent(); + Iterator iterator = readStates.iterator(sample); + List indelPile = new ArrayList(readStates.size(sample)); + hasBeenSampled |= loc.getStart() <= readStates.getDownsamplingExtent(sample); size = 0; nDeletions = 0; @@ -377,7 +377,8 @@ public class LocusIteratorByState extends LocusIterator { nMQ0Reads = 0; int maxDeletionLength = 0; - for ( SAMRecordState state : psrsm ) { + while(iterator.hasNext()) { + SAMRecordState state = iterator.next(); if ( state.hadIndel() ) { size++; if ( state.getEventBases() == null ) { @@ -432,16 +433,17 @@ public class LocusIteratorByState extends LocusIterator { Map fullPileup = new HashMap(); boolean hasBeenSampled = false; - for ( Sample sample: samples ) { - ReadStateManager.PerSampleReadStateManager psrsm = readStates.readStatesBySample.get(sample); - ArrayList pile = new ArrayList(psrsm.size()); - hasBeenSampled |= location.getStart() <= psrsm.getDownsamplingExtent(); + for(Sample sample: samples) { + Iterator iterator = readStates.iterator(sample); + List pile = new ArrayList(readStates.size(sample)); + hasBeenSampled |= location.getStart() <= readStates.getDownsamplingExtent(sample); size = 0; nDeletions = 0; nMQ0Reads = 0; - for ( SAMRecordState state : psrsm ) { + while(iterator.hasNext()) { + SAMRecordState state = iterator.next(); if ( state.getCurrentCigarOperator() != CigarOperator.D && state.getCurrentCigarOperator() != CigarOperator.N ) { if ( filterRead(state.getRead(), location.getStart(), filters ) ) { //discarded_bases++; @@ -496,7 +498,7 @@ public class LocusIteratorByState extends LocusIterator { private void updateReadStates() { for(Sample sample: samples) { - Iterator it = readStates.iteratorForSample(sample); + Iterator it = readStates.iterator(sample); while ( it.hasNext() ) { SAMRecordState state = it.next(); CigarOperator op = state.stepForwardOnGenome(); @@ -548,7 +550,13 @@ public class LocusIteratorByState extends LocusIterator { samplePartitioner = new SamplePartitioner(readSelectors); } - public Iterator iteratorForSample(final Sample sample) { + /** + * Returns a iterator over all the reads associated with the given sample. Note that remove() is implemented + * for this iterator; if present, total read states will be decremented. + * @param sample The sample. + * @return Iterator over the reads associated with that sample. + */ + public Iterator iterator(final Sample sample) { return new Iterator() { private Iterator wrappedIterator = readStatesBySample.get(sample).iterator(); @@ -571,10 +579,33 @@ public class LocusIteratorByState extends LocusIterator { return totalReadStates == 0; } + /** + * Retrieves the total number of reads in the manager across all samples. + * @return Total number of reads over all samples. + */ public int size() { return totalReadStates; } + /** + * Retrieves the total number of reads in the manager in the given sample. + * @param sample The sample. + * @return Total number of reads in the given sample. + */ + public int size(final Sample sample) { + return readStatesBySample.get(sample).size(); + } + + /** + * The extent of downsampling; basically, the furthest base out which has 'fallen + * victim' to the downsampler. + * @param sample Sample, downsampled independently. + * @return Integer stop of the furthest undownsampled region. + */ + public int getDownsamplingExtent(final Sample sample) { + return readStatesBySample.get(sample).getDownsamplingExtent(); + } + public SAMRecordState getFirst() { for(Sample sample: samples) { PerSampleReadStateManager reads = readStatesBySample.get(sample); @@ -785,7 +816,7 @@ public class LocusIteratorByState extends LocusIterator { if(currentCounter.getCount() == 0) counterIterator.remove(); removedCount++; - toPurge = elements.nextSetBit(toPurge+1); + toPurge = elements.nextSetBit(toPurge+1); } readIndex++;