Search in sources :

Example 16 with CigarOperator

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);
    }
}
Also used : CigarOperator(htsjdk.samtools.CigarOperator) AlignmentStateMachine(org.broadinstitute.hellbender.utils.locusiterator.AlignmentStateMachine) LocusIteratorByStateBaseTest(org.broadinstitute.hellbender.utils.locusiterator.LocusIteratorByStateBaseTest) Test(org.testng.annotations.Test) LIBSTest(org.broadinstitute.hellbender.utils.locusiterator.LIBSTest)

Example 17 with CigarOperator

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));
        }
    }
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) ReadPileup(org.broadinstitute.hellbender.utils.pileup.ReadPileup) PileupElement(org.broadinstitute.hellbender.utils.pileup.PileupElement) CigarOperator(htsjdk.samtools.CigarOperator) AlignmentContext(org.broadinstitute.hellbender.engine.AlignmentContext) Locatable(htsjdk.samtools.util.Locatable)

Example 18 with CigarOperator

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);
}
Also used : CigarOperator(htsjdk.samtools.CigarOperator) CigarElement(htsjdk.samtools.CigarElement)

Aggregations

CigarOperator (htsjdk.samtools.CigarOperator)18 GATKRead (org.broadinstitute.hellbender.utils.read.GATKRead)8 LIBSTest (org.broadinstitute.hellbender.utils.locusiterator.LIBSTest)7 LocusIteratorByStateBaseTest (org.broadinstitute.hellbender.utils.locusiterator.LocusIteratorByStateBaseTest)7 Test (org.testng.annotations.Test)7 CigarElement (htsjdk.samtools.CigarElement)5 DataProvider (org.testng.annotations.DataProvider)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Cigar (htsjdk.samtools.Cigar)2 AlignmentStateMachine (org.broadinstitute.hellbender.utils.locusiterator.AlignmentStateMachine)2 Locatable (htsjdk.samtools.util.Locatable)1 ArrayList (java.util.ArrayList)1 AlignmentContext (org.broadinstitute.hellbender.engine.AlignmentContext)1 GATKException (org.broadinstitute.hellbender.exceptions.GATKException)1 SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)1 PileupElement (org.broadinstitute.hellbender.utils.pileup.PileupElement)1 ReadPileup (org.broadinstitute.hellbender.utils.pileup.ReadPileup)1