Skip to content

Instantly share code, notes, and snippets.

@chapmanb
Created May 13, 2013 13:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chapmanb/5568411 to your computer and use it in GitHub Desktop.
Save chapmanb/5568411 to your computer and use it in GitHub Desktop.
Fix for BadCigar filtering in GATK 2.5-2 where zero length cigar string elements trick filter.
diff --git a/public/java/src/org/broadinstitute/sting/gatk/filters/BadCigarFilter.java b/public/java/src/org/broadinstitute/sting/gatk/filters/BadCigarFilter.java
index 85c60f0..c610006 100644
--- a/public/java/src/org/broadinstitute/sting/gatk/filters/BadCigarFilter.java
+++ b/public/java/src/org/broadinstitute/sting/gatk/filters/BadCigarFilter.java
@@ -81,42 +81,45 @@ public class BadCigarFilter extends ReadFilter {
CigarOperator previousOp = firstOp;
while (elementIterator.hasNext()) {
- CigarOperator op = elementIterator.next().getOperator();
+ CigarElement el = elementIterator.next();
+ CigarOperator op = el.getOperator();
- if (op != CigarOperator.S && op != CigarOperator.H) {
+ if (el.getLength() > 0) {
+ if (op != CigarOperator.S && op != CigarOperator.H) {
- // No reads with Hard/Soft clips in the middle of the cigar
- if (previousOp == CigarOperator.S || previousOp == CigarOperator.H)
- return true;
+ // No reads with Hard/Soft clips in the middle of the cigar
+ if (previousOp == CigarOperator.S || previousOp == CigarOperator.H)
+ return true;
- lastOp = op;
+ lastOp = op;
- if (!hasMeaningfulElements && op.consumesReadBases()) {
- hasMeaningfulElements = true;
- }
+ if (!hasMeaningfulElements && op.consumesReadBases()) {
+ hasMeaningfulElements = true;
+ }
- if (op == CigarOperator.I || op == CigarOperator.D) {
+ if (op == CigarOperator.I || op == CigarOperator.D) {
- // No reads that have consecutive indels in the cigar (II, DD, ID or DI)
- if (previousElementWasIndel) {
- return true;
+ // No reads that have consecutive indels in the cigar (II, DD, ID or DI)
+ if (previousElementWasIndel) {
+ return true;
+ }
+ previousElementWasIndel = true;
+ }
+ else {
+ previousElementWasIndel = false;
}
- previousElementWasIndel = true;
}
- else {
- previousElementWasIndel = false;
+ // No reads with Hard/Soft clips in the middle of the cigar
+ else if (op == CigarOperator.S && previousOp == CigarOperator.H) {
+ return true;
}
- }
- // No reads with Hard/Soft clips in the middle of the cigar
- else if (op == CigarOperator.S && previousOp == CigarOperator.H) {
- return true;
- }
- previousOp = op;
+ previousOp = op;
+ }
}
// No reads ending in deletions (with or without follow-up clips)
// No reads that are fully hard or soft clipped
return lastOp == CigarOperator.D || !hasMeaningfulElements;
}
-}
\ No newline at end of file
+}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment