Skip to content

Commit f6dfec9

Browse files
authored
Merge pull request #61 from rickbeeloo/record-fix
Fix missing last qual char in case of no newline at eof
2 parents baa0001 + 9fe6fe9 commit f6dfec9

3 files changed

Lines changed: 14 additions & 34 deletions

File tree

.github/workflows/ci.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
name: Rust
22

3-
on: push
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
48

59
env:
610
CARGO_TERM_COLOR: always

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "paraseq"
3-
version = "0.4.9"
3+
version = "0.4.10"
44
edition = "2021"
55
authors = ["Noam Teyssier"]
66
keywords = ["fasta", "fastq", "parser", "parallel", "paired"]

src/fastq.rs

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -391,14 +391,13 @@ impl RecordSet {
391391

392392
// Split out record processing to separate function
393393
fn process_records<R: io::Read>(&mut self, reader: &mut Reader<R>) -> Result<bool, Error> {
394-
let mut available_complete = self.newlines.len() / 4;
395-
396394
// At EOF, check if we have exactly 3 newlines remaining (final record without trailing newline)
397-
let has_final_incomplete = reader.eof && (self.newlines.len() % 4 == 3);
398-
if has_final_incomplete {
399-
available_complete += 1;
395+
if reader.eof && self.newlines.len() % 4 == 3 {
396+
// If we just have 3 lines (no trailing newline), add a synthetic newline to the buffer
397+
self.buffer.push(b'\n');
398+
self.find_newlines(self.buffer.len());
400399
}
401-
400+
let available_complete = self.newlines.len() / 4;
402401
let records_to_process = available_complete.min(self.capacity);
403402

404403
if records_to_process > 0 {
@@ -409,7 +408,7 @@ impl RecordSet {
409408
// Process complete records with 4 newlines
410409
self.newlines
411410
.chunks_exact(4)
412-
.take(records_to_process.saturating_sub(if has_final_incomplete { 1 } else { 0 }))
411+
.take(records_to_process)
413412
.for_each(|chunk| {
414413
let (seq_start, sep_start, qual_start, end) =
415414
(chunk[0], chunk[1], chunk[2], chunk[3]);
@@ -425,30 +424,7 @@ impl RecordSet {
425424
record_start = end;
426425
last_end = end;
427426
});
428-
429-
// Handle final record with only 3 newlines at EOF
430-
if has_final_incomplete {
431-
let remaining = self.newlines.len() % 4;
432-
let start_idx = self.newlines.len() - remaining;
433-
let (seq_start, sep_start, qual_start) = (
434-
self.newlines[start_idx],
435-
self.newlines[start_idx + 1],
436-
self.newlines[start_idx + 2],
437-
);
438-
439-
self.positions.push(Positions {
440-
start: record_start,
441-
seq_start,
442-
sep_start,
443-
qual_start,
444-
qual_end: self.buffer.len(),
445-
end: self.buffer.len(),
446-
});
447-
last_end = self.buffer.len();
448-
}
449-
450427
self.update_avg_record_size(last_end);
451-
452428
// Move remaining partial data to overflow
453429
reader.overflow.extend_from_slice(&self.buffer[last_end..]);
454430
self.buffer.truncate(last_end);
@@ -729,9 +705,9 @@ mod tests {
729705
assert!(record_set.fill(&mut reader).unwrap());
730706

731707
for record in record_set.iter() {
732-
println!("Record: {:?}", record);
708+
let record = record.unwrap();
709+
assert_eq!(record.seq().len(), record.qual().unwrap().len());
733710
}
734-
735711
assert!(record_set.iter().next().unwrap().is_ok());
736712
}
737713

0 commit comments

Comments
 (0)