Skip to content

Commit

Permalink
Fixed bug where final reads were skipped
Browse files Browse the repository at this point in the history
  • Loading branch information
olliecheng committed Dec 11, 2024
1 parent e7891ed commit 6b93d25
Show file tree
Hide file tree
Showing 2 changed files with 338 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,18 @@ pub fn consensus(
) -> Result<()> {
rayon::ThreadPoolBuilder::new().num_threads(threads).build_global()?;

let duplicate_iterator = iter_duplicates(input, duplicates, duplicates_only)?;
let mut duplicate_iterator = iter_duplicates(input, duplicates, duplicates_only)?
.peekable();

let chunk_size = 100usize * threads;

let mut chunk_buffer = Vec::with_capacity(chunk_size);
let mut duplicate_buffer = Vec::new();

for (idx, elem) in duplicate_iterator.enumerate() {
let mut idx = 0;
while let Some(elem) = duplicate_iterator.next() {
idx += 1;

if (idx > 0) && (idx % 100000 == 0) {
eprintln!("Called {} reads...", idx);
}
Expand All @@ -67,8 +71,10 @@ pub fn consensus(
duplicate_buffer.push(group);
}

// if we have filled the buffer, then, process it
if chunk_buffer.len() == chunk_size {
let end_of_buffer = duplicate_iterator.peek().is_none();

// if we have filled the buffer OR are at the end, process this
if (chunk_buffer.len() == chunk_size) || end_of_buffer {
let mut duplicate_output = Vec::with_capacity(duplicate_buffer.len());

// generate new records into a separate buffer
Expand Down
Loading

0 comments on commit 6b93d25

Please sign in to comment.