Skip to content
Snippets Groups Projects
Commit 3d0d74cc authored by Bakker, Sibbe's avatar Bakker, Sibbe :speech_balloon:
Browse files

Wrapping function.

parent 5863ba94
Branches
No related tags found
No related merge requests found
......@@ -9,6 +9,12 @@
///
/// In this module, the Needleman-Wunch algorithm is implemented.
pub mod algo {
#[cfg(windows)]
/// Windows line ending
const LINE_ENDING: &'static str = "\r\n";
#[cfg(not(windows))]
/// The unix line ending.
const LINE_ENDING: &'static str = "\n";
use std::{fmt, ops::Add};
......@@ -18,7 +24,7 @@ pub mod algo {
///
/// eg: `(a + b).modulo(c)`
/// ## Reference
/// Written bio [Ideaman42](https://stackoverflow.com/a/41422009).
/// Written by [Ideaman42](https://stackoverflow.com/a/41422009).
pub trait ModuloSignedExt {
fn modulo(
&self,
......@@ -85,19 +91,29 @@ pub mod algo {
pub(super) end_gap: i64,
}
/// # Converts a string to a `Vec` where each item is a wrapped string.
fn wrap_string(
x: &String,
n: usize,
) -> Vec<String> {
dbg!(x);
let mut res: Vec<String> = Vec::new();
let mut res_part = String::new();
for (i, ch) in x.chars().enumerate() {
if i.modulo(n) == n {
let mut i: usize = 0;
for ch in x.chars() {
dbg!(ch, i);
if i == n {
res_part.push(ch);
} else {
res.push(res_part.clone());
res_part.clear();
i = 0;
} else {
res_part.push(ch);
}
i += 1;
}
if res.is_empty() {
res.push(res_part.clone());
}
res
}
......@@ -108,8 +124,10 @@ pub mod algo {
&self,
f: &mut fmt::Formatter,
) -> fmt::Result {
dbg!("Display");
let line_number: usize = 79;
write!(f, "{:?}", wrap_string(&self.x, line_number))
let out = wrap_string(&self.x, line_number);
write!(f, "{:?}", out)
}
}
......@@ -542,9 +560,30 @@ mod test_algo {
let res = alignment.get_traceback();
alignment.construct_alignment(res.0, res.1);
}
// let result = alignment.get_traceback();
// let alignment = alignment.construct_alignment(result.0, result.1);
// println!("{}", alignment);
}
// let result = alignment.get_traceback();
// let alignment = alignment.construct_alignment(result.0, result.1);
// println!("{}", alignment);
#[test]
fn test_alignmnent_print() {
let x: String = "MGLLCSRSRH".to_string();
let y: String = "MGLLCSRSRHHTEDTD".to_string();
let file: &Path = Path::new("assets/blosum_62.txt");
let blosum = import_protein_substitution_matrix(file);
let end_gap = -8;
let gap_score = end_gap;
let mut alignment = NeedlemanWunch::new(
x.clone(),
y.clone(),
end_gap,
gap_score,
blosum.clone(),
);
alignment.set_traceback();
let res = alignment.get_traceback();
let alg = alignment.construct_alignment(res.0, res.1);
println!("{}", alg);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment