use of htsjdk.samtools.CigarOperator in project gatk by broadinstitute.
the class PileupElementUnitTest method testIsImmediatelyAfter_insideFinalMs.
@Test
public void testIsImmediatelyAfter_insideFinalMs() {
final GATKRead read = ArtificialReadUtils.createArtificialRead("10M10D10M");
final PileupElement pe = PileupElement.createPileupForReadAndOffset(read, 15);
Assert.assertFalse(pe.atStartOfCurrentCigar(), "atStartOfCurrentCigar");
Assert.assertFalse(pe.atEndOfCurrentCigar(), "atEndOfCurrentCigar");
for (final CigarOperator op : CigarOperator.values()) {
Assert.assertFalse(pe.isImmediatelyAfter(op), "isImmediatelyAfter " + op);
}
for (final CigarOperator op : CigarOperator.values()) {
Assert.assertFalse(pe.isImmediatelyBefore(op), "isImmediatelyBefore " + op);
}
}
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);
}
use of htsjdk.samtools.CigarOperator in project polyGembler by c-zhou.
the class HetCorr method buffer.
private static void buffer(final Set<SAMRecord> record_pool, final Set<Integer> ins_pool, final SAMRecordIterator[] iter1, final SAMRecord[] buffer, final int[] bufferS, final int pos, final int i) {
// TODO Auto-generated method stub
SAMRecord tmp_record = buffer[i];
while (tmp_record != null && tmp_record.getAlignmentStart() <= pos) {
// if(tmp_record.getNotPrimaryAlignmentFlag() ||
// tmp_record.getSupplementaryAlignmentFlag()&&tmp_record.getMappingQuality()<10 ) {
// System.out.println(tmp_record.getSAMString());
// } else {
record_pool.add(tmp_record);
// to decide insertion position which cannot be decided from reference sequence
if (tmp_record.getCigarString().contains("I")) {
List<CigarElement> cigars = tmp_record.getCigar().getCigarElements();
int overhang = tmp_record.getAlignmentStart();
for (CigarElement cigar : cigars) {
CigarOperator operator = cigar.getOperator();
if (operator == CigarOperator.I)
ins_pool.add(overhang);
else if (operator != CigarOperator.D && operator != CigarOperator.S && operator != CigarOperator.H)
overhang += cigar.getLength();
}
}
// }
tmp_record = iter1[i].hasNext() ? iter1[i].next() : null;
}
buffer[i] = tmp_record;
bufferS[i] = tmp_record == null ? Integer.MAX_VALUE : tmp_record.getAlignmentStart();
return;
}
Aggregations