Skip to content

Commit

Permalink
#239 explicitly checking for non-null read pairing statistics when a …
Browse files Browse the repository at this point in the history
…record is flagged as paired.
  • Loading branch information
Daniel Cameron committed Sep 17, 2019
1 parent 6bf86d0 commit f079e88
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/main/java/au/edu/wehi/idsv/DirectedEvidenceIterator.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import htsjdk.samtools.SAMRecord;
import htsjdk.samtools.util.CloseableIterator;
import htsjdk.samtools.util.CloserUtil;
import htsjdk.samtools.util.Log;

import java.util.ArrayDeque;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Queue;

public class DirectedEvidenceIterator implements CloseableIterator<DirectedEvidence>, PeekingIterator<DirectedEvidence> {
private static final Log log = Log.getInstance(DirectedEvidenceIterator.class);
private final SAMEvidenceSource source;
private Iterator<SAMRecord> it;
private Queue<DirectedEvidence> buffer = new ArrayDeque<>();
Expand All @@ -20,6 +22,9 @@ public class DirectedEvidenceIterator implements CloseableIterator<DirectedEvide
* @param it input records
*/
public DirectedEvidenceIterator(Iterator<SAMRecord> it, SAMEvidenceSource source, int minIndelSize) {
if (source == null) {
throw new IllegalArgumentException("source cannot be null");
}
this.source = source;
this.it = it;
this.minIndelSize = minIndelSize;
Expand All @@ -32,17 +37,24 @@ private void ensureBuffer() {
}
}
private void addToBuffer(SAMRecord record) {
if (record.getReadUnmappedFlag() || record.getMappingQuality() < source.getContext().getConfig().minMapq) {
if (record == null || record.getReadUnmappedFlag() || record.getMappingQuality() < source.getContext().getConfig().minMapq) {
return;
}
buffer.addAll(SingleReadEvidence.createEvidence(source, minIndelSize, record));
if (!record.getSupplementaryAlignmentFlag()) {
if (record.getReadPairedFlag()
&& !record.getReadUnmappedFlag()
&& !source.getReadPairConcordanceCalculator().isConcordant(record)) {
NonReferenceReadPair nrrp = NonReferenceReadPair.create(source, record);
if (nrrp != null) {
buffer.add(nrrp);
if (record.getReadPairedFlag()) {
ReadPairConcordanceCalculator rpcc = source.getReadPairConcordanceCalculator();
if (rpcc == null) {
String msg = String.format("Sanity check failure: null ReadPairConcordanceCalculator for an input file where %s has read paired flag set.", record.getReadName());
log.error(msg);
throw new RuntimeException(msg);
}
if (!record.getReadUnmappedFlag()
&& !rpcc.isConcordant(record)) {
NonReferenceReadPair nrrp = NonReferenceReadPair.create(source, record);
if (nrrp != null) {
buffer.add(nrrp);
}
}
}
}
Expand Down

0 comments on commit f079e88

Please sign in to comment.