diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/PrintReadsWalker.java b/java/src/org/broadinstitute/sting/gatk/walkers/PrintReadsWalker.java index a656fc175..25e1c50b1 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/PrintReadsWalker.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/PrintReadsWalker.java @@ -44,6 +44,8 @@ public class PrintReadsWalker extends ReadWalker { SAMFileWriter outputBamFile = null; @Argument(fullName = "maxReadLength", shortName = "maxRead", doc="Discard reads with length greater than the specified value", required = false) Integer maxLength = null; + @Argument(fullName = "readGroup", shortName = "readGroup", doc="Discard reads not belonging to the specified read group", required = false) + String readGroup = null; @Argument(fullName = "platform", shortName = "platform", doc="Discard reads not generated by the specified platform", required = false) String platform = null; // E.g. ILLUMINA, 454 @@ -63,19 +65,28 @@ public class PrintReadsWalker extends ReadWalker { * @return true if the read passes the filter, false if it doesn't */ public boolean filter(char[] ref, SAMRecord read) { + // check the length if ( maxLength != null && read.getReadLength() > maxLength ) return false; - if ( platform != null ) { - Object readGroupAttr = read.getAttribute("RG"); - if ( readGroupAttr != null ) { - SAMReadGroupRecord readGroup = getToolkit().getSAMFileHeader().getReadGroup(readGroupAttr.toString()); - if ( readGroup != null ) { - Object readPlatformAttr = readGroup.getAttribute("PL"); - if ( readPlatformAttr != null ) - return readPlatformAttr.toString().toUpperCase().contains(platform); - } - } + + // check the read group + if ( readGroup != null ) { + SAMReadGroupRecord myReadGroup = read.getReadGroup(); + if ( myReadGroup == null || !readGroup.equals(myReadGroup) ) + return false; } + + // check the platform + if ( platform != null ) { + SAMReadGroupRecord readGroup = read.getReadGroup(); + if ( readGroup == null ) + return false; + + Object readPlatformAttr = readGroup.getAttribute("PL"); + if ( readPlatformAttr == null || !readPlatformAttr.toString().toUpperCase().contains(platform)) + return false; + } + return true; }