diff --git a/java/src/org/broadinstitute/sting/gatk/iterators/MergingSamRecordIterator2.java b/java/src/org/broadinstitute/sting/gatk/iterators/MergingSamRecordIterator2.java index f826cc59c..a70ebcc5d 100644 --- a/java/src/org/broadinstitute/sting/gatk/iterators/MergingSamRecordIterator2.java +++ b/java/src/org/broadinstitute/sting/gatk/iterators/MergingSamRecordIterator2.java @@ -235,15 +235,22 @@ public class MergingSamRecordIterator2 implements CloseableIterator, final SAMRecord record = iterator.next(); addIfNotEmpty(iterator); + // Fix the read group if needs be if (this.samHeaderMerger.hasReadGroupCollisions()) { - final String id = (String) record.getAttribute(ReservedTagConstants.READ_GROUP_ID); - final String newId = this.samHeaderMerger.getReadGroupId(iterator.getReader(), id); - record.setAttribute(ReservedTagConstants.READ_GROUP_ID, newId); + final String oldGroupId = (String) record.getAttribute(ReservedTagConstants.READ_GROUP_ID); + if (oldGroupId != null ) { + final String newGroupId = this.samHeaderMerger.getReadGroupId(iterator.getReader(), oldGroupId); + record.setAttribute(ReservedTagConstants.READ_GROUP_ID, newGroupId); + } } - final String oldProgramGroupId = (String) record.getAttribute(SAMTag.PG.toString()); - if (oldProgramGroupId != null) { - final String newProgramGroupId = this.samHeaderMerger.getProgramGroupId(iterator.getReader(), oldProgramGroupId); - record.setAttribute(SAMTag.PG.toString(), newProgramGroupId); + + // Fix the program group if needs be + if (this.samHeaderMerger.hasProgramGroupCollisions()) { + final String oldGroupId = (String) record.getAttribute(ReservedTagConstants.PROGRAM_GROUP_ID); + if (oldGroupId != null ) { + final String newGroupId = this.samHeaderMerger.getProgramGroupId(iterator.getReader(), oldGroupId); + record.setAttribute(ReservedTagConstants.PROGRAM_GROUP_ID, newGroupId); + } } // if we don't have a read group, set one correctly