From 39678b6a20fc56f46eb5aff3732d9cabeaa9dca0 Mon Sep 17 00:00:00 2001 From: Eric Banks Date: Thu, 10 Nov 2011 13:34:03 -0500 Subject: [PATCH] Check for reads with missing read groups and throw a UserException when encountered. Mauricio said this wouldn't break integration tests. --- .../gatk/filters/MalformedReadFilter.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/public/java/src/org/broadinstitute/sting/gatk/filters/MalformedReadFilter.java b/public/java/src/org/broadinstitute/sting/gatk/filters/MalformedReadFilter.java index 11bbf9e4c..46d28185b 100644 --- a/public/java/src/org/broadinstitute/sting/gatk/filters/MalformedReadFilter.java +++ b/public/java/src/org/broadinstitute/sting/gatk/filters/MalformedReadFilter.java @@ -50,19 +50,20 @@ public class MalformedReadFilter extends ReadFilter { public boolean filterOut(SAMRecord read) { // slowly changing the behavior to blow up first and filtering out if a parameter is explicitly provided - if (!checkMismatchingBasesAndQuals(read)) { - if (!filterMismatchingBaseAndQuals) - throw new UserException.MalformedBAM(read, "BAM file has a read with mismatching number of bases and base qualities. Offender: " + read.getReadName() +" [" + read.getReadLength() + " bases] [" +read.getBaseQualities().length +"] quals"); - else - return true; - } - return !checkInvalidAlignmentStart(read) || !checkInvalidAlignmentEnd(read) || !checkAlignmentDisagreesWithHeader(this.header,read) || + !checkHasReadGroup(read) || + !checkMismatchingBasesAndQuals(read, filterMismatchingBaseAndQuals) || !checkCigarDisagreesWithAlignment(read); } + private static boolean checkHasReadGroup(SAMRecord read) { + if ( read.getReadGroup() == null ) + throw new UserException.ReadMissingReadGroup(read); + return true; + } + /** * Check for the case in which the alignment start is inconsistent with the read unmapped flag. * @param read The read to validate. @@ -127,7 +128,9 @@ public class MalformedReadFilter extends ReadFilter { * @param read the read to validate * @return true if they have the same number. False otherwise. */ - private static boolean checkMismatchingBasesAndQuals(SAMRecord read) { + private static boolean checkMismatchingBasesAndQuals(SAMRecord read, boolean filterMismatchingBaseAndQuals) { + if (!filterMismatchingBaseAndQuals) + throw new UserException.MalformedBAM(read, "BAM file has a read with mismatching number of bases and base qualities. Offender: " + read.getReadName() +" [" + read.getReadLength() + " bases] [" +read.getBaseQualities().length +"] quals"); return (read.getReadLength() == read.getBaseQualities().length); } }