diff --git a/src/main/java/org/broadinstitute/hellbender/tools/walkers/mutect/SomaticGenotypingEngine.java b/src/main/java/org/broadinstitute/hellbender/tools/walkers/mutect/SomaticGenotypingEngine.java index aa3a4986391..2fdfc4446bb 100644 --- a/src/main/java/org/broadinstitute/hellbender/tools/walkers/mutect/SomaticGenotypingEngine.java +++ b/src/main/java/org/broadinstitute/hellbender/tools/walkers/mutect/SomaticGenotypingEngine.java @@ -250,12 +250,17 @@ public CalledHaplotypes callMutations( for (final Allele allele : outputCall.getAlternateAlleles()) { // note: this creates the minimal representation behind the scenes final Event event = new Event(outputCall.getContig(), outputCall.getStart(), outputCall.getReference(), allele); - final Haplotype bestHaplotype = haplotypesByEvent.get(event).stream() - .sorted(Comparator.comparingInt(h -> haplotypeSupportCounts.getOrDefault(h, new MutableInt(0)).intValue()).reversed()) - .findFirst().get(); - - eventCountAnnotations.computeIfAbsent(outputCall, vc -> new ArrayList<>()) - .add(bestHaplotype.getEventMap().getNumberOfEvents()); + // haplotypesByEvent contains every *assembled* event, including events injected into the original assembly, + // but there are some modes where we genotype events that were never in an assembly graph, in which case + // this annotation is irrelevant + if (haplotypesByEvent.containsKey(event)) { + final Haplotype bestHaplotype = haplotypesByEvent.get(event).stream() + .sorted(Comparator.comparingInt(h -> haplotypeSupportCounts.getOrDefault(h, new MutableInt(0)).intValue()).reversed()) + .findFirst().get(); + + eventCountAnnotations.computeIfAbsent(outputCall, vc -> new ArrayList<>()) + .add(bestHaplotype.getEventMap().getNumberOfEvents()); + } } } final List outputCallsWithEventCountAnnotation = outputCalls.stream()