diff --git a/java/src/org/broadinstitute/sting/gatk/executive/Accumulator.java b/java/src/org/broadinstitute/sting/gatk/executive/Accumulator.java index 8022cbcce..d24242613 100755 --- a/java/src/org/broadinstitute/sting/gatk/executive/Accumulator.java +++ b/java/src/org/broadinstitute/sting/gatk/executive/Accumulator.java @@ -123,6 +123,12 @@ public abstract class Accumulator { * and aggregates those results into a single list. */ private static class IntervalAccumulator extends Accumulator { + /** + * True if a new interval is being started. This flag is used to + * ensure that reduceInit() is not called unnecessarily. + */ + private boolean startingNewInterval = true; + /** * An iterator through all intervals in the series. */ @@ -138,19 +144,27 @@ public abstract class Accumulator { */ private final List> intervalAccumulator = new ArrayList>(); + /** + * Holds the next value to be passed in as the reduce result. + */ private Object nextReduceInit = null; protected IntervalAccumulator(Walker walker, GenomeLocSortedSet intervals) { super(walker); this.intervalIterator = intervals.iterator(); if(intervalIterator.hasNext()) currentInterval = intervalIterator.next(); - nextReduceInit = walker.reduceInit(); } /** * Interval accumulator always feeds reduceInit into every new traversal. */ - public Object getReduceInit() { return nextReduceInit; } + public Object getReduceInit() { + if(startingNewInterval) { + startingNewInterval = false; + nextReduceInit = walker.reduceInit(); + } + return nextReduceInit; + } /** * Create a holder for interval results if none exists. Add the result to the holder. @@ -164,7 +178,7 @@ public abstract class Accumulator { if(currentInterval != null && currentInterval.getContig().equals(location.getContig()) && currentInterval.getStop() == location.getStop()) { intervalAccumulator.add(new Pair(currentInterval,result)); - nextReduceInit = walker.reduceInit(); + startingNewInterval = true; } else nextReduceInit = result;