Package htsjdk.samtools

Examples of htsjdk.samtools.GATKBAMFileSpan


            // Prepare chunk buffer for next read.
            chunkData.flip();

            BAMScheduleEntry nextScheduleEntry = new BAMScheduleEntry(start,stop);
            nextScheduleEntry.addFileSpan(reader,new GATKBAMFileSpan(chunks));

            // Reset the position of the iterator at the next contig.
            currentPosition = position();

            return nextScheduleEntry;
View Full Code Here


                nextFilePointer.addFileSpans(scheduleEntry.fileSpans);
            }
            else {
                // Always create a file span, whether there was covered data or not.  If there was no covered data, then the binTree is empty.
                for(SAMReaderID reader: indexFiles.keySet())
                    nextFilePointer.addFileSpans(reader,new GATKBAMFileSpan());
            }

            // Early exit if no bins were found.
            if(coveredRegion == null) {
                // for debugging only: maximum split is 16384.               
View Full Code Here

     * Create a span from the given start point to the end of the file.
     * @param startOfRegion Start of the region, in encoded coordinates (block start << 16 & block offset).
     * @return A file span from the given point to the end of the file.
     */
    private GATKBAMFileSpan createSpanToEndOfFile(final long startOfRegion) {
      return new GATKBAMFileSpan(new GATKChunk(startOfRegion,Long.MAX_VALUE));
    }
View Full Code Here

        PeekableIterator<Map.Entry<SAMReaderID,SAMFileSpan>> otherIterator = new PeekableIterator<Map.Entry<SAMReaderID,SAMFileSpan>>(other.fileSpans.entrySet().iterator());

        while(thisIterator.hasNext()) {
            // If there are no elements left in the 'other' iterator, spin out this iterator.
            if(!otherIterator.hasNext()) {
                GATKBAMFileSpan nextSpan = (GATKBAMFileSpan)thisIterator.next().getValue();
                difference += nextSpan.size();
                continue;
            }

            // Otherwise, compare the latest value.
            int compareValue = thisIterator.peek().getKey().compareTo(otherIterator.peek().getKey());

            if(compareValue < 0) {
                // This before other.
                difference += ((GATKBAMFileSpan)thisIterator.next().getValue()).size();
            }
            else if(compareValue > 0) {
                // Other before this.
                difference += ((GATKBAMFileSpan)otherIterator.next().getValue()).size();
            }
            else {
                // equality; difference the values.
                GATKBAMFileSpan thisRegion = (GATKBAMFileSpan)thisIterator.next().getValue();
                GATKBAMFileSpan otherRegion = (GATKBAMFileSpan)otherIterator.next().getValue();
                difference += Math.abs(thisRegion.minus(otherRegion).size());
            }
        }
        return difference;
    }
View Full Code Here

     */
    private void mergeElementsInto(final FilePointer combined, Iterator<Map.Entry<SAMReaderID,SAMFileSpan>>... iterators) {
        if(iterators.length == 0)
            throw new ReviewedGATKException("Tried to add zero elements to an existing file pointer.");
        Map.Entry<SAMReaderID,SAMFileSpan> initialElement = iterators[0].next();
        GATKBAMFileSpan fileSpan = (GATKBAMFileSpan)initialElement.getValue();
        for(int i = 1; i < iterators.length; i++)
            fileSpan = fileSpan.union((GATKBAMFileSpan)iterators[i].next().getValue());
        combined.addFileSpans(initialElement.getKey(),fileSpan);
    }
View Full Code Here

            locations.addAll(filePointer.getLocations());
            if (mergeRule != filePointer.getIntervalMergingRule())
                throw new ReviewedGATKException("All FilePointers in FilePointer.union() must have use the same IntervalMergeRule");

            for ( Map.Entry<SAMReaderID, SAMFileSpan> fileSpanEntry : filePointer.getFileSpans().entrySet() ) {
                GATKBAMFileSpan fileSpan = (GATKBAMFileSpan)fileSpanEntry.getValue();

                if ( fileChunks.containsKey(fileSpanEntry.getKey()) ) {
                    fileChunks.get(fileSpanEntry.getKey()).addAll(fileSpan.getGATKChunks());
                }
                else {
                    fileChunks.put(fileSpanEntry.getKey(), fileSpan.getGATKChunks());
                }
            }
        }

        // Now sort and merge the intervals
        List<GenomeLoc> sortedMergedLocations = new ArrayList<GenomeLoc>();
        sortedMergedLocations.addAll(IntervalUtils.sortAndMergeIntervals(parser, locations, mergeRule));

        // For each BAM file, convert from an unsorted, unmerged list of chunks to a GATKBAMFileSpan containing
        // the sorted, merged union of the chunks for that file
        Map<SAMReaderID, SAMFileSpan> mergedFileSpans = new HashMap<SAMReaderID, SAMFileSpan>(fileChunks.size());
        for ( Map.Entry<SAMReaderID, List<GATKChunk>> fileChunksEntry : fileChunks.entrySet() ) {
            List<GATKChunk> unmergedChunks = fileChunksEntry.getValue();
            mergedFileSpans.put(fileChunksEntry.getKey(),
                                (new GATKBAMFileSpan(unmergedChunks.toArray(new GATKChunk[unmergedChunks.size()]))).union(new GATKBAMFileSpan()));
        }

        return new FilePointer(mergedFileSpans, mergeRule, sortedMergedLocations);
    }
View Full Code Here

     * @param other the FilePointer against which to check overlap with this FilePointer
     * @return true if any file spans overlap their counterparts in other, otherwise false
     */
    public boolean hasFileSpansOverlappingWith( FilePointer other ) {
        for ( Map.Entry<SAMReaderID, SAMFileSpan> thisFilePointerEntry : fileSpans.entrySet() ) {
            GATKBAMFileSpan thisFileSpan = new GATKBAMFileSpan(thisFilePointerEntry.getValue());

            SAMFileSpan otherEntry = other.fileSpans.get(thisFilePointerEntry.getKey());
            if ( otherEntry == null ) {
                continue// no counterpart for this file span in other
            }
            GATKBAMFileSpan otherFileSpan = new GATKBAMFileSpan(otherEntry);

            if ( thisFileSpan.getExtent().overlaps(otherFileSpan.getExtent()) ) {
                return true;
            }
        }

        return false;
View Full Code Here

        // [position,limit), while extra capacity exists in the range [limit,capacity)
        buffer.limit(0);

        this.dispatcher = dispatcher;
        // TODO: Kill the region when all we want to do is start at the beginning of the stream and run to the end of the stream.
        this.accessPlan = new BAMAccessPlan(reader,this,new GATKBAMFileSpan(new GATKChunk(0,Long.MAX_VALUE)));

        // The block offsets / block positions guarantee that the ending offset/position in the data structure maps to
        // the point in the file just following the last read.  These two arrays should never be empty; initializing
        // to 0 to match the position above.
        this.blockOffsets.add(0);
View Full Code Here

                    continue;
                }

                // Code at this point knows that the current bin is neither before nor after the current locus,
                // so it must overlap.  Add this region to the filesystem.
                final GATKBAMFileSpan fileSpan = indexData.getSpanOverlapping(bin);

                if(!fileSpan.isEmpty()) {
                    // File format is binary in little endian; start of region, end of region, num chunks, then the chunks themselves.
                    ByteBuffer buffer = allocateByteBuffer(2*INT_SIZE_IN_BYTES + INT_SIZE_IN_BYTES + fileSpan.getGATKChunks().size()*LONG_SIZE_IN_BYTES*2);
                    buffer.putInt(binStart);
                    buffer.putInt(binStop);
                    buffer.putInt(fileSpan.getGATKChunks().size());
                    for(GATKChunk chunk: fileSpan.getGATKChunks()) {
                        buffer.putLong(chunk.getChunkStart());
                        buffer.putLong(chunk.getChunkEnd());
                    }
                    maxChunkCount = Math.max(maxChunkCount,fileSpan.getGATKChunks().size());

                    // Prepare buffer for writing
                    buffer.flip();

                    // And write.
View Full Code Here

                scheduleIterator.next();
        }

        // For each schedule entry without data, add a blank entry.
        for (int reader = selectedIterators.nextClearBit(0); reader < readerIDs.size(); reader = selectedIterators.nextClearBit(reader+1)) {
            mergedScheduleEntry.addFileSpan(readerIDs.get(reader),new GATKBAMFileSpan());
        }

        nextScheduleEntry = mergedScheduleEntry;
    }
View Full Code Here

TOP

Related Classes of htsjdk.samtools.GATKBAMFileSpan

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.