diff --git a/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/variantutils/CombineGVCFs.java b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/variantutils/CombineGVCFs.java index c0c73af67..a428b6ab8 100644 --- a/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/variantutils/CombineGVCFs.java +++ b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/variantutils/CombineGVCFs.java @@ -181,11 +181,9 @@ public class CombineGVCFs extends RodWalker 1 ? startingStates.refBases[1] : (byte)'N' ): refBase; final List stoppedVCs = new ArrayList<>(state.VCs.size()); for ( int i = state.VCs.size() - 1; i >= 0; i-- ) { final VariantContext vc = state.VCs.get(i); - if ( vc.getStart() <= pos ) { + //the VC for the previous state will be stopped if its position is previous to the current position or it we've moved to a new contig + if ( vc.getStart() <= pos.getStart() || !vc.getChr().equals(pos.getContig())) { stoppedVCs.add(vc); // if it was ending anyways, then remove it from the future state - if ( vc.getEnd() == pos) { + if ( vc.getEnd() == pos.getStart()) { state.samples.removeAll(vc.getSampleNames()); state.VCs.remove(i); continue; //don't try to remove twice @@ -282,18 +283,18 @@ public class CombineGVCFs extends RodWalker lastWritePos) { - final GenomeLoc gLoc = genomeLocParser.createGenomeLoc(stoppedVCs.get(0).getChr(), pos); + //output the stopped VCs if there is no previous output (state.prevPos == null) or our current position is past + // the last write position (state.prevPos) + //NOTE: BP resolution with have current position == state.prevPos because it gets output via a different control flow + if ( !stoppedVCs.isEmpty() && (state.prevPos == null || pos.isPast(state.prevPos) )) { + final GenomeLoc gLoc = genomeLocParser.createGenomeLoc(stoppedVCs.get(0).getChr(), pos.getStart()); // we need the specialized merge if the site contains anything other than ref blocks final VariantContext mergedVC; if ( containsTrueAltAllele(stoppedVCs) ) mergedVC = ReferenceConfidenceVariantContextMerger.merge(stoppedVCs, gLoc, refBase, false); else - mergedVC = referenceBlockMerge(stoppedVCs, state, pos); + mergedVC = referenceBlockMerge(stoppedVCs, state, pos.getStart()); vcfWriter.add(mergedVC); state.prevPos = gLoc;