Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: memory efficient poa bug fix #552

Closed
wants to merge 8 commits into from
12 changes: 6 additions & 6 deletions src/alignment/poa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ impl Traceback {
/// * `n` - the length of the query sequence
fn with_capacity(m: usize, n: usize) -> Self {
// each row of matrix contain start end position and vec of traceback cells
let matrix: Vec<(Vec<TracebackCell>, usize, usize)> = vec![(vec![], 0, n); m + 1];
let matrix: Vec<(Vec<TracebackCell>, usize, usize)> = vec![(vec![], 0, n + 1); m + 1];
Traceback {
rows: m,
cols: n,
Expand Down Expand Up @@ -268,15 +268,15 @@ impl Traceback {

fn set(&mut self, i: usize, j: usize, cell: TracebackCell) {
// set the matrix cell if in band range
if !(self.matrix[i].1 > j || self.matrix[i].2 < j) {
if !(self.matrix[i].1 > j || self.matrix[i].2 <= j) {
let real_position = j - self.matrix[i].1;
self.matrix[i].0[real_position] = cell;
}
}

fn get(&self, i: usize, j: usize) -> &TracebackCell {
// get the matrix cell if in band range else return the appropriate values
if !(self.matrix[i].1 > j || self.matrix[i].2 < j) {
if !(self.matrix[i].1 > j || self.matrix[i].2 <= j) && (self.matrix[i].0.len() > 0) {
let real_position = j - self.matrix[i].1;
return &self.matrix[i].0[real_position];
}
Expand All @@ -288,7 +288,7 @@ impl Traceback {
};
}
// infront of the band
else if j > self.matrix[i].2 {
else if j >= self.matrix[i].2 {
return &TracebackCell {
score: MIN_SCORE,
op: AlignmentOperation::Ins(None),
Expand Down Expand Up @@ -507,7 +507,7 @@ impl<F: MatchFunc> Poa<F> {
// iterate over the predecessors of this node
let prevs: Vec<NodeIndex<usize>> =
self.graph.neighbors_directed(node, Incoming).collect();
traceback.new_row(i, n + 1, self.scoring.gap_open, 0, n);
traceback.new_row(i, n + 1, self.scoring.gap_open, 0, n + 1);
// query base and its index in the DAG (traceback matrix rows)
for (query_index, query_base) in query.iter().enumerate() {
let j = query_index + 1; // 0 index is initialized so we start at 1
Expand Down Expand Up @@ -600,7 +600,7 @@ impl<F: MatchFunc> Poa<F> {
max_scoring_j - bandwidth
};
let end = max_scoring_j + bandwidth;
traceback.new_row(i, (end - start) + 1, self.scoring.gap_open, start, end);
traceback.new_row(i, (end - start) + 1, self.scoring.gap_open, start, end + 1);
for (query_index, query_base) in query.iter().enumerate().skip(start) {
let j = query_index + 1; // 0 index is initialized so we start at 1
if j > end {
Expand Down