/** * @return true if vfp2 points to somewhere in the same BGZF block, or the one immediately following vfp1's BGZF block. */ public static boolean areInSameOrAdjacentBlocks(final long vfp1, final long vfp2) { final long block1 = getBlockAddress(vfp1); final long block2 = getBlockAddress(vfp2); return (block1 == block2 || block1 + 1 == block2); }
/** * @return true if vfp2 points to somewhere in the same BGZF block, or the one immediately following vfp1's BGZF block. */ public static boolean areInSameOrAdjacentBlocks(final long vfp1, final long vfp2) { final long block1 = getBlockAddress(vfp1); final long block2 = getBlockAddress(vfp2); return (block1 == block2 || block1 + 1 == block2); }
/** * @return true if vfp2 points to somewhere in the same BGZF block, or the one immediately following vfp1's BGZF block. */ public static boolean areInSameOrAdjacentBlocks(final long vfp1, final long vfp2) { final long block1 = getBlockAddress(vfp1); final long block2 = getBlockAddress(vfp2); return (block1 == block2 || block1 + 1 == block2); }
public static long getFileBlock(final long bgzfOffset) { return BlockCompressedFilePointerUtil.getBlockAddress(bgzfOffset); }
public static long getFileBlock(final long bgzfOffset) { return BlockCompressedFilePointerUtil.getBlockAddress(bgzfOffset); }
public static long getFileBlock(final long bgzfOffset) { return BlockCompressedFilePointerUtil.getBlockAddress(bgzfOffset); }
public static long getFileBlock(final long bgzfOffset) { return BlockCompressedFilePointerUtil.getBlockAddress(bgzfOffset); }
private static long shiftVirtualFilePointer(long virtualFilePointer, long offset) { long blockAddress = BlockCompressedFilePointerUtil.getBlockAddress(virtualFilePointer); int blockOffset = BlockCompressedFilePointerUtil.getBlockOffset(virtualFilePointer); return (blockAddress + offset) << 16 | (long) blockOffset; } }
private static long shiftVirtualFilePointer(long virtualFilePointer, long offset) { long blockAddress = BlockCompressedFilePointerUtil.getBlockAddress(virtualFilePointer); int blockOffset = BlockCompressedFilePointerUtil.getBlockOffset(virtualFilePointer); return (blockAddress + offset) << 16 | (long) blockOffset; } }
private static long shiftVirtualFilePointer(long virtualFilePointer, long offset) { long blockAddress = BlockCompressedFilePointerUtil.getBlockAddress(virtualFilePointer); int blockOffset = BlockCompressedFilePointerUtil.getBlockOffset(virtualFilePointer); return (blockAddress + offset) << 16 | (long) blockOffset; } }
public static String asString(final long vfp) { return String.format("%d(0x%x): (block address: %d, offset: %d)", vfp, vfp, getBlockAddress(vfp), getBlockOffset(vfp)); } }
public static String asString(final long vfp) { return String.format("%d(0x%x): (block address: %d, offset: %d)", vfp, vfp, getBlockAddress(vfp), getBlockOffset(vfp)); } }
public static String asString(final long vfp) { return String.format("%d(0x%x): (block address: %d, offset: %d)", vfp, vfp, getBlockAddress(vfp), getBlockOffset(vfp)); } }
/** * Returns whether two chunks overlap. * @param other Chunk to which this should be compared. * @return True if the two chunks are adjacent. Returns false if the chunks overlap or are discontinuous. */ public boolean isAdjacentTo(final Chunk other) { // Simpler implementation would be to == the chunk end of one to the chunk start of the other. Chose this implementation to ensure that all chunk // comparisons point directly to the return (BlockCompressedFilePointerUtil.getBlockAddress(this.getChunkEnd()) == BlockCompressedFilePointerUtil.getBlockAddress(other.getChunkStart()) && BlockCompressedFilePointerUtil.getBlockOffset(this.getChunkEnd()) == BlockCompressedFilePointerUtil.getBlockOffset(other.getChunkStart())) || (BlockCompressedFilePointerUtil.getBlockAddress(this.getChunkStart()) == BlockCompressedFilePointerUtil.getBlockAddress(other.getChunkEnd()) && BlockCompressedFilePointerUtil.getBlockOffset(this.getChunkStart()) == BlockCompressedFilePointerUtil.getBlockOffset(other.getChunkEnd())); }
/** * Returns whether two chunks overlap. * @param other Chunk to which this should be compared. * @return True if the two chunks are adjacent. Returns false if the chunks overlap or are discontinuous. */ public boolean isAdjacentTo(final Chunk other) { // Simpler implementation would be to == the chunk end of one to the chunk start of the other. Chose this implementation to ensure that all chunk // comparisons point directly to the return (BlockCompressedFilePointerUtil.getBlockAddress(this.getChunkEnd()) == BlockCompressedFilePointerUtil.getBlockAddress(other.getChunkStart()) && BlockCompressedFilePointerUtil.getBlockOffset(this.getChunkEnd()) == BlockCompressedFilePointerUtil.getBlockOffset(other.getChunkStart())) || (BlockCompressedFilePointerUtil.getBlockAddress(this.getChunkStart()) == BlockCompressedFilePointerUtil.getBlockAddress(other.getChunkEnd()) && BlockCompressedFilePointerUtil.getBlockOffset(this.getChunkStart()) == BlockCompressedFilePointerUtil.getBlockOffset(other.getChunkEnd())); }
/** * Returns whether two chunks overlap. * @param other Chunk to which this should be compared. * @return True if the two chunks are adjacent. Returns false if the chunks overlap or are discontinuous. */ public boolean isAdjacentTo(final Chunk other) { // Simpler implementation would be to == the chunk end of one to the chunk start of the other. Chose this implementation to ensure that all chunk // comparisons point directly to the return (BlockCompressedFilePointerUtil.getBlockAddress(this.getChunkEnd()) == BlockCompressedFilePointerUtil.getBlockAddress(other.getChunkStart()) && BlockCompressedFilePointerUtil.getBlockOffset(this.getChunkEnd()) == BlockCompressedFilePointerUtil.getBlockOffset(other.getChunkStart())) || (BlockCompressedFilePointerUtil.getBlockAddress(this.getChunkStart()) == BlockCompressedFilePointerUtil.getBlockAddress(other.getChunkEnd()) && BlockCompressedFilePointerUtil.getBlockOffset(this.getChunkStart()) == BlockCompressedFilePointerUtil.getBlockOffset(other.getChunkEnd())); }
@Test(dataProvider = "virtualOffsetForSeekData") public void testGetVirtualOffsetForSeek(final long uncompressedOffset, final long expectedBlockAddress, final long expectedBlockOffset, final GZIIndex index) throws Exception { final long virtualOffset = index.getVirtualOffsetForSeek(uncompressedOffset); Assert.assertEquals(BlockCompressedFilePointerUtil.getBlockAddress(virtualOffset), expectedBlockAddress); Assert.assertEquals(BlockCompressedFilePointerUtil.getBlockOffset(virtualOffset), expectedBlockOffset); }
/** * 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; }
private long populateMultiBlockCompressedFile(final File tempBlockCompressedFile) throws IOException { long sentinelLineOffset = -1; try (BlockCompressedOutputStream bcos = new BlockCompressedOutputStream(tempBlockCompressedFile)) { // write lines until we exceed the size of the first block (block address != 0) do { bcos.write("Write this line enough times to exceed the size or a compressed block\n".getBytes()); } while (BlockCompressedFilePointerUtil.getBlockAddress(bcos.getFilePointer()) == 0); sentinelLineOffset = bcos.getFilePointer(); // write a terminating line that is guaranteed to not be in the first block bcos.write(sentinelLine.getBytes()); } return sentinelLineOffset; } }
@Test(dataProvider = "gzippedBedTestData") public void testReadActualHeader(final File gzippedBedFile, final int firstFeatureOffset) throws IOException { // Given an indexable SOURCE on a BED file, test that readActualHeader retains the correct offset // of the first feature, whether there is a header or not BEDCodec bedCodec = new BEDCodec(); try (final InputStream is = ParsingUtils.openInputStream(gzippedBedFile.getPath()); final BlockCompressedInputStream bcis = new BlockCompressedInputStream(is)) { AsciiLineReaderIterator it = (AsciiLineReaderIterator) bedCodec.makeIndexableSourceFromStream(bcis); Object header = bedCodec.readActualHeader(it); // BEDCodec doesn't model or return the BED header, even when there is one! Assert.assertNull(header); Assert.assertEquals(BlockCompressedFilePointerUtil.getBlockAddress(it.getPosition()), 0); Assert.assertEquals(BlockCompressedFilePointerUtil.getBlockOffset(it.getPosition()), firstFeatureOffset); } }