/** * Deep clone the given chunk list. * @return A copy of the chunk list. */ public BAMFileSpan clone() { final BAMFileSpan clone = new BAMFileSpan(); for(final Chunk chunk: chunks) clone.chunks.add(chunk.clone()); return clone; }
@Override public BAMFileSpan getSpanOverlapping(Bin bin) { return new BAMFileSpan(getBinChunks(bin)); }
/** * Deep clone the given chunk list. * @return A copy of the chunk list. */ @Override public BAMFileSpan clone() { final BAMFileSpan clone = new BAMFileSpan(); for(final Chunk chunk: chunks) clone.chunks.add(chunk.clone()); return clone; }
/** * Gets an unbounded pointer to the first record in the BAM file. Because the reader doesn't necessarily know * when the file ends, the rightmost bound of the file pointer will not end exactly where the file ends. However, * the rightmost bound is guaranteed to be after the last read in the file. * @return An unbounded pointer to the first record in the BAM file. */ @Override public SAMFileSpan getFilePointerSpanningReads() { return new BAMFileSpan(new Chunk(mFirstRecordPointer,Long.MAX_VALUE)); }
/** * Gets an unbounded pointer to the first record in the BAM file. Because the reader doesn't necessarily know * when the file ends, the rightmost bound of the file pointer will not end exactly where the file ends. However, * the rightmost bound is guaranteed to be after the last read in the file. * @return An unbounded pointer to the first record in the BAM file. */ @Override public SAMFileSpan getFilePointerSpanningReads() { return new BAMFileSpan(new Chunk(mFirstRecordPointer,Long.MAX_VALUE)); }
/** * Gets an unbounded pointer to the first record in the BAM file. Because the reader doesn't necessarily know * when the file ends, the rightmost bound of the file pointer will not end exactly where the file ends. However, * the rightmost bound is guaranteed to be after the last read in the file. * @return An unbounded pointer to the first record in the BAM file. */ @Override public SAMFileSpan getFilePointerSpanningReads() { return new BAMFileSpan(new Chunk(mFirstRecordPointer,Long.MAX_VALUE)); }
/** * Gets an unbounded pointer to the first record in the BAM file. Because the reader doesn't necessarily know * when the file ends, the rightmost bound of the file pointer will not end exactly where the file ends. However, * the rightmost bound is guaranteed to be after the last read in the file. * @return An unbounded pointer to the first record in the BAM file. */ @Override public SAMFileSpan getFilePointerSpanningReads() { return new BAMFileSpan(new Chunk(mFirstRecordPointer,Long.MAX_VALUE)); }
@Override public SAMFileSpan getFilePointerSpanningReads() { return new BAMFileSpan(new Chunk(iterator.firstContainerOffset << 16, Long.MAX_VALUE)); }
/** * Gets a file span over the data immediately following this span. * @return The a pointer to data immediately following this span. */ public SAMFileSpan getContentsFollowing() { if(chunks.isEmpty()) throw new SAMException("Unable to get the file pointer following this one: no data present."); validateSorted(); return new BAMFileSpan(new Chunk(chunks.get(chunks.size()-1).getChunkEnd(),Long.MAX_VALUE)); }
/** * Gets a file span over the data immediately following this span. * @return The a pointer to data immediately following this span. */ @Override public SAMFileSpan getContentsFollowing() { if(chunks.isEmpty()) throw new SAMException("Unable to get the file pointer following this one: no data present."); validateSorted(); return new BAMFileSpan(new Chunk(chunks.get(chunks.size()-1).getChunkEnd(),Long.MAX_VALUE)); }
@Override public SAMFileSpan getFilePointerSpanningReads() { if (recordRangeInfo.getTotalRecordRangeLength() <= 0) { throw new RuntimeException("Cannot create file span - SRA file is empty"); } return new BAMFileSpan(new Chunk(0, recordRangeInfo.getTotalRecordRangeLength())); }
@Override public SAMFileSpan getFilePointerSpanningReads() { if (recordRangeInfo.getTotalRecordRangeLength() <= 0) { throw new RuntimeException("Cannot create file span - SRA file is empty"); } return new BAMFileSpan(new Chunk(0, recordRangeInfo.getTotalRecordRangeLength())); }
@Override public CloseableIterator<SAMRecord> getIterator() { // BGZ file pointers are of the form block/offset where the high 48 bits of the 64 bit value // are block location in the file. long offsetFilePointer = offset << 16; BAMFileSpan spanStartingFromOffset = new BAMFileSpan(new Chunk(offsetFilePointer, Long.MAX_VALUE)); return getIterator(spanStartingFromOffset); } }
@Override public CloseableIterator<SAMRecord> getIterator() { // BGZ file pointers are of the form block/offset where the high 48 bits of the 64 bit value // are block location in the file. long offsetFilePointer = offset << 16; BAMFileSpan spanStartingFromOffset = new BAMFileSpan(new Chunk(offsetFilePointer, Long.MAX_VALUE)); return getIterator(spanStartingFromOffset); } }
/** * Read the next record from the input stream. */ SAMRecord getNextRecord() throws IOException { final long startCoordinate = mCompressedInputStream.getFilePointer(); final SAMRecord next = bamRecordCodec.decode(); final long stopCoordinate = mCompressedInputStream.getFilePointer(); if(mReader != null && next != null) next.setFileSource(new SAMFileSource(mReader,new BAMFileSpan(new Chunk(startCoordinate,stopCoordinate)))); return next; }
/** * Read the next record from the input stream. */ SAMRecord getNextRecord() throws IOException { final long startCoordinate = mCompressedInputStream.getFilePointer(); final SAMRecord next = bamRecordCodec.decode(); final long stopCoordinate = mCompressedInputStream.getFilePointer(); if(mReader != null && next != null) next.setFileSource(new SAMFileSource(mReader,new BAMFileSpan(new Chunk(startCoordinate,stopCoordinate)))); return next; }
@Override public CloseableIterator<SAMRecord> queryUnmapped() { if (recordRangeInfo.getTotalRecordRangeLength() <= 0) { throw new RuntimeException("Cannot create file span - SRA file is empty"); } SAMFileSpan span = new BAMFileSpan(new Chunk(recordRangeInfo.getTotalReferencesLength(), recordRangeInfo.getTotalRecordRangeLength())); return getIterator(span); }
@Override public CloseableIterator<SAMRecord> queryUnmapped() { if (recordRangeInfo.getTotalRecordRangeLength() <= 0) { throw new RuntimeException("Cannot create file span - SRA file is empty"); } SAMFileSpan span = new BAMFileSpan(new Chunk(recordRangeInfo.getTotalReferencesLength(), recordRangeInfo.getTotalRecordRangeLength())); return getIterator(span); }
private List<SAMRecord> getReadsInChunk(final File bamFile, final Chunk chunk) { try (CloseableIterator<SAMRecord> iterator = bamFileReader(bamFile).getIterator(new BAMFileSpan(chunk))) { return Iterables.slurp(iterator); } } }
private SAMRecord getReadAtOffset(final File bamFile, final long virtualOffset) { final Chunk chunk = new Chunk(virtualOffset, BlockCompressedFilePointerUtil.makeFilePointer(bamFile.length())); try (CloseableIterator<SAMRecord> iterator = bamFileReader(bamFile).getIterator(new BAMFileSpan(chunk))) { Assert.assertTrue(iterator.hasNext()); return iterator.next(); } }