/// construct the band in the alignment matrix. this band is organized as "stripes"
/// that define the query sequence range for each reference position
construct the band in the alignment matrix. this band is organized as "stripes"
that define the query sequence range for each reference position
construct the band in the alignment matrix . this band is organized as " stripes " that define the query sequence range for each reference position
pub fn create_stripes(
  seed_matches: &[SeedMatch],
  qry_len: i32,
  ref_len: i32,
  terminal_bandwidth: i32,
  excess_bandwidth: i32,
  max_indel: usize,
) -> Result<Vec<Stripe>, Report> {
  let mut seed_matches = seed_matches.to_vec();
  // Discard seed matches right at the terminals of the ref sequence
  if seed_matches[0].ref_pos == 0 {
    seed_matches = seed_matches[1..].to_vec();
  }
  if seed_matches[seed_matches.len() - 1].ref_pos == ref_len as usize - 1 {
    seed_matches = seed_matches[0..(seed_matches.len() - 1)].to_vec();
  }
  // Vec shifts contains offsets of each seed match
  let mut shifts = vec![0; seed_matches.len() + 4];
  for i in 0..seed_matches.len() {
    let shift = seed_matches[i].qry_pos as i32 - seed_matches[i].ref_pos as i32;
    shifts[i + 2] = shift;
  }
  // Pad shifts at terminals for robust width determination
  shifts[0] = shifts[2];
  shifts[1] = shifts[2];
  let shifts_len = shifts.len();
  shifts[shifts_len - 2] = shifts[shifts_len - 3];
  shifts[shifts_len - 1] = shifts[shifts_len - 3];
  let mut robust_shifts = Vec::with_capacity(seed_matches.len() + 1);
  // For each stripe segment, consider seed offsets of previous and following segment
  for slice in shifts.windows(4) {
    let min = slice.iter().min().unwrap();
    let max = slice.iter().max().unwrap();
    let width = max - min;
    // Prevent huge widths, which would require massive amount of memory
    if width as usize > max_indel {
      return make_error!("Unable to align: seed matches suggest large indels or are ambiguous due to duplications.");
    }
    robust_shifts.push((min, max));
  }
  let mut robust_stripes = Vec::with_capacity(robust_shifts.len());
  // Add stripes from ref_pos=0 to the first seed match
  robust_stripes = add_robust_stripes(
    robust_stripes,
    0,
    seed_matches[0].ref_pos as i32,
    qry_len,
    robust_shifts[0],
    terminal_bandwidth,
  );
  // Add stripes between successive seed matches
  for i in 1..robust_shifts.len() - 1 {
    robust_stripes = add_robust_stripes(
      robust_stripes,
      seed_matches[i - 1].ref_pos as i32,
      seed_matches[i].ref_pos as i32,
      qry_len,
      robust_shifts[i],
      excess_bandwidth,
    );
  }
  // Add stripes after the last seed match
  robust_stripes = add_robust_stripes(
    robust_stripes,
    seed_matches.last().unwrap().ref_pos as i32,
    ref_len + 1,
    qry_len,
    *robust_shifts.last().unwrap(),
    terminal_bandwidth,
  );
  robust_stripes = regularize_stripes(robust_stripes, qry_len as usize);
  Ok(robust_stripes)
}
pub fn create_stripes ( seed_matches : & [ SeedMatch ] , qry_len : i32 , ref_len : i32 , terminal_bandwidth : i32 , excess_bandwidth : i32 , max_indel : usize , ) -> Result < Vec < Stripe > , Report > { let mut seed_matches = seed_matches . to_vec ( ) ; // Discard seed matches right at the terminals of the ref sequence if seed_matches [ 0 ] . ref_pos == 0 { seed_matches = seed_matches [ 1 .. ] . to_vec ( ) ; } if seed_matches [ seed_matches . len ( ) - 1 ] . ref_pos == ref_len as usize - 1 { seed_matches = seed_matches [ 0 .. ( seed_matches . len ( ) - 1 ) ] . to_vec ( ) ; } // Vec shifts contains offsets of each seed match let mut shifts = vec ! [ 0 seed_matches len ( ) 4 ] ; for i in 0 .. seed_matches . len ( ) { let shift = seed_matches [ i ] . qry_pos as i32 - seed_matches [ i ] . ref_pos as i32 ; shifts [ i + 2 ] = shift ; } // Pad shifts at terminals for robust width determination shifts [ 0 ] = shifts [ 2 ] ; shifts [ 1 ] = shifts [ 2 ] ; let shifts_len = shifts . len ( ) ; shifts [ shifts_len - 2 ] = shifts [ shifts_len - 3 ] ; shifts [ shifts_len - 1 ] = shifts [ shifts_len - 3 ] ; let mut robust_shifts = Vec :: with_capacity ( seed_matches . len ( ) + 1 ) ; // For each stripe segment, consider seed offsets of previous and following segment for slice in shifts . windows ( 4 ) { let min = slice . iter ( ) . min ( ) . unwrap ( ) ; let max = slice . iter ( ) . max ( ) . unwrap ( ) ; let width = max - min ; // Prevent huge widths, which would require massive amount of memory if width as usize > max_indel { return make_error ! ( " " ) ; } robust_shifts . push ( ( min , max ) ) ; } let mut robust_stripes = Vec :: with_capacity ( robust_shifts . len ( ) ) ; // Add stripes from ref_pos=0 to the first seed match robust_stripes = add_robust_stripes ( robust_stripes , 0 , seed_matches [ 0 ] . ref_pos as i32 , qry_len , robust_shifts [ 0 ] , terminal_bandwidth , ) ; // Add stripes between successive seed matches for i in 1 .. robust_shifts . len ( ) - 1 { robust_stripes = add_robust_stripes ( robust_stripes , seed_matches [ i - 1 ] . ref_pos as i32 , seed_matches [ i ] . ref_pos as i32 , qry_len , robust_shifts [ i ] , excess_bandwidth , ) ; } // Add stripes after the last seed match robust_stripes = add_robust_stripes ( robust_stripes , seed_matches . last ( ) . unwrap ( ) . ref_pos as i32 , ref_len + 1 , qry_len , * robust_shifts . last ( ) . unwrap ( ) , terminal_bandwidth , ) ; robust_stripes = regularize_stripes ( robust_stripes , qry_len as usize ) ; Ok ( robust_stripes ) }
construct the band in the alignment matrix.
construct the band in the alignment matrix .
seed_matches
&[SeedMatch]
qry_len
i32
ref_len
i32
terminal_bandwidth
i32
excess_bandwidth
i32
max_indel
usize