Skip to content
This repository has been archived by the owner on Dec 6, 2024. It is now read-only.

Commit

Permalink
try returning no r2 for single ended
Browse files Browse the repository at this point in the history
  • Loading branch information
govinda-kamath committed May 25, 2024
1 parent 8f39e91 commit 5ef45b8
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions src/read_pair_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use crate::read_pair::{MutReadPair, ReadPair, ReadPairStorage, ReadPart, WhichRead};
use bytes::{BufMut, BytesMut};
use fastq::{self, OwnedRecord, Record, RecordRefIter};
use fastq::{self, Record, RecordRefIter};
use rand::distributions::{Distribution, Uniform};
use rand::SeedableRng;
use rand_xorshift::XorShiftRng;
Expand Down Expand Up @@ -406,7 +406,7 @@ impl ReadPairIter {
iter.advance()
.fastq_err(paths[idx].as_ref().unwrap(), rec_num[idx] * 4)?;

let current_read_record = {
{
let record = iter.get();

// Check for non-ACGTN characters
Expand All @@ -433,8 +433,7 @@ impl ReadPairIter {
}

rec_num[idx] += 1;
record
};
}

// If R1 is interleaved, read another entry
// and store it as R2
Expand Down Expand Up @@ -475,16 +474,6 @@ impl ReadPairIter {
}

rec_num[idx] += 1;
} else if let Some(current_read_record) = current_read_record {
let read_length = read_lengths[WhichRead::R2 as usize];
let fake_r2_read = OwnedRecord {
head: current_read_record.head().to_owned(),
sep: Some(current_read_record.seq().to_owned()),
seq: vec![],
qual: vec![],
};
let tr = TrimRecord::new(&fake_r2_read, read_length);
rp.push_read(&tr, WhichRead::R2)
}
}

Check failure on line 478 in src/read_pair_iter.rs

View workflow job for this annotation

GitHub Actions / test

this `if` statement can be collapsed

error: this `if` statement can be collapsed --> src/read_pair_iter.rs:440:21 | 440 | / if idx == 0 && self.r1_interleaved && !iter_ended[idx] { 441 | | if !is_single_ended { 442 | | iter.advance() 443 | | .fastq_err(paths[idx].as_ref().unwrap(), (rec_num[idx] + 1) * 4)?; ... | 477 | | } 478 | | } | |_____________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_if note: the lint level is defined here --> src/lib.rs:12:9 | 12 | #![deny(warnings, unused)] | ^^^^^^^^ = note: `#[deny(clippy::collapsible_if)]` implied by `#[deny(warnings)]` help: collapse nested if block | 440 ~ if idx == 0 && self.r1_interleaved && !iter_ended[idx] && !is_single_ended { 441 + iter.advance() 442 + .fastq_err(paths[idx].as_ref().unwrap(), (rec_num[idx] + 1) * 4)?; 443 + let record = iter.get(); 444 + 445 + // Check for non-ACGTN characters 446 + if let Some(ref rec) = record { 447 + if !fastq::Record::validate_dnan(rec) { 448 + let msg = "FASTQ contains sequence base with character other than [ACGTN].".to_string(); 449 + let e = FastqError::format( 450 + msg, 451 + paths[idx].as_ref().unwrap(), 452 + rec_num[idx] * 4, 453 + ); 454 + return Err(e); 455 + } 456 + 457 + if sample { 458 + let which = WhichRead::read_types()[idx + 1]; 459 + let read_length = read_lengths[which as usize]; 460 + let tr = TrimRecord::new(rec, read_length); 461 + rp.push_read(&tr, which) 462 + } 463 + } else { 464 + // We should only hit this if the FASTQ has an odd 465 + // number of records. Throw an error 466 + let msg = "Input FASTQ file was input as interleaved R1 and R2, but contains an odd number of records".to_string(); 467 + let e = FastqError::format( 468 + msg, 469 + paths[idx].as_ref().unwrap(), 470 + rec_num[idx] * 4, 471 + ); 472 + return Err(e); 473 + } 474 + 475 + rec_num[idx] += 1; 476 + } |
}
Expand Down Expand Up @@ -653,6 +642,7 @@ mod test_read_pair_iter {

let res: Result<Vec<ReadPair>, FastqError> = it.collect();
assert!(res.is_ok());
println!("{:#?}", &res);
assert_eq!(res.unwrap().len(), 8);
}

Expand Down

0 comments on commit 5ef45b8

Please sign in to comment.