Skip to content

Commit 56ee2bd

Browse files
fix: in bam record buffer, change the start of the window to the first added item in last iteration (#430)
* 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 <[email protected]>
1 parent d869fdd commit 56ee2bd

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/bam/buffer.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use std::str;
1111
use crate::bam;
1212
use crate::bam::Read;
1313
use crate::errors::{Error, Result};
14-
1514
/// A buffer for BAM records. This allows access regions in a sorted BAM file while iterating
1615
/// over it in a single pass.
1716
/// The buffer is implemented as a ringbuffer, such that extension or movement to the right has
@@ -25,6 +24,7 @@ pub struct RecordBuffer {
2524
cache_cigar: bool,
2625
min_refetch_distance: u64,
2726
buffer_record: Rc<bam::Record>,
27+
start_pos: Option<u64>,
2828
}
2929

3030
unsafe impl Sync for RecordBuffer {}
@@ -45,6 +45,7 @@ impl RecordBuffer {
4545
cache_cigar,
4646
min_refetch_distance: 1,
4747
buffer_record: Rc::new(bam::Record::new()),
48+
start_pos: Some(0),
4849
}
4950
}
5051

@@ -89,7 +90,7 @@ impl RecordBuffer {
8990
if self.inner.is_empty()
9091
|| window_start.saturating_sub(self.end().unwrap()) >= self.min_refetch_distance
9192
|| self.tid().unwrap() != tid as i32
92-
|| self.start().unwrap() > window_start
93+
|| self.start().unwrap() > self.start_pos.unwrap()
9394
{
9495
let end = self.reader.header.target_len(tid).unwrap();
9596
self.reader.fetch((tid, window_start, end))?;
@@ -145,6 +146,7 @@ impl RecordBuffer {
145146
added += 1;
146147
}
147148
}
149+
self.start_pos = Some(self.start().unwrap_or(window_start));
148150

149151
Ok((added, deleted))
150152
} else {

0 commit comments

Comments
 (0)