Package htsjdk.samtools

Examples of htsjdk.samtools.CigarElement


        ArrayList<CigarElement> elements = new ArrayList<CigarElement>(cigar.numCigarElements());
        for (int i = 0; i < indexOfIndel - 1; i++)
            elements.add(cigar.getCigarElement(i));

        // get the indel element and move it left one base
        CigarElement ce = cigar.getCigarElement(indexOfIndel - 1);
        elements.add(new CigarElement(Math.max(ce.getLength() - 1, 0), ce.getOperator()));
        elements.add(cigar.getCigarElement(indexOfIndel));
        if (indexOfIndel + 1 < cigar.numCigarElements()) {
            ce = cigar.getCigarElement(indexOfIndel + 1);
            elements.add(new CigarElement(ce.getLength() + 1, ce.getOperator()));
        } else {
            elements.add(new CigarElement(1, CigarOperator.M));
        }

        // get the last few elements
        for (int i = indexOfIndel + 2; i < cigar.numCigarElements(); i++)
            elements.add(cigar.getCigarElement(i));
View Full Code Here


     * @return non-null byte array which is the indel representation against the reference
     */
    @Requires("cigar != null && indexOfIndel >= 0 && indexOfIndel < cigar.numCigarElements() && refSeq != null && readSeq != null && refIndex >= 0 && readIndex >= 0")
    @Ensures("result != null")
    private static byte[] createIndelString(final Cigar cigar, final int indexOfIndel, final byte[] refSeq, final byte[] readSeq, int refIndex, int readIndex) {
        CigarElement indel = cigar.getCigarElement(indexOfIndel);
        int indelLength = indel.getLength();

        int totalRefBases = 0;
        for (int i = 0; i < indexOfIndel; i++) {
            CigarElement ce = cigar.getCigarElement(i);
            int length = ce.getLength();

            switch (ce.getOperator()) {
                case M:
                case EQ:
                case X:
                    readIndex += length;
                    refIndex += length;
View Full Code Here

     * @return the position after we've traversed all elt.length bases of elt
     */
   protected static int addCigarElements(final List<CigarElement> dest, int pos, final int start, final int end, final CigarElement elt) {
        final int length = Math.min(pos + elt.getLength() - 1, end) - Math.max(pos, start) + 1;
        if ( length > 0 )
            dest.add(new CigarElement(length, elt.getOperator()));
        return pos + elt.getLength();
    }
View Full Code Here

        int cigar12I = 0, cigar23I = 0;
        int elt12I = 0, elt23I = 0;

        while ( cigar12I < nElements12 && cigar23I < nElements23 ) {
            final CigarElement elt12 = firstToSecond.getCigarElement(cigar12I);
            final CigarElement elt23 = secondToThird.getCigarElement(cigar23I);

            final CigarPairTransform transform = getTransformer(elt12.getOperator(), elt23.getOperator());

            if ( DEBUG )
                System.out.printf("Transform %s => %s with elt1 = %d %s @ %d elt2 = %d %s @ %d with transform %s%n",
                        firstToSecond, secondToThird, cigar12I, elt12.getOperator(), elt12I, cigar23I, elt23.getOperator(), elt23I, transform);

            if ( transform.op13 != null ) // skip no ops
                newElements.add(new CigarElement(1, transform.op13));

            elt12I += transform.advance12;
            elt23I += transform.advance23;

            // if have exhausted our current element, advance to the next one
            if ( elt12I == elt12.getLength() ) { cigar12I++; elt12I = 0; }
            if ( elt23I == elt23.getLength() ) { cigar23I++; elt23I = 0; }
        }

        return AlignmentUtils.consolidateCigar(new Cigar(newElements));
    }
View Full Code Here

                case MATCH_MISMATCH: operator = CigarOperator.MATCH_OR_MISMATCH; break;
                case INSERTION: operator = CigarOperator.INSERTION; break;
                case DELETION: operator = CigarOperator.DELETION; break;
                default: throw new ReviewedGATKException("convertToCigar: cannot process state: " + entry.getAlignmentState());
            }
            cigar.add( new CigarElement(entry.count,operator) );
        }
        return cigar;
    }
View Full Code Here

    public void testBiasedDownsampling(final SAMFileHeader header, final int originalCount, final int toRemove) {

        final LinkedList<PileupElement> elements = new LinkedList<>();
        for ( int i = 0; i < originalCount; i++ ) {
            final GATKSAMRecord read = ArtificialSAMUtils.createArtificialRead(header, "read", 0, 1, 1);
            elements.add(new PileupElement(read, 0, new CigarElement(1, CigarOperator.M), 0, 0));
        }

        final List<PileupElement> result = AlleleBiasedDownsamplingUtils.downsampleElements(elements, originalCount, toRemove);

        Assert.assertEquals(result.size(), toRemove);
View Full Code Here

    protected Cigar refactorNDNtoN(final Cigar originalCigar) {
        final Cigar refactoredCigar = new Cigar();
        final int cigarLength = originalCigar.numCigarElements();
        for(int i = 0; i < cigarLength; i++){
            final CigarElement element = originalCigar.getCigarElement(i);
            if(element.getOperator() == CigarOperator.N && thereAreAtLeast2MoreElements(i,cigarLength)){
                final CigarElement nextElement = originalCigar.getCigarElement(i+1);
                final CigarElement nextNextElement = originalCigar.getCigarElement(i+2);

                // if it is N-D-N replace with N (with the total length) otherwise just add the first N.
                if(nextElement.getOperator() == CigarOperator.D && nextNextElement.getOperator() == CigarOperator.N){
                    final int threeElementsLength = element.getLength() + nextElement.getLength() + nextNextElement.getLength();
                    final CigarElement refactoredElement = new CigarElement(threeElementsLength,CigarOperator.N);
                    refactoredCigar.add(refactoredElement);
                    i += 2; //skip the elements that were refactored
                }
                else
                    refactoredCigar.add(element)// add only the first N
View Full Code Here

            //pe.getLengthOfImmediatelyFollowingIndel();
            //pe.getBasesOfImmediatelyFollowingInsertion();

            // Don't test -- pe.getBaseIndex();
            if ( pe.atEndOfCurrentCigar() && state.getCurrentCigarElementOffset() < read.getCigarLength() - 1 ) {
                final CigarElement nextElement = read.getCigar().getCigarElement(state.getCurrentCigarElementOffset() + 1);
                if ( nextElement.getOperator() == CigarOperator.I ) {
                    Assert.assertTrue(pe.getBetweenNextPosition().size() >= 1);
                    Assert.assertEquals(pe.getBetweenNextPosition().get(0), nextElement);
                }
                if ( nextElement.getOperator() == CigarOperator.M ) {
                    Assert.assertTrue(pe.getBetweenNextPosition().isEmpty());
                }
            } else {
                Assert.assertTrue(pe.getBetweenNextPosition().isEmpty());
            }

            if ( pe.atStartOfCurrentCigar() && state.getCurrentCigarElementOffset() > 0 ) {
                final CigarElement prevElement = read.getCigar().getCigarElement(state.getCurrentCigarElementOffset() - 1);
                if ( prevElement.getOperator() == CigarOperator.I ) {
                    Assert.assertTrue(pe.getBetweenPrevPosition().size() >= 1);
                    Assert.assertEquals(pe.getBetweenPrevPosition().getLast(), prevElement);
                }
                if ( prevElement.getOperator() == CigarOperator.M ) {
                    Assert.assertTrue(pe.getBetweenPrevPosition().isEmpty());
                }
            } else {
                Assert.assertTrue(pe.getBetweenPrevPosition().isEmpty());
            }
View Full Code Here

    @Test
    public void testSimpleInsertionAllele() {
        final String bases = "ACTGGTCAACTGGTCAACTGGTCAACTGGTCA";

        final ArrayList<CigarElement> h1CigarList = new ArrayList<CigarElement>();
        h1CigarList.add(new CigarElement(bases.length(), CigarOperator.M));
        final Cigar h1Cigar = new Cigar(h1CigarList);
        String h1bases = "AACTTCTGGTCAACTGGTCAACTGGTCAACTGGTCA";
        basicInsertTest("A", "AACTT", 0, h1Cigar, bases, h1bases);
        h1bases = "ACTGGTCAACTTACTGGTCAACTGGTCAACTGGTCA";
        basicInsertTest("A", "AACTT", 7, h1Cigar, bases, h1bases);
View Full Code Here

    @Test
    public void testSimpleDeletionAllele() {
        final String bases = "ACTGGTCAACTGGTCAACTGGTCAACTGGTCA";

        final ArrayList<CigarElement> h1CigarList = new ArrayList<CigarElement>();
        h1CigarList.add(new CigarElement(bases.length(), CigarOperator.M));
        final Cigar h1Cigar = new Cigar(h1CigarList);
        String h1bases = "ATCAACTGGTCAACTGGTCAACTGGTCA";
        basicInsertTest("ACTGG", "A", 0, h1Cigar, bases, h1bases);
        h1bases = "ACTGGTCAGTCAACTGGTCAACTGGTCA";
        basicInsertTest("AACTG", "A", 7, h1Cigar, bases, h1bases);
View Full Code Here

TOP

Related Classes of htsjdk.samtools.CigarElement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.