4
4
//! including the primary 'R1' and 'R2' and index 'I1' and 'I2' reads.
5
5
6
6
use crate :: WhichEnd ;
7
- use anyhow:: { bail, Result } ;
7
+ use anyhow:: { bail, ensure , Result } ;
8
8
use bytes:: { Bytes , BytesMut } ;
9
9
use fastq:: { OwnedRecord , Record } ;
10
10
use serde:: { Deserialize , Serialize } ;
@@ -186,9 +186,9 @@ impl RpRange {
186
186
/// # Args
187
187
/// * `read` - Specify `WhichRead`
188
188
/// * `offset` - Start of the interval. Must be less than 2^15 (=32,768)
189
- /// * `len` - Optional length that determines the end of the interval. A
190
- /// value `None` indicates everything from `offset` until the end of the
191
- /// `read`. Must be less than 2^15 (=32,768)
189
+ /// * `len` - Optional length that determines the end of the interval.
190
+ /// A value `None` indicates everything from `offset` until the end of the `read`.
191
+ /// Must be less than 2^15 (=32,768)
192
192
///
193
193
/// # Panics
194
194
/// * If `offset` or `len` is >= `2^15`
@@ -205,11 +205,11 @@ impl RpRange {
205
205
///
206
206
/// # Tests
207
207
/// * `test_rprange_invalid_offset()` - Test that this function panics with
208
- /// an offset that is too large
208
+ /// an offset that is too large
209
209
/// * `test_rprange_invalid_len()` - Test that this function panics with
210
- /// a length that is too large
210
+ /// a length that is too large
211
211
/// * `prop_test_rprange_representation()` - Test that arbitrary construction of RpRange
212
- /// stores the values correctly.
212
+ /// stores the values correctly.
213
213
pub fn new ( read : WhichRead , offset : usize , len : Option < usize > ) -> RpRange {
214
214
assert ! ( offset < ( 1 << 15 ) ) ;
215
215
let len_bits = match len {
@@ -296,7 +296,7 @@ impl RpRange {
296
296
///
297
297
/// # Tests
298
298
/// * `test_rprange_intersect_panic()` - Make sure that this function panics
299
- /// if the reads do not match
299
+ /// if the reads do not match
300
300
/// * `test_rprange_intersect_both_open()` - Test a case when both lengths are not set
301
301
/// * `test_rprange_intersect_self_open()` - Test a case when only self length is set
302
302
/// * `test_rprange_intersect_other_open()` - Test a case when only other length is set
@@ -363,7 +363,7 @@ impl RpRange {
363
363
/// * `test_shrink_invalid_range_3()`: Test for panic if shrink range start > end
364
364
/// * `test_rprange_trivial_shrink()`: Test shrink to an empty range.
365
365
/// * `prop_test_rprange_shrink()`: Test shrink for arbitrary values of
366
- /// `RpRange` and valid `shrink_range`
366
+ /// `RpRange` and valid `shrink_range`
367
367
pub fn shrink ( & mut self , shrink_range : & ops:: Range < usize > ) {
368
368
assert ! (
369
369
shrink_range. start <= shrink_range. end,
@@ -496,14 +496,12 @@ impl<'a> MutReadPair<'a> {
496
496
497
497
pub fn new < R : Record > ( buffer : & ' a mut BytesMut , rr : & [ Option < R > ; 4 ] ) -> MutReadPair < ' a > {
498
498
let mut rp = MutReadPair :: empty ( buffer) ;
499
-
500
- for ( _rec, which) in rr. iter ( ) . zip ( WhichRead :: read_types ( ) . iter ( ) ) {
501
- if let Some ( ref rec) = * _rec {
502
- rp. push_read ( rec, * which)
499
+ for ( rec, which) in rr. iter ( ) . zip ( WhichRead :: read_types ( ) ) {
500
+ if let Some ( rec) = rec {
501
+ rp. push_read ( rec, which) ;
503
502
}
504
503
// default ReadOffsets is exists = false
505
504
}
506
-
507
505
rp
508
506
}
509
507
@@ -600,32 +598,26 @@ impl ReadPair {
600
598
601
599
pub fn check_range ( & self , range : & RpRange , region_name : & str ) -> Result < ( ) > {
602
600
let req_len = range. offset ( ) + range. len ( ) . unwrap_or ( 0 ) ;
603
-
604
- match self . get ( range. read ( ) , ReadPart :: Seq ) {
605
- Some ( read) => {
606
- if read. len ( ) < req_len {
607
- bail ! (
608
- "{} is expected in positions {}-{} in Read {}, but read is {} bp long." ,
609
- region_name,
610
- range. offset( ) ,
611
- req_len,
612
- range. read( ) ,
613
- read. len( )
614
- ) ;
615
- } else {
616
- Ok ( ( ) )
617
- }
618
- }
619
- None => bail ! (
601
+ let Some ( read) = self . get ( range. read ( ) , ReadPart :: Seq ) else {
602
+ bail ! (
620
603
"{region_name} is missing from FASTQ. Read {} is not present." ,
621
604
range. read( )
622
- ) ,
623
- }
605
+ ) ;
606
+ } ;
607
+ ensure ! (
608
+ read. len( ) >= req_len,
609
+ "{region_name} is expected in positions {}-{} in Read {}, but read is {} bp long." ,
610
+ range. offset( ) ,
611
+ req_len,
612
+ range. read( ) ,
613
+ read. len( )
614
+ ) ;
615
+ Ok ( ( ) )
624
616
}
625
617
626
618
pub fn to_owned_record ( & self ) -> HashMap < WhichRead , OwnedRecord > {
627
619
let mut result = HashMap :: new ( ) ;
628
- for & which in WhichRead :: read_types ( ) . iter ( ) {
620
+ for & which in & WhichRead :: read_types ( ) {
629
621
if self . offsets [ which as usize ] . exists {
630
622
let w = self . offsets [ which as usize ] ;
631
623
let rec = OwnedRecord {
0 commit comments