Skip to content

Commit

Permalink
Added GLobalForA and made STEPS const generic
Browse files Browse the repository at this point in the history
  • Loading branch information
douweschulte committed Dec 12, 2023
1 parent b5dae7f commit 807e9ac
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/align/align_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ pub enum Type {
Local,
/// Hybrid alignment, the second sequence will be fully aligned to the first sequence, this could lead to trailing ends on the first sequence but not on the second.
GlobalForB,
/// Hybrid alignment, the first sequence will be fully aligned to the second sequence, this could lead to trailing ends on the second sequence but not on the first.
GlobalForA,
}

impl Type {
Expand Down
13 changes: 9 additions & 4 deletions src/align/mass_alignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,21 @@ use crate::uom::num_traits::Zero;
/// # Panics
/// It panics when the length of `seq_a` or `seq_b` is bigger then [`isize::MAX`].
#[allow(clippy::too_many_lines)]
pub fn align(
pub fn align<const STEPS: usize>(
seq_a: LinearPeptide,
seq_b: LinearPeptide,
alphabet: &[&[i8]],
tolerance: MassTolerance,
ty: Type,
) -> Alignment {
const STEPS: usize = 3; // can at max be i8::MAX / 2 => 64
assert!(isize::try_from(seq_a.len()).is_ok());
assert!(isize::try_from(seq_b.len()).is_ok());
let mut matrix = vec![vec![Piece::default(); seq_b.len() + 1]; seq_a.len() + 1];
let mut high = (0, 0, 0);
let masses_a = calculate_masses(STEPS, &seq_a);
let masses_b = calculate_masses(STEPS, &seq_b);

if ty.global() {
if ty == Type::Global || ty == Type::GlobalForB {
#[allow(clippy::cast_possible_wrap)]
// b is always less than seq_b
for index_b in 0..=seq_b.len() {
Expand All @@ -35,7 +34,7 @@ pub fn align(
);
}
}
if ty == Type::Global {
if ty == Type::Global || ty == Type::GlobalForA {
#[allow(clippy::cast_possible_wrap)]
// a is always less than seq_a
for (index_a, row) in matrix.iter_mut().enumerate() {
Expand Down Expand Up @@ -130,6 +129,12 @@ pub fn align(
.max_by(|a, b| a.1.cmp(&b.1))
.unwrap_or_default();
high = (value.1, value.0, seq_b.len());
} else if ty == Type::GlobalForA {
let value = (0..=seq_b.len())
.map(|v| (v, matrix[seq_a.len()][v].score))
.max_by(|a, b| a.1.cmp(&b.1))
.unwrap_or_default();
high = (value.1, seq_a.len(), value.0);
}
let mut path = Vec::new();
let high_score = high.0;
Expand Down

0 comments on commit 807e9ac

Please sign in to comment.