From 56ee2bd562788dad0dc8516d0e3db90ffa916320 Mon Sep 17 00:00:00 2001 From: Addimator <44083468+Addimator@users.noreply.github.com> Date: Fri, 10 May 2024 13:38:50 +0200 Subject: [PATCH] fix: in bam record buffer, change the start of the window to the first added item in last iteration (#430) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Change the start of the window to the first added item in last iteration * Change linting * Pay attention when start_pos is None * Change location of start_pos update * Remove debug infos * fmt * Change to make rust clippy happy --------- Co-authored-by: Johannes Köster --- src/bam/buffer.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/bam/buffer.rs b/src/bam/buffer.rs index 07bd17d35..2bf41d589 100644 --- a/src/bam/buffer.rs +++ b/src/bam/buffer.rs @@ -11,7 +11,6 @@ use std::str; use crate::bam; use crate::bam::Read; use crate::errors::{Error, Result}; - /// A buffer for BAM records. This allows access regions in a sorted BAM file while iterating /// over it in a single pass. /// The buffer is implemented as a ringbuffer, such that extension or movement to the right has @@ -25,6 +24,7 @@ pub struct RecordBuffer { cache_cigar: bool, min_refetch_distance: u64, buffer_record: Rc, + start_pos: Option, } unsafe impl Sync for RecordBuffer {} @@ -45,6 +45,7 @@ impl RecordBuffer { cache_cigar, min_refetch_distance: 1, buffer_record: Rc::new(bam::Record::new()), + start_pos: Some(0), } } @@ -89,7 +90,7 @@ impl RecordBuffer { if self.inner.is_empty() || window_start.saturating_sub(self.end().unwrap()) >= self.min_refetch_distance || self.tid().unwrap() != tid as i32 - || self.start().unwrap() > window_start + || self.start().unwrap() > self.start_pos.unwrap() { let end = self.reader.header.target_len(tid).unwrap(); self.reader.fetch((tid, window_start, end))?; @@ -145,6 +146,7 @@ impl RecordBuffer { added += 1; } } + self.start_pos = Some(self.start().unwrap_or(window_start)); Ok((added, deleted)) } else {