Package htsjdk.samtools

Examples of htsjdk.samtools.SAMFileReader


    @Test()
    public void testWithBAMFile() {
        // create a fake BAM file, and iterate through it
        final ArtificialBAMBuilder bamBuilder = new ArtificialBAMBuilder(seq, 20, 10);
        final File bam = bamBuilder.makeTemporarilyBAMFile();
        final SAMFileReader reader = new SAMFileReader(bam);
        reader.setSAMRecordFactory(new GATKSamRecordFactory());

        final Iterator<SAMRecord> bamIt = reader.iterator();
        while ( bamIt.hasNext() ) {
            final GATKSAMRecord read = (GATKSAMRecord)bamIt.next(); // all reads are actually GATKSAMRecords
            // TODO -- add some tests that use reads from a BAM
        }
    }
View Full Code Here


        }

        liftOver.setLiftOverMinMatch(LiftOver.DEFAULT_LIFTOVER_MINMATCH);

        try {
            final SAMFileHeader toHeader = new SAMFileReader(NEW_SEQ_DICT).getFileHeader();
            liftOver.validateToSequences(toHeader.getSequenceDictionary());
        } catch (RuntimeException e) {
            throw new UserException.BadInput("the chain file you are using is not compatible with the reference you are trying to lift over to; please use the appropriate chain file for the given reference");   
        }
View Full Code Here

    @Override
    public Integer getMaxReads() { return maxReads; }
   
    public void timeDecompressBamFile(int reps) {
        for(int i = 0; i < reps; i++) {
            SAMFileReader reader = new SAMFileReader(inputFile);
            CloseableIterator<SAMRecord> iterator = reader.iterator();
            while(iterator.hasNext())
                iterator.next();
            iterator.close();
            reader.close();
        }
    }
View Full Code Here

        }
    }

    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

        }
    }

    public void timeSamLocusIterator(int reps) {
        for(int i = 0; i < reps; i++) {
            SAMFileReader reader = new SAMFileReader(inputFile);
            long loci = 0;

            SamLocusIterator samLocusIterator = new SamLocusIterator(reader);
            samLocusIterator.setEmitUncoveredLoci(false);
            Iterator<SamLocusIterator.LocusInfo> workhorseIterator = samLocusIterator.iterator();

            while(workhorseIterator.hasNext()) {
                SamLocusIterator.LocusInfo locusInfo = workhorseIterator.next();
                // Use the value of locusInfo to avoid optimization.
                if(locusInfo != null) loci++;
            }
            System.out.printf("Total loci = %d%n",loci);

            reader.close();
        }
    }
View Full Code Here

    public Integer getMaxReads() { return maxReads; }

    public void timeIterateOverEachBase(int reps) {
        System.out.printf("Processing " + inputFile);
        for(int i = 0; i < reps; i++) {
            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;
                    }
                }
            }
            System.out.printf("As = %d; Cs = %d; Gs = %d; Ts = %d; total = %d%n",As,Cs,Gs,Ts,As+Cs+Gs+Ts);
            iterator.close();
            reader.close();
        }
    }
View Full Code Here

            long matchMismatches = 0;
            long insertions = 0;
            long deletions = 0;
            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;
                            case I: insertions++; break;
                            case D: deletions++; break;
                            default: others++; break;
                        }
                        elementSize--;
                    }
                }
            }
            System.out.printf("Ms = %d; Is = %d; Ds = %d; others = %d; total = %d%n",matchMismatches,insertions,deletions,others,matchMismatches+insertions+deletions+others);

            iterator.close();
            reader.close();
        }
    }
View Full Code Here

    private GATKBAMIndex bamIndex;

   
    @BeforeClass
    public void init() throws FileNotFoundException {
        SAMFileReader reader = new SAMFileReader(bamFile);
        SAMSequenceDictionary sequenceDictionary = reader.getFileHeader().getSequenceDictionary();
        reader.close();
       
        bamIndex = new GATKBAMIndex(bamIndexFile);
    }
View Full Code Here

    @Override
    public int execute() throws IOException {
        final IndexedFastaSequenceFile reference = new CachingIndexedFastaSequenceFile(referenceFile);
        final GenomeLocParser genomeLocParser = new GenomeLocParser(reference);

        final SAMFileReader reader = new SAMFileReader(samFile);
        reader.setSAMRecordFactory(new GATKSamRecordFactory());

        SAMRecordIterator rawIterator;
        if ( location == null )
            rawIterator = reader.iterator();
        else {
            final GenomeLoc loc = genomeLocParser.parseGenomeLoc(location);
            rawIterator = reader.query(loc.getContig(), loc.getStart(), loc.getStop(), false);
        }

        final GATKSAMRecordIterator iterator = new GATKSAMRecordIterator(rawIterator);

        final Set<String> samples = new HashSet<String>();
        for ( final SAMReadGroupRecord rg : reader.getFileHeader().getReadGroups() )
            samples.add(rg.getSample());

        final LIBSDownsamplingInfo ds = new LIBSDownsamplingInfo(downsample, 250);

        final LocusIteratorByState libs =
View Full Code Here

        Collection<SAMFileHeader> headers = new ArrayList<SAMFileHeader>(perSampleArtificialReadStreams.size());

        for ( ArtificialSingleSampleReadStream readStream : perSampleArtificialReadStreams ) {
            Collection<SAMRecord> thisStreamReads = readStream.makeReads();

            SAMFileReader reader = new ArtificialSAMFileReader(readStream.getHeader(),
                                                               thisStreamReads.toArray(new SAMRecord[thisStreamReads.size()]));
            perSampleSAMReaders.add(reader);
            headers.add(reader.getFileHeader());
        }

        SamFileHeaderMerger headerMerger = new SamFileHeaderMerger(SAMFileHeader.SortOrder.coordinate, headers, true);
        mergingIterator = new MergingSamRecordIterator(headerMerger, perSampleSAMReaders, true);
    }
View Full Code Here

TOP

Related Classes of htsjdk.samtools.SAMFileReader

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.