From 3289826892c6295a3cdd9056d8f0e1a27fa67124 Mon Sep 17 00:00:00 2001 From: hanna Date: Thu, 25 Feb 2010 21:02:18 +0000 Subject: [PATCH] Fix chartl's issue -- reduceInit() is sometimes called unnecessarily at the end of a traversal. git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@2889 348d0f76-0448-11de-a6fe-93d51630548a --- .../sting/gatk/executive/Accumulator.java | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) 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;