A few cleanups in the LocusIteratorByState

* No more N's in the extended event pileups
   * Only add to the pileup MQ0 counter if the read actually goes into the pileup
This commit is contained in:
Mauricio Carneiro 2012-01-30 21:37:02 -05:00
parent e7ace8efc4
commit 17dbe9a95d
1 changed files with 36 additions and 35 deletions

View File

@ -82,8 +82,8 @@ public class LocusIteratorByState extends LocusIterator {
CigarElement curElement = null; CigarElement curElement = null;
int nCigarElements = 0; int nCigarElements = 0;
// how far are we into a single cigarElement
int cigarElementCounter = -1; int cigarElementCounter = -1; // how far are we into a single cigarElement
// The logical model for generating extended events is as follows: the "record state" implements the traversal // The logical model for generating extended events is as follows: the "record state" implements the traversal
// along the reference; thus stepForwardOnGenome() returns on every and only on actual reference bases. This // along the reference; thus stepForwardOnGenome() returns on every and only on actual reference bases. This
@ -241,6 +241,8 @@ public class LocusIteratorByState extends LocusIterator {
readOffset += curElement.getLength(); readOffset += curElement.getLength();
break; break;
case D: // deletion w.r.t. the reference case D: // deletion w.r.t. the reference
if (readOffset < 0) // we don't want reads starting with deletion, this is a malformed cigar string
throw new UserException.MalformedBAM(read, "Read starting with deletion. Cigar: " + read.getCigarString());
if (generateExtendedEvents) { if (generateExtendedEvents) {
if (cigarElementCounter == 1) { if (cigarElementCounter == 1) {
// generate an extended event only if we just stepped into the deletion (i.e. don't // generate an extended event only if we just stepped into the deletion (i.e. don't
@ -403,9 +405,9 @@ public class LocusIteratorByState extends LocusIterator {
final int eventStartOffset = state.getReadEventStartOffset(); // this will be -1 if base is not a deletion, or if base is the first deletion in the event. Otherwise, it will give the last base before the deletion began. final int eventStartOffset = state.getReadEventStartOffset(); // this will be -1 if base is not a deletion, or if base is the first deletion in the event. Otherwise, it will give the last base before the deletion began.
final int eventLength = state.getEventLength(); final int eventLength = state.getEventLength();
// if (op != CigarOperator.N) // N's are never added to any pileup if (op == CigarOperator.N) // N's are never added to any pileup
// continue; continue;
//
if (state.hadIndel()) { // this read has an indel associated with the previous position on the ref if (state.hadIndel()) { // this read has an indel associated with the previous position on the ref
size++; size++;
ExtendedEventPileupElement pileupElement; ExtendedEventPileupElement pileupElement;
@ -418,22 +420,21 @@ public class LocusIteratorByState extends LocusIterator {
nInsertions++; nInsertions++;
pileupElement = new ExtendedEventPileupElement(read, eventStartOffset, eventLength, state.getEventBases()); pileupElement = new ExtendedEventPileupElement(read, eventStartOffset, eventLength, state.getEventBases());
} }
if (read.getMappingQuality() == 0)
nMQ0Reads++;
indelPile.add(pileupElement); indelPile.add(pileupElement);
} }
// this read has no indel associated with the previous position on the ref. Criteria to include in the pileup are: // this read has no indel so add it to the pileup as a NOEVENT:
// we only add reads that are not N's // a deletion that didn't start here (therefore, not an extended event)
// we only include deletions to the pileup if the walker requests it // we add (mis)matches as no events.
else if ( (op != CigarOperator.N) && (op != CigarOperator.D || readInfo.includeReadsWithDeletionAtLoci())) { else if (op != CigarOperator.D || readInfo.includeReadsWithDeletionAtLoci()) {
size++; size++;
indelPile.add(new ExtendedEventPileupElement((GATKSAMRecord) state.getRead(), readOffset)); indelPile.add(new ExtendedEventPileupElement((GATKSAMRecord) state.getRead(), readOffset));
} if (read.getMappingQuality() == 0)
if (state.getRead().getMappingQuality() == 0)
nMQ0Reads++; nMQ0Reads++;
}
} }
if (indelPile.size() != 0) if (indelPile.size() != 0)
@ -461,25 +462,25 @@ public class LocusIteratorByState extends LocusIterator {
final CigarOperator op = state.getCurrentCigarOperator(); // current cigar operator final CigarOperator op = state.getCurrentCigarOperator(); // current cigar operator
final CigarOperator nextOp = state.peekForwardOnGenome(); // next cigar operator final CigarOperator nextOp = state.peekForwardOnGenome(); // next cigar operator
final int readOffset = state.getReadOffset(); // the base offset on this read final int readOffset = state.getReadOffset(); // the base offset on this read
final int eventStartOffset = state.getReadEventStartOffset(); // this will be -1 if base is not a deletion, or if base is the first deletion in the event. Otherwise, it will give the last base before the deletion began.
if (op == CigarOperator.N) // N's are never added to any pileup if (op == CigarOperator.N) // N's are never added to any pileup
continue; continue;
if (read.getMappingQuality() == 0)
nMQ0Reads++;
if (op == CigarOperator.D) { if (op == CigarOperator.D) {
if (readInfo.includeReadsWithDeletionAtLoci()) { // only add deletions to the pileup if we are authorized to do so if (readInfo.includeReadsWithDeletionAtLoci()) { // only add deletions to the pileup if we are authorized to do so
int leftAlignedStart = (eventStartOffset < 0) ? readOffset : eventStartOffset; pile.add(new PileupElement(read, readOffset, true, nextOp == CigarOperator.I, false));
pile.add(new PileupElement(read, leftAlignedStart, true, nextOp == CigarOperator.I, false));
size++; size++;
nDeletions++; nDeletions++;
if (read.getMappingQuality() == 0)
nMQ0Reads++;
} }
} else { }
else {
if (!filterBaseInRead(read, location.getStart())) { if (!filterBaseInRead(read, location.getStart())) {
pile.add(new PileupElement(read, readOffset, false, nextOp == CigarOperator.I, op == CigarOperator.S)); pile.add(new PileupElement(read, readOffset, false, nextOp == CigarOperator.I, op == CigarOperator.S));
size++; size++;
if (read.getMappingQuality() == 0)
nMQ0Reads++;
} }
} }
} }