diff --git a/Cargo.lock b/Cargo.lock index 24a5900..36b5f96 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -212,7 +212,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chopper" -version = "0.7.0" +version = "0.7.1" dependencies = [ "approx", "bio", diff --git a/Cargo.toml b/Cargo.toml index e85a6c4..018247e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "chopper" -version = "0.7.0" +version = "0.7.1" authors = ["wdecoster "] edition = "2021" diff --git a/src/main.rs b/src/main.rs index 75fe4b8..77be5b1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -78,7 +78,7 @@ where let mut output_reads = 0; let aligner = setup_contamination_filter(fas); fastq::Reader::new(input).records().for_each(|record| { - let record = record.unwrap(); + let record = record.expect("ERROR: problem parsing fastq record"); total_reads += 1; if !record.is_empty() { let read_len = record.seq().len(); @@ -86,16 +86,18 @@ where if args.headcrop + args.tailcrop < read_len { let average_quality = ave_qual(&record.qual().iter().map(|i| i - 33).collect::>()); - if (!args.inverse && average_quality >= args.minqual + if (!args.inverse + && average_quality >= args.minqual && average_quality <= args.maxqual && read_len >= args.minlength && read_len <= args.maxlength && !is_contamination(&record.seq(), &aligner)) - || (args.inverse && (average_quality < args.minqual - || average_quality > args.maxqual - || read_len < args.minlength - || read_len > args.maxlength - || is_contamination(&record.seq(), &aligner))) + || (args.inverse + && (average_quality < args.minqual + || average_quality > args.maxqual + || read_len < args.minlength + || read_len > args.maxlength + || is_contamination(&record.seq(), &aligner))) { write_record(record, &args, read_len); output_reads += 1; @@ -112,12 +114,12 @@ where rayon::ThreadPoolBuilder::new() .num_threads(args.threads) .build_global() - .unwrap(); + .expect("Error: Unable to build threadpool"); fastq::Reader::new(input) .records() .par_bridge() .for_each(|record| { - let record = record.unwrap(); + let record = record.expect("ERROR: problem parsing fastq record"); total_reads_.fetch_add(1, Ordering::SeqCst); if !record.is_empty() { let read_len = record.seq().len(); @@ -126,14 +128,16 @@ where let average_quality = ave_qual( &record.qual().iter().map(|i| i - 33).collect::>(), ); - if (!args.inverse && average_quality >= args.minqual + if (!args.inverse + && average_quality >= args.minqual && average_quality <= args.maxqual && read_len >= args.minlength && read_len <= args.maxlength) - || (args.inverse && (average_quality < args.minqual - || average_quality > args.maxqual - || read_len < args.minlength - || read_len > args.maxlength)) + || (args.inverse + && (average_quality < args.minqual + || average_quality > args.maxqual + || read_len < args.minlength + || read_len > args.maxlength)) { write_record(record, &args, read_len); output_reads_.fetch_add(1, Ordering::SeqCst); @@ -159,8 +163,10 @@ fn write_record(record: fastq::Record, args: &Cli, read_len: usize) { println!( "@{}\n{}\n+\n{}", header, - std::str::from_utf8(&record.seq()[args.headcrop..read_len - args.tailcrop]).unwrap(), - std::str::from_utf8(&record.qual()[args.headcrop..read_len - args.tailcrop]).unwrap() + std::str::from_utf8(&record.seq()[args.headcrop..read_len - args.tailcrop]) + .expect("ERROR: problem writing fastq seq"), + std::str::from_utf8(&record.qual()[args.headcrop..read_len - args.tailcrop]) + .expect("ERROR: problem writing fastq qual") ); }