use of htsjdk.samtools.CigarOperator in project gatk by broadinstitute.
the class PileupElementUnitTest method testImmediateBeforeAndAfterTest.
@Test(dataProvider = "PrevAndNextTest")
public void testImmediateBeforeAndAfterTest(final GATKRead read, final CigarOperator firstOp, final CigarOperator lastOp, final List<CigarOperator> ops) {
final AlignmentStateMachine state = new AlignmentStateMachine(read);
//before the first 'op' from the list
state.stepForwardOnGenome();
final PileupElement pe1 = state.makePileupElement();
Assert.assertEquals(pe1.getAdjacentOperator(PileupElement.Direction.PREV), null);
Assert.assertEquals(pe1.getAdjacentOperator(PileupElement.Direction.NEXT), ops.get(0));
for (final CigarOperator op : CigarOperator.values()) {
Assert.assertEquals(pe1.isImmediatelyBefore(op), ops.get(0) == op, op.toString());
Assert.assertFalse(pe1.isImmediatelyAfter(op), op.toString());
}
//after the first 'op' from the list
state.stepForwardOnGenome();
final PileupElement pe2 = state.makePileupElement();
Assert.assertEquals(pe2.getAdjacentOperator(PileupElement.Direction.PREV), ops.get(ops.size() - 1));
Assert.assertEquals(pe2.getAdjacentOperator(PileupElement.Direction.NEXT), null);
for (final CigarOperator op : CigarOperator.values()) {
Assert.assertFalse(pe2.isImmediatelyBefore(op), "immediately before " + op);
Assert.assertEquals(pe2.isImmediatelyAfter(op), op == ops.get(ops.size() - 1), "immediately after " + op);
}
}
use of htsjdk.samtools.CigarOperator in project gatk by broadinstitute.
the class LocusIteratorByState method lazyLoadNextAlignmentContext.
/**
* Creates the next alignment context from the given state. Note that this is implemented as a
* lazy load method. nextAlignmentContext MUST BE null in order for this method to advance to the
* next entry.
*/
private void lazyLoadNextAlignmentContext() {
while (nextAlignmentContext == null && readStates.hasNext()) {
readStates.collectPendingReads();
final Locatable location = getLocation();
final Map<String, ReadPileup> fullPileupPerSample = new LinkedHashMap<>();
for (final Map.Entry<String, PerSampleReadStateManager> sampleStatePair : readStates) {
final String sample = sampleStatePair.getKey();
final PerSampleReadStateManager readState = sampleStatePair.getValue();
final Iterator<AlignmentStateMachine> iterator = readState.iterator();
final List<PileupElement> pile = new ArrayList<>(readState.size());
while (iterator.hasNext()) {
// state object with the read/offset information
final AlignmentStateMachine state = iterator.next();
final GATKRead read = state.getRead();
final CigarOperator op = state.getCigarOperator();
if (!includeReadsWithNsAtLoci && op == CigarOperator.N) {
continue;
}
if (!dontIncludeReadInPileup(read, location.getStart())) {
if (!includeReadsWithDeletionAtLoci && op == CigarOperator.D) {
continue;
}
pile.add(state.makePileupElement());
}
}
if (!pile.isEmpty()) {
// if this pileup added at least one base, add it to the full pileup
fullPileupPerSample.put(sample, new ReadPileup(location, pile));
}
}
// critical - must be called after we get the current state offsets and location
readStates.updateReadStates();
if (!fullPileupPerSample.isEmpty()) {
// if we got reads with non-D/N over the current position, we are done
nextAlignmentContext = new AlignmentContext(location, new ReadPileup(location, fullPileupPerSample));
}
}
}
use of htsjdk.samtools.CigarOperator in project gatk by broadinstitute.
the class OverclippedReadFilter method test.
@Override
public boolean test(final GATKRead read) {
int alignedLength = 0;
int softClipBlocks = 0;
int minSoftClipBlocks = doNotRequireSoftclipsOnBothEnds ? 1 : 2;
CigarOperator prevOperator = null;
for (final CigarElement element : read.getCigarElements()) {
if (element.getOperator() == CigarOperator.S) {
//Treat consecutive S blocks as a single one
if (prevOperator != CigarOperator.S) {
softClipBlocks += 1;
}
} else if (element.getOperator().consumesReadBases()) {
// M, I, X, and EQ (S was already accounted for above)
alignedLength += element.getLength();
}
prevOperator = element.getOperator();
}
return (alignedLength >= minimumSequenceLength || softClipBlocks < minSoftClipBlocks);
}
Aggregations