/** * @param slice */ void recordMetaData(Slice slice) { final int alignmentStart = slice.alignmentStart; if (alignmentStart == SAMRecord.NO_ALIGNMENT_START) { noCoordinateRecords+=slice.nofRecords; return; } final long start = slice.offset; final long end = slice.offset + 0; if (slice.alignmentSpan < 1) { unAlignedRecords += slice.nofRecords; } else { alignedRecords += slice.nofRecords; } if (BlockCompressedFilePointerUtil.compare(start, firstOffset) < 1 || firstOffset == -1) { this.firstOffset = start; } if (BlockCompressedFilePointerUtil.compare(lastOffset, end) < 1) { this.lastOffset = end; } }
/** * @param slice */ void recordMetaData(Slice slice) { final int alignmentStart = slice.alignmentStart; if (alignmentStart == SAMRecord.NO_ALIGNMENT_START) { noCoordinateRecords+=slice.nofRecords; return; } final long start = slice.offset; final long end = slice.offset + 0; if (slice.alignmentSpan < 1) { unAlignedRecords += slice.nofRecords; } else { alignedRecords += slice.nofRecords; } if (BlockCompressedFilePointerUtil.compare(start, firstOffset) < 1 || firstOffset == -1) { this.firstOffset = start; } if (BlockCompressedFilePointerUtil.compare(lastOffset, end) < 1) { this.lastOffset = end; } }
/** * Create the virtual file pointer, and also assert that is can be converted back into the input parameters. * @param blockAddress * @param blockOffset * @return block compressed file pointer */ private long makeFilePointer(long blockAddress, int blockOffset) { final long ret = BlockCompressedFilePointerUtil.makeFilePointer(blockAddress, blockOffset); Assert.assertEquals(BlockCompressedFilePointerUtil.getBlockAddress(ret), blockAddress); Assert.assertEquals(BlockCompressedFilePointerUtil.getBlockOffset(ret), blockOffset); Assert.assertEquals(BlockCompressedFilePointerUtil.compare(ret, ret), 0); return ret; }
@Test public void basicTest() { List<Long> pointers = new ArrayList<Long>(); pointers.add(makeFilePointer(0, 0)); pointers.add(makeFilePointer(0, BlockCompressedFilePointerUtil.MAX_OFFSET)); final long BIG_BLOCK_ADDRESS = 1L << 46; pointers.add(makeFilePointer(BIG_BLOCK_ADDRESS-1, 0)); pointers.add(makeFilePointer(BIG_BLOCK_ADDRESS-1, BlockCompressedFilePointerUtil.MAX_OFFSET)); pointers.add(makeFilePointer(BIG_BLOCK_ADDRESS, 0)); pointers.add(makeFilePointer(BIG_BLOCK_ADDRESS, BlockCompressedFilePointerUtil.MAX_OFFSET)); pointers.add(makeFilePointer(BlockCompressedFilePointerUtil.MAX_BLOCK_ADDRESS, 0)); pointers.add(makeFilePointer(BlockCompressedFilePointerUtil.MAX_BLOCK_ADDRESS, BlockCompressedFilePointerUtil.MAX_OFFSET)); for (int i = 0; i < pointers.size() - 1; ++i) { for (int j = i+1; j < pointers.size(); ++j) { Assert.assertTrue(BlockCompressedFilePointerUtil.compare(pointers.get(i), pointers.get(j)) < 0, BlockCompressedFilePointerUtil.asString(pointers.get(i)) + " should be < " + BlockCompressedFilePointerUtil.asString(pointers.get(j))); Assert.assertTrue(BlockCompressedFilePointerUtil.compare(pointers.get(j), pointers.get(i)) > 0, BlockCompressedFilePointerUtil.asString(pointers.get(j)) + " should be > " + BlockCompressedFilePointerUtil.asString(pointers.get(i))); } } }
/** * Extract relevant metaData from the record and its filePointer * Call only once per record in the file being indexed * * @param rec */ void recordMetaData(final SAMRecord rec) { final int alignmentStart = rec.getAlignmentStart(); if (alignmentStart == SAMRecord.NO_ALIGNMENT_START) { incrementNoCoordinateRecordCount(); return; } if (rec.getFileSource() == null) { throw new SAMException("BAM cannot be indexed without setting a fileSource for record " + rec); } final Chunk newChunk = ((BAMFileSpan) rec.getFileSource().getFilePointer()).getSingleChunk(); final long start = newChunk.getChunkStart(); final long end = newChunk.getChunkEnd(); if (rec.getReadUnmappedFlag()) { unAlignedRecords++; } else { alignedRecords++; } if (BlockCompressedFilePointerUtil.compare(start, firstOffset) < 1 || firstOffset == -1) { this.firstOffset = start; } if (BlockCompressedFilePointerUtil.compare(lastOffset, end) < 1) { this.lastOffset = end; } }
/** * Extract relevant metaData from the record and its filePointer * Call only once per record in the file being indexed * * @param rec */ void recordMetaData(final SAMRecord rec) { final int alignmentStart = rec.getAlignmentStart(); if (alignmentStart == SAMRecord.NO_ALIGNMENT_START) { incrementNoCoordinateRecordCount(); return; } if (rec.getFileSource() == null) { throw new SAMException("BAM cannot be indexed without setting a fileSource for record " + rec); } final Chunk newChunk = ((BAMFileSpan) rec.getFileSource().getFilePointer()).getSingleChunk(); final long start = newChunk.getChunkStart(); final long end = newChunk.getChunkEnd(); if (rec.getReadUnmappedFlag()) { unAlignedRecords++; } else { alignedRecords++; } if (BlockCompressedFilePointerUtil.compare(start, firstOffset) < 1 || firstOffset == -1) { this.firstOffset = start; } if (BlockCompressedFilePointerUtil.compare(lastOffset, end) < 1) { this.lastOffset = end; } }
/** * Extract relevant metaData from the record and its filePointer * Call only once per record in the file being indexed * * @param rec */ void recordMetaData(final SAMRecord rec) { final int alignmentStart = rec.getAlignmentStart(); if (alignmentStart == SAMRecord.NO_ALIGNMENT_START) { incrementNoCoordinateRecordCount(); return; } if (rec.getFileSource() == null){ throw new SAMException("BAM cannot be indexed without setting a fileSource for record " + rec); } final Chunk newChunk = ((BAMFileSpan) rec.getFileSource().getFilePointer()).getSingleChunk(); final long start = newChunk.getChunkStart(); final long end = newChunk.getChunkEnd(); if (rec.getReadUnmappedFlag()) { unAlignedRecords++; } else { alignedRecords++; } if (BlockCompressedFilePointerUtil.compare(start, firstOffset) < 1 || firstOffset == -1) { this.firstOffset = start; } if (BlockCompressedFilePointerUtil.compare(lastOffset, end) < 1) { this.lastOffset = end; } }