diff --git a/java/src/org/broadinstitute/sting/gatk/iterators/DownsamplingLocusIteratorByState.java b/java/src/org/broadinstitute/sting/gatk/iterators/DownsamplingLocusIteratorByState.java index b72d32d2e..11167860e 100755 --- a/java/src/org/broadinstitute/sting/gatk/iterators/DownsamplingLocusIteratorByState.java +++ b/java/src/org/broadinstitute/sting/gatk/iterators/DownsamplingLocusIteratorByState.java @@ -284,7 +284,7 @@ public class DownsamplingLocusIteratorByState extends LocusIterator { readStates = new ReadStateManager(samIterator,readInformation.getDownsamplingMethod(),readInformation.getMaxReadsAtLocus(),sampleNames); this.readInfo = readInformation; this.filters = filters; - overflowTracker = new LocusOverflowTracker(readInformation.getMaxReadsAtLocus()); + overflowTracker = new LocusOverflowTracker(readInformation.getMaxReadsAtLocus()); } public Iterator iterator() { @@ -534,11 +534,22 @@ public class DownsamplingLocusIteratorByState extends LocusIterator { public ReadStateManager(Iterator source, DownsamplingMethod downsamplingMethod, int maxReadsAtLocus, Collection sampleNames) { this.iterator = new PeekableIterator(source); this.downsamplingMethod = downsamplingMethod; - this.targetCoverage = downsamplingMethod.toCoverage != null ? downsamplingMethod.toCoverage : 1; + switch(downsamplingMethod.type) { + case EXPERIMENTAL_NAIVE_DUPLICATE_ELIMINATOR: + this.targetCoverage = downsamplingMethod.toCoverage != null ? downsamplingMethod.toCoverage : 1; + break; + case EXPERIMENTAL_BY_SAMPLE: + if(downsamplingMethod.toCoverage == null) + throw new StingException("Downsampling coverage (-dcov) must be specified when downsampling by sample"); + this.targetCoverage = downsamplingMethod.toCoverage; + break; + default: + this.targetCoverage = Integer.MAX_VALUE; + } this.maxReadsAtLocus = maxReadsAtLocus; if(downsamplingMethod.type == DownsampleType.NONE) aggregatorsBySampleName.put(null,new ArrayList()); - if(downsamplingMethod.type == DownsampleType.EXPERIMENTAL_NAIVE_DUPLICATE_ELIMINATOR) + else if(downsamplingMethod.type == DownsampleType.EXPERIMENTAL_NAIVE_DUPLICATE_ELIMINATOR) aggregatorsBySampleName.put(null,new ReservoirDownsampler(targetCoverage)); else { for(String sampleName: sampleNames) @@ -705,10 +716,10 @@ public class DownsamplingLocusIteratorByState extends LocusIterator { } private Collection getAggregator(String sampleName) { - if(downsamplingMethod.type == DownsampleType.EXPERIMENTAL_NAIVE_DUPLICATE_ELIMINATOR) - return aggregatorsBySampleName.get(null); - else + if(downsamplingMethod.type == DownsampleType.EXPERIMENTAL_BY_SAMPLE) return aggregatorsBySampleName.get(sampleName); + else + return aggregatorsBySampleName.get(null); } private int countReadsInHanger(final String sampleName) {