Package htsjdk.samtools

Examples of htsjdk.samtools.SAMRecord


    }

    public boolean hasNext() { return this.it.hasNext(); }
    public SAMRecord next() {

        SAMRecord cur = it.next();
        if ( last != null )
            verifyRecord(last, cur);
        if ( ! cur.getReadUnmappedFlag() )
            last = cur;
        return cur;
    }
View Full Code Here


    /**
     * get the next SAMRecord
     * @return SAMRecord representing the next read
     */
    public SAMRecord next() {
        SAMRecord cached = record;
        record = null;
        return cached;
    }
View Full Code Here

    public SAMRecord next() {
        if ( nextRead == null ) {
            throw new NoSuchElementException("next() called when there are no more items");
        }

        SAMRecord toReturn = nextRead;
        advanceToNextRead();

        return toReturn;
    }
View Full Code Here

        return earliestPendingRead == null ||
               readComparator.compare(orderedDownsampledReadsCache.peek(), earliestPendingRead) <= 0;
    }

    private boolean fillDownsampledReadsCache() {
        SAMRecord prevRead = null;
        int numPositionalChanges = 0;

        // Continue submitting reads to the per-sample downsamplers until the read at the top of the priority queue
        // can be released without violating global sort order
        while ( nestedSAMIterator.hasNext() && ! readyToReleaseReads() ) {
            SAMRecord read = nestedSAMIterator.next();
            String sampleName = read.getReadGroup() != null ? read.getReadGroup().getSample() : null;

            ReadsDownsampler<SAMRecord> thisSampleDownsampler = perSampleDownsamplers.get(sampleName);
            if ( thisSampleDownsampler == null ) {
                thisSampleDownsampler = downsamplerFactory.newInstance();
                perSampleDownsamplers.put(sampleName, thisSampleDownsampler);
            }

            thisSampleDownsampler.submit(read);
            processFinalizedAndPendingItems(thisSampleDownsampler);

            if ( prevRead != null && prevRead.getAlignmentStart() != read.getAlignmentStart() ) {
                numPositionalChanges++;
            }

            // Periodically inform all downsamplers of the current position in the read stream. This is
            // to prevent downsamplers for samples with sparser reads than others from getting stuck too
View Full Code Here

     * Get the next value in the sequence.
     * @return Next value in the sequence.  By convention, a NoSuchElementException should be thrown if
     *         no next exists.
     */
    public SAMRecord next() {
        SAMRecord rec = wrappedIterator.next();

        // Always consolidate the cigar string into canonical form, collapsing zero-length / repeated cigar elements.
        // Downstream code (like LocusIteratorByState) cannot necessarily handle non-consolidated cigar strings.
        rec.setCigar(AlignmentUtils.consolidateCigar(rec.getCigar()));

        // if we are using default quals, check if we need them, and add if necessary.
        // 1. we need if reads are lacking or have incomplete quality scores
        // 2. we add if defaultBaseQualities has a positive value
        if (defaultBaseQualities >= 0) {
            byte reads [] = rec.getReadBases();
            byte quals [] = rec.getBaseQualities();
            if (quals == null || quals.length < reads.length) {
                byte new_quals [] = new byte [reads.length];
                for (int i=0; i<reads.length; i++)
                    new_quals[i] = defaultBaseQualities;
                rec.setBaseQualities(new_quals);
            }
        }

        // if we are using original quals, set them now if they are present in the record
        if ( useOriginalBaseQualities ) {
            byte[] originalQuals = rec.getOriginalBaseQualities();
            if ( originalQuals != null )
                rec.setBaseQualities(originalQuals);
        }

        return rec;
    }
View Full Code Here

    public SAMRecord next() {
        if ( nextRead == null ) {
            throw new NoSuchElementException("next() called when there are no more items");
        }

        SAMRecord toReturn = nextRead;
        advanceToNextRead();

        return toReturn;
    }
View Full Code Here

    @Test
    public void basicReadIteratorTest() {
        GATKSAMIterator iter = ArtificialSAMUtils.mappedReadIterator(1, 100, 100);
        int count = 0;
        while (iter.hasNext()) {
            SAMRecord rec = iter.next();
            count++;
        }
        assertEquals(count, 100 * 100);
    }
View Full Code Here

    @Test
    public void tenPerChromosome() {
        GATKSAMIterator iter = ArtificialSAMUtils.mappedReadIterator(1, 100, 10);
        int count = 0;
        while (iter.hasNext()) {
            SAMRecord rec = iter.next();

            assertEquals(Integer.valueOf(Math.round(count / 10)), rec.getReferenceIndex());
            count++;
        }
        assertEquals(count, 100 * 10);
    }
View Full Code Here

    @Test
    public void onePerChromosome() {
        GATKSAMIterator iter = ArtificialSAMUtils.mappedReadIterator(1, 100, 1);
        int count = 0;
        while (iter.hasNext()) {
            SAMRecord rec = iter.next();

            assertEquals(Integer.valueOf(count), rec.getReferenceIndex());
            count++;
        }
        assertEquals(count, 100 * 1);
    }
View Full Code Here

        int count = 0;
        for (int x = 0; x < (100* 100); x++ ) {
            if (!iter.hasNext()) {
                fail ("we didn't get the expected number of reads");
            }
            SAMRecord rec = iter.next();
            assertTrue(rec.getReferenceIndex() >= 0);
            count++;
        }
        assertEquals(100 * 100, count);

        // now we should have 1000 unmapped reads
        count = 0;
        while (iter.hasNext()) {
            SAMRecord rec = iter.next();
            assertTrue(rec.getReferenceIndex() < 0);
            count++;
        }
        assertEquals(count, 1000);
    }
View Full Code Here

TOP

Related Classes of htsjdk.samtools.SAMRecord

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.