From 7443237129aee4b0f043d929c0b2ad51f62f567a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciara=CC=81n=20O=E2=80=99Mara?= Date: Sun, 16 May 2021 12:20:55 +1000 Subject: [PATCH] Adjust BGZFStreams.virtualoffset https://github.com/BioJulia/BGZFStreams.jl/issues/22#issuecomment-874491338 --- src/bam/bam.jl | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/bam/bam.jl b/src/bam/bam.jl index 6fd1174..09552ae 100644 --- a/src/bam/bam.jl +++ b/src/bam/bam.jl @@ -15,6 +15,22 @@ import BioGenerics: isfilled, header import GenomicFeatures: eachoverlap +# Overwrite virtualoffset method as per https://github.com/BioJulia/BGZFStreams.jl/issues/22#issuecomment-874491338. +function BGZFStreams.virtualoffset(stream::BGZFStreams.BGZFStream) + if stream.mode == BGZFStreams.READ_MODE + i = BGZFStreams.ensure_buffered_data(stream) + if i == 0 + # Provide a VirtualOffset beyond the bounds of the stream. + block = stream.blocks[end] + return BGZFStreams.VirtualOffset(block.block_offset, 0) + (block.position - 1) + else + block = stream.blocks[i] + end + else + block = stream.blocks[1] + end + return BGZFStreams.VirtualOffset(block.block_offset, block.position - 1) +end include("bai.jl") include("auxdata.jl")