public long getBlockStart() { return getChunkStart() >>> 16; }
public int getBlockOffsetStart() { return (int)(getChunkStart() & 0xFFFF); }
/** * Computes an approximation of the uncompressed size of the * chunk, in bytes. Can be used to determine relative weights * of chunk size. * @return An approximation of the chunk size in bytes. */ public long size() { final long chunkSpan = Math.round(((getChunkEnd()>>16)-(getChunkStart()>>16))/AVERAGE_BAM_COMPRESSION_RATIO); final int offsetSpan = (int)((getChunkEnd()&0xFFFF)-(getChunkStart()&0xFFFF)); return chunkSpan + offsetSpan; }
/** * Merges two chunks together. The caller is responsible for testing whether the * chunks overlap/are adjacent before calling this method! * * @param other the chunk to merge with this chunk * @return a new chunk representing the union of the two chunks (provided the chunks were * overlapping/adjacent) */ public GATKChunk merge ( GATKChunk other ) { return new GATKChunk(Math.min(getChunkStart(), other.getChunkStart()), Math.max(getChunkEnd(), other.getChunkEnd())); } }
@Override public GATKChunk clone() { return new GATKChunk(getChunkStart(),getChunkEnd()); }
if(thisChunk.getChunkEnd() <= otherChunk.getChunkStart()) { subtracted.add(thisChunk); thisChunk = thisIterator.hasNext() ? thisIterator.next() : null; if(thisChunk.getChunkStart() >= otherChunk.getChunkEnd()) { otherChunk = otherIterator.hasNext() ? otherIterator.next() : null; continue; if(thisChunk.getChunkStart() < otherChunk.getChunkStart()) subtracted.add(new GATKChunk(thisChunk.getChunkStart(),otherChunk.getChunkStart()));
if(thisChunk.getChunkEnd() <= otherChunk.getChunkStart()) { thisChunk = thisIterator.hasNext() ? thisIterator.next() : null; continue; if(thisChunk.getChunkStart() >= otherChunk.getChunkEnd()) { otherChunk = otherIterator.hasNext() ? otherIterator.next() : null; continue; GATKChunk firstChunk = thisChunk.getChunkStart() < otherChunk.getChunkStart() ? thisChunk : otherChunk; GATKChunk secondChunk = thisChunk==firstChunk ? otherChunk : thisChunk; GATKChunk intersectedChunk = new GATKChunk(secondChunk.getChunkStart(),Math.min(firstChunk.getChunkEnd(),secondChunk.getChunkEnd())); intersected.add(intersectedChunk);
blockOffsets.add(buffer.position()); blockPositions.removeLast(); blockPositions.add(spanOverlapping.getChunkStart());
/** * Generate a span that runs from the end of the BAM header to the end of the fle. * @return A file pointer over the specified region. */ private FilePointer generatePointerOverEntireFileset() { FilePointer filePointer = new FilePointer(intervalMergingRule); // This is a "monolithic" FilePointer representing all regions in all files we will ever visit, and is // the only FilePointer we will create. This allows us to have this FilePointer represent regions from // multiple contigs filePointer.setIsMonolithic(true); Map<SAMReaderID,GATKBAMFileSpan> currentPosition; currentPosition = dataSource.getInitialReaderPositions(); for(SAMReaderID reader: dataSource.getReaderIDs()) filePointer.addFileSpans(reader,createSpanToEndOfFile(currentPosition.get(reader).getGATKChunks().get(0).getChunkStart())); return filePointer; }
buffer.putInt(fileSpan.getGATKChunks().size()); for(GATKChunk chunk: fileSpan.getGATKChunks()) { buffer.putLong(chunk.getChunkStart()); buffer.putLong(chunk.getChunkEnd());
/** * Advances the current position to the next block to read, given the current position in the file. * @param filePosition The current position within the file. */ void advancePosition(final long filePosition) { nextBlockAddress = BlockCompressedFilePointerUtil.getBlockAddress(filePosition); // Check the current file position against the iterator; if the iterator is before the current file position, // draw the iterator forward. Remember when performing the check that coordinates are half-open! while(positionIterator.hasNext() && isFilePositionPastEndOfChunk(filePosition,positionIterator.peek())) positionIterator.next(); // If the block iterator has shot past the file pointer, bring the file pointer flush with the start of the current block. if(positionIterator.hasNext() && filePosition < positionIterator.peek().getChunkStart()) nextBlockAddress = positionIterator.peek().getBlockStart(); // If we've shot off the end of the block pointer, notify consumers that iteration is complete. if(!positionIterator.hasNext()) nextBlockAddress = -1; }
if(newChunk.getChunkStart() <= newChunk.getChunkEnd()) spansOverlapping.add(new GATKChunk(blockAddress,blockOffsetStart,blockEnd,blockOffsetEnd));