Skip to content

Commit

Permalink
custom number of columns in Alignment::pretty()
Browse files Browse the repository at this point in the history
  • Loading branch information
TianyiShi2001 committed Oct 1, 2020
1 parent c2206e3 commit 91564b9
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/alignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ impl Alignment {
/// AAAAACCGTTGACGGCCA--A
/// ```
///
pub fn pretty(&self, x: TextSlice, y: TextSlice) -> String {
pub fn pretty(&self, x: TextSlice, y: TextSlice, ncol: usize) -> String {
let mut x_pretty = String::new();
let mut y_pretty = String::new();
let mut inb_pretty = String::new();
Expand Down Expand Up @@ -293,7 +293,6 @@ impl Alignment {

let mut s = String::new();
let mut idx = 0;
let step = 100; // Number of characters per line
use std::cmp::min;

assert_eq!(x_pretty.len(), inb_pretty.len());
Expand All @@ -302,7 +301,7 @@ impl Alignment {
let ml = x_pretty.len();

while idx < ml {
let rng = idx..min(idx + step, ml);
let rng = idx..min(idx + ncol, ml);
s.push_str(&x_pretty[rng.clone()]);
s.push_str("\n");

Expand All @@ -313,7 +312,7 @@ impl Alignment {
s.push_str("\n");

s.push_str("\n\n");
idx += step;
idx += ncol;
}

s
Expand Down Expand Up @@ -459,7 +458,7 @@ mod tests {
mode: AlignmentMode::Semiglobal,
};
let pretty = concat!(" GAT \n", " \\|| \n", "CTAATCC\n", "\n\n");
assert_eq!(alignment.pretty(b"GAT", b"CTAATCC"), pretty);
assert_eq!(alignment.pretty(b"GAT", b"CTAATCC", 100), pretty);
let alignment = Alignment {
score: 5,
xstart: 0,
Expand All @@ -472,6 +471,6 @@ mod tests {
mode: AlignmentMode::Custom,
};
let pretty = concat!(" AAAA--A\n |\\\\+xx \nTTTTTTTT-TT \n\n\n");
assert_eq!(alignment.pretty(b"AAAAA", b"TTTTTTTTTT"), pretty);
assert_eq!(alignment.pretty(b"AAAAA", b"TTTTTTTTTT", 100), pretty);
}
}

0 comments on commit 91564b9

Please sign in to comment.