Package htsjdk.samtools

Examples of htsjdk.samtools.SAMRecord


    public void timeExtractTag(int reps) {
        for(int i = 0; i < reps; i++) {
            SAMFileReader reader = new SAMFileReader(inputFile);
            CloseableIterator<SAMRecord> iterator = reader.iterator();
            while(iterator.hasNext()) {
                SAMRecord read = iterator.next();
                read.getAttribute("OQ");
            }
            iterator.close();
            reader.close();
        }
    }
View Full Code Here


            SAMFileReader reader = new SAMFileReader(inputFile);
            CloseableIterator<SAMRecord> iterator = reader.iterator();

            long As=0,Cs=0,Gs=0,Ts=0;
            while(iterator.hasNext()) {
                SAMRecord read = iterator.next();
                for(byte base: read.getReadBases()) {
                    switch(base) {
                        case 'A': As++; break;
                        case 'C': Cs++; break;
                        case 'G': Gs++; break;
                        case 'T': Ts++; break;
View Full Code Here

            long others = 0;

            SAMFileReader reader = new SAMFileReader(inputFile);
            CloseableIterator<SAMRecord> iterator = reader.iterator();
            while(iterator.hasNext()) {
                SAMRecord read = iterator.next();

                Cigar cigar = read.getCigar();
                for(CigarElement cigarElement: cigar.getCigarElements()) {
                    int elementSize = cigarElement.getLength();
                    while(elementSize > 0) {
                        switch(cigarElement.getOperator()) {
                            case M: case EQ: case X: matchMismatches++; break;
View Full Code Here

        while (super.hasNext() && this.peek().getReferenceIndex() >= 0) {
            super.next();
        }
        // sanity check that we have an actual matching read next
        SAMRecord rec = this.peek();
        if (rec == null) {
            throw new ReviewedGATKException("The next read doesn't match");
        }
        // set the seeked variable to true
        seeked = true;
View Full Code Here

        }
        while (super.hasNext() && this.peek().getAlignmentStart() < start) {
            super.next();
        }
        // sanity check that we have an actual matching read next
        SAMRecord rec = this.peek();
        if (!matches(rec)) {
            throw new ReviewedGATKException("The next read doesn't match");
        }
        // set the seeked variable to true
        seeked = true;
View Full Code Here


    public SAMRecord next() {
        open = true;       

        SAMRecord ret = next;
        createNextRead();
        return ret;
    }
View Full Code Here

    private Collection<SAMRecord> makeReadStack( int contig, int alignmentStart, int stackSize ) {
        Collection<SAMRecord> readStack = new ArrayList<SAMRecord>(stackSize);

        for ( int i = 0; i < stackSize; i++ ) {
            SAMRecord read = ArtificialSAMUtils.createArtificialRead(header,
                                                                     "foo",
                                                                     contig,
                                                                     alignmentStart,
                                                                     MathUtils.randomIntegerInRange(minReadLength, maxReadLength));
            read.setAttribute(READ_GROUP_TAG, readGroupID);
            readStack.add(read);
        }

        return readStack;
    }
View Full Code Here

        int lastStart = -1;

        // build an initial map, grabbing all of the multi-read fragments
        for ( final T p : readContainingObjects ) {
            final SAMRecord read = getter.get(p);

            if ( read.getAlignmentStart() < lastStart ) {
                throw new IllegalArgumentException(String.format(
                        "FragmentUtils.create assumes that the incoming objects are ordered by " +
                                "SAMRecord alignment start, but saw a read %s with alignment start " +
                                "%d before the previous start %d", read.getSAMString(), read.getAlignmentStart(), lastStart));
            }
            lastStart = read.getAlignmentStart();

            final int mateStart = read.getMateAlignmentStart();
            if ( mateStart == 0 || mateStart > read.getAlignmentEnd() ) {
                // if we know that this read won't overlap its mate, or doesn't have one, jump out early
                if ( singletons == null ) singletons = new ArrayList<T>(nElements); // lazy init
                singletons.add(p);
            } else {
                // the read might overlap it's mate, or is the rightmost read of a pair
                final String readName = read.getReadName();
                final T pe1 = nameMap == null ? null : nameMap.get(readName);
                if ( pe1 != null ) {
                    // assumes we have at most 2 reads per fragment
                    if ( overlapping == null ) overlapping = new ArrayList<List<T>>(); // lazy init
                    overlapping.add(Arrays.asList(pe1, p));
View Full Code Here

            final CloseableIterator<SAMRecord> it = reader.iterator();
            final ProgressLogger progress = new ProgressLogger(Log.getInstance(CleanSam.class));

            // If the read (or its mate) maps off the end of the alignment, clip it
            while(it.hasNext()) {
                final SAMRecord rec = it.next();

                // If the read (or its mate) maps off the end of the alignment, clip it
                AbstractAlignmentMerger.createNewCigarsIfMapsOffEndOfReference(rec);

                // check the read's mapping quality
                if (rec.getReadUnmappedFlag() && 0 != rec.getMappingQuality()) {
                    rec.setMappingQuality(0);
                }

                writer.addAlignment(rec);
                progress.record(rec);
            }
View Full Code Here

            return underlyingIterator.hasNext();
        }

        @Override
        public SAMRecord next() {
            final SAMRecord rec = underlyingIterator.next();
            final String readName = rec.getReadName();
            if (readName.endsWith(suffixToTrim)) {
                rec.setReadName(readName.substring(0, readName.length() - suffixToTrim.length()));
            }
            return rec;
        }
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.