Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/bam/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,6 +24,7 @@ pub struct RecordBuffer {
cache_cigar: bool,
min_refetch_distance: u64,
buffer_record: Rc<bam::Record>,
start_pos: Option<u64>,
}

unsafe impl Sync for RecordBuffer {}
Expand All @@ -45,6 +45,7 @@ impl RecordBuffer {
cache_cigar,
min_refetch_distance: 1,
buffer_record: Rc::new(bam::Record::new()),
start_pos: Some(0),
}
}

Expand Down Expand Up @@ -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))?;
Expand Down Expand Up @@ -145,6 +146,7 @@ impl RecordBuffer {
added += 1;
}
}
self.start_pos = Some(self.start().unwrap_or(window_start));

Ok((added, deleted))
} else {
Expand Down