diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/coverage/CoverageUtils.java b/java/src/org/broadinstitute/sting/gatk/walkers/coverage/CoverageUtils.java index 0705af8af..32dcd1b0e 100644 --- a/java/src/org/broadinstitute/sting/gatk/walkers/coverage/CoverageUtils.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/coverage/CoverageUtils.java @@ -86,7 +86,7 @@ public class CoverageUtils { Map countsByRG = new HashMap(); for ( PileupElement e : context.getBasePileup() ) { if ( e.getMappingQual() >= minMapQ && e.getMappingQual() <= maxMapQ && ( e.getQual() >= minBaseQ && e.getQual() <= maxBaseQ || e.isDeletion() ) ) { - SAMReadGroupRecord readGroup = e.getRead().getReadGroup(); + SAMReadGroupRecord readGroup = getReadGroup(e.getRead()); if ( ! countsByRG.keySet().contains(readGroup) ) { countsByRG.put(readGroup,new int[6]); updateCounts(countsByRG.get(readGroup),e); @@ -112,4 +112,16 @@ public class CoverageUtils { } } } + + private static SAMReadGroupRecord getReadGroup(SAMRecord r) { + SAMReadGroupRecord rg = r.getReadGroup(); + if ( rg == null ) { + String msg = "Read "+r.getReadName()+" lacks read group information."; + msg += " Please associate all reads with read groups [recommended]\n"; + msg += " Or run with -rf MissingReadGroup [not recommended]"; + throw new StingException(msg); + } + + return rg; + } }