Search in sources :

Example 31 with CigarOperator

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

Example 32 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 33 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 34 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)

Example 35 with CigarOperator

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

Aggregations

CigarOperator (htsjdk.samtools.CigarOperator)48 CigarElement (htsjdk.samtools.CigarElement)31 Cigar (htsjdk.samtools.Cigar)24 SAMRecord (htsjdk.samtools.SAMRecord)22 ArrayList (java.util.ArrayList)17 SAMRecordIterator (htsjdk.samtools.SAMRecordIterator)15 SamReader (htsjdk.samtools.SamReader)15 SAMSequenceDictionaryProgress (com.github.lindenb.jvarkit.util.picard.SAMSequenceDictionaryProgress)13 SAMFileHeader (htsjdk.samtools.SAMFileHeader)12 File (java.io.File)12 SAMSequenceDictionary (htsjdk.samtools.SAMSequenceDictionary)11 List (java.util.List)11 Parameter (com.beust.jcommander.Parameter)9 Launcher (com.github.lindenb.jvarkit.util.jcommander.Launcher)9 Logger (com.github.lindenb.jvarkit.util.log.Logger)9 SAMReadGroupRecord (htsjdk.samtools.SAMReadGroupRecord)9 CloserUtil (htsjdk.samtools.util.CloserUtil)9 Program (com.github.lindenb.jvarkit.util.jcommander.Program)8 IndexedFastaSequenceFile (htsjdk.samtools.reference.IndexedFastaSequenceFile)8 HashMap (java.util.HashMap)8