fn traceback(&self, path: &Vec<Coordinates>) -> i32 {
		let mut score = 0;
		let mut alignment = (Vec::new(), Vec::new());
		// count
		let mut x_gaps = 0;
		let mut y_gaps = 0;

		for (idx, cell) in path.into_iter().rev().enumerate() {
			if idx == path.len() - 1 {
				break;
			}
			//println!("idx: {}, still kicking", idx);
			let prev = &path[path.len() - idx - 2];
			let x_step = cell.1 - prev.1;
			let y_step = cell.0 - prev.0;

			// closure for any residue, x or y
			let r = |seq_r: &[u8], algnmnt: &Vec<u8>, n_gaps: usize| {
				if seq_r.len() + n_gaps >= algnmnt.len() + 1 {
					seq_r[seq_r.len() + n_gaps - 1 - algnmnt.len()]
				} else {
					// this is for the last letter. No need to append to the gap count;
					b'-'
				}
			};

			let x = r(self.seq_x, &alignment.0, x_gaps);
			let y = r(self.seq_y, &alignment.1, y_gaps);

			match (x_step, y_step) {
				(1, 0) => {
					// gap right
					//println!("Gap right");
					x_gaps += 1;
					alignment.0.push(b'-');
					alignment.1.push(y);
					score += self.gap_extend;
				}
				(0, 1) => {
					// gap down
					//println!("Gap down");
					y_gaps += 1;
					alignment.0.push(x);
					alignment.1.push(b'-');
					score += self.gap_extend;
				}
				(1, 1) => {
					// match or mismatch
					alignment.0.push(x);
					alignment.1.push(y);
					if x == y {
						score += self.match_;
					} else {
						score += self.mismatch;
					}
				}
				(_, _) => panic!("Invalid path"),
			}
		}

		// check that the whole sequence is there
		assert_eq!(
			str::from_utf8(self.seq_x).unwrap(),
			str::from_utf8(&alignment.0)
				.unwrap()
				.replace("-", "")
				.chars()
				.rev()
				.collect::<String>()
		);
		assert_eq!(
			str::from_utf8(self.seq_y).unwrap(),
			str::from_utf8(&alignment.1)
				.unwrap()
				.replace("-", "")
				.chars()
				.rev()
				.collect::<String>()
		);
		score
	}
// Evaluate the score of a path. The path is assumed to be valid, complete, and ordered from beginning to end.
Evaluate the score of a path. The path is assumed to be valid, complete, and ordered from beginning to end.
Evaluate the score of a path . The path is assumed to be valid complete and ordered from beginning to end .
fn traceback(&self, path: &Vec<Coordinates>) -> i32 {
		let mut score = 0;
		let mut alignment = (Vec::new(), Vec::new());
		// count
		let mut x_gaps = 0;
		let mut y_gaps = 0;
		for (idx, cell) in path.into_iter().rev().enumerate() {
			if idx == path.len() - 1 {
				break;
			}
			//println!("idx: {}, still kicking", idx);
			let prev = &path[path.len() - idx - 2];
			let x_step = cell.1 - prev.1;
			let y_step = cell.0 - prev.0;
			// closure for any residue, x or y
			let r = |seq_r: &[u8], algnmnt: &Vec<u8>, n_gaps: usize| {
				if seq_r.len() + n_gaps >= algnmnt.len() + 1 {
					seq_r[seq_r.len() + n_gaps - 1 - algnmnt.len()]
				} else {
					// this is for the last letter. No need to append to the gap count;
					b'-'
				}
			};
			let x = r(self.seq_x, &alignment.0, x_gaps);
			let y = r(self.seq_y, &alignment.1, y_gaps);
			match (x_step, y_step) {
				(1, 0) => {
					// gap right
					//println!("Gap right");
					x_gaps += 1;
					alignment.0.push(b'-');
					alignment.1.push(y);
					score += self.gap_extend;
				}
				(0, 1) => {
					// gap down
					//println!("Gap down");
					y_gaps += 1;
					alignment.0.push(x);
					alignment.1.push(b'-');
					score += self.gap_extend;
				}
				(1, 1) => {
					// match or mismatch
					alignment.0.push(x);
					alignment.1.push(y);
					if x == y {
						score += self.match_;
					} else {
						score += self.mismatch;
					}
				}
				(_, _) => panic!("Invalid path"),
			}
		}
		// check that the whole sequence is there
		assert_eq!(
			str::from_utf8(self.seq_x).unwrap(),
			str::from_utf8(&alignment.0)
				.unwrap()
				.replace("-", "")
				.chars()
				.rev()
				.collect::<String>()
		);
		assert_eq!(
			str::from_utf8(self.seq_y).unwrap(),
			str::from_utf8(&alignment.1)
				.unwrap()
				.replace("-", "")
				.chars()
				.rev()
				.collect::<String>()
		);
		score
	}
fn traceback ( & self , path : & Vec < Coordinates > ) -> i32 { let mut score = 0 ; let mut alignment = ( Vec :: new ( ) , Vec :: new ( ) ) ; // count let mut x_gaps = 0 ; let mut y_gaps = 0 ; for ( idx , cell ) in path . into_iter ( ) . rev ( ) . enumerate ( ) { if idx == path . len ( ) - 1 { break ; } //println!("idx: {}, still kicking", idx); let prev = & path [ path . len ( ) - idx - 2 ] ; let x_step = cell . 1 - prev . 1 ; let y_step = cell . 0 - prev . 0 ; // closure for any residue, x or y let r = | seq_r : & [ u8 ] , algnmnt : & Vec < u8 > , n_gaps : usize | { if seq_r . len ( ) + n_gaps >= algnmnt . len ( ) + 1 { seq_r [ seq_r . len ( ) + n_gaps - 1 - algnmnt . len ( ) ] } else { // this is for the last letter. No need to append to the gap count; b'-' } } ; let x = r ( self . seq_x , & alignment . 0 , x_gaps ) ; let y = r ( self . seq_y , & alignment . 1 , y_gaps ) ; match ( x_step , y_step ) { ( 1 , 0 ) => { // gap right //println!("Gap right"); x_gaps += 1 ; alignment . 0 . push ( b'-' ) ; alignment . 1 . push ( y ) ; score += self . gap_extend ; } ( 0 , 1 ) => { // gap down //println!("Gap down"); y_gaps += 1 ; alignment . 0 . push ( x ) ; alignment . 1 . push ( b'-' ) ; score += self . gap_extend ; } ( 1 , 1 ) => { // match or mismatch alignment . 0 . push ( x ) ; alignment . 1 . push ( y ) ; if x == y { score += self . match_ ; } else { score += self . mismatch ; } } ( _ , _ ) => panic ! ( " " ) , } } // check that the whole sequence is there assert_eq ! ( str from_utf8 ( self seq_x ) unwrap ( ) str from_utf8 ( alignment 0 ) unwrap ( ) replace ( " " " " ) chars ( ) rev ( ) collect String ( ) ) ; assert_eq ! ( str from_utf8 ( self seq_y ) unwrap ( ) str from_utf8 ( alignment 1 ) unwrap ( ) replace ( " " " " ) chars ( ) rev ( ) collect String ( ) ) ; score }
Evaluate the score of a path.
Evaluate the score of a path .
&self
path
&Vec<Coordinates>
&self
path
&Vec<Coordinates>