Skip to content

Commit

Permalink
Add manual mismatch filter
Browse files Browse the repository at this point in the history
  • Loading branch information
hextraza committed Aug 6, 2024
1 parent 9a25d8e commit 2f8bac1
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/align.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub enum FilterReason {
SuccessfulMatch,
StrandWasWrong,
TriageEmptyEquivalenceClass,
AboveMismatchThreshold,
None,
}

Expand All @@ -67,6 +68,7 @@ impl Display for FilterReason {
FilterReason::SuccessfulMatch => write!(f, "Successful Match"),
FilterReason::StrandWasWrong => write!(f, "Strandedness Filtered"),
FilterReason::TriageEmptyEquivalenceClass => write!(f, "Equivalence Class Empty After Filters"),
FilterReason::AboveMismatchThreshold => write!(f, "Above Mismatch Threshold"),
FilterReason::None => write!(f, "None"),
}
}
Expand Down Expand Up @@ -942,7 +944,6 @@ fn pseudoalign(
// Perform the alignment of the sequence to the reference debruijn graph. Pass the number of allowed mismatches
match reference_index.map_read_with_mismatch(&sequence, config.num_mismatches) {
Some((equivalence_class, score, mismatches)) => {

// Normalize score by read length
let normalized_score = score as f64 / sequence.len() as f64;

Expand All @@ -959,6 +960,8 @@ fn pseudoalign(
config.score_threshold,
config.score_percent,
config.discard_multiple_matches,
config.num_mismatches,
mismatches
)
}
None => (None, Some((FilterReason::NoMatch, 0.0, 0))),
Expand Down
89 changes: 89 additions & 0 deletions src/filter/align.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ pub fn filter_alignment_by_metrics(
score_threshold: usize,
normalized_score_threshold: f64,
discard_multiple_matches: bool,
mismatch_threshold: usize,
mismatches: usize
) -> (
Option<(Vec<u32>, f64, usize)>,
Option<(FilterReason, f64, usize)>,
Expand All @@ -22,6 +24,15 @@ pub fn filter_alignment_by_metrics(
score,
)),
)
} else if mismatches > mismatch_threshold {
(
None,
Some((
FilterReason::AboveMismatchThreshold,
normalized_score,
score,
)),
)
} else {
(Some((equivalence_class, normalized_score, score)), None)
}
Expand Down Expand Up @@ -52,6 +63,8 @@ mod tests {
score_threshold,
score_percent,
false,
0,
0
);
let expected_results = Some((vec![1, 2], 1.0, 50));

Expand All @@ -74,6 +87,8 @@ mod tests {
score_threshold,
score_percent,
false,
0,
0
);
let expected_results = Some((super::FilterReason::ScoreBelowThreshold, 0.10, 10));

Expand All @@ -97,10 +112,84 @@ mod tests {
score_threshold,
score_percent,
true,
0,
0
);

let expected_results = Some((super::FilterReason::DiscardedMultipleMatch, 1.0, 50));

assert_eq!(results, expected_results);
}

// Case where the mismatches are lower than the threshold -- should not filter the alignment
#[test]
fn do_not_filter_mismatches() {
let score = 50;
let normalized_score = 1.0;
let score_threshold = 20;
let score_percent = 0.5;
let equiv_class = vec![1, 2];

let (results, _) = super::filter_alignment_by_metrics(
equiv_class,
score,
normalized_score,
score_threshold,
score_percent,
false,
1,
0
);
let expected_results = Some((vec![1, 2], 1.0, 50));

assert_eq!(results, expected_results);
}

// Case where the mismatches are equal to the threshold -- should not filter the alignment
#[test]
fn do_not_filter_mismatches_equal() {
let score = 50;
let normalized_score = 1.0;
let score_threshold = 20;
let score_percent = 0.5;
let equiv_class = vec![1, 2];

let (results, _) = super::filter_alignment_by_metrics(
equiv_class,
score,
normalized_score,
score_threshold,
score_percent,
false,
1,
1
);
let expected_results = Some((vec![1, 2], 1.0, 50));

assert_eq!(results, expected_results);
}

// Case where the mismatches are equal to the threshold -- should not filter the alignment
#[test]
fn filter_mismatches() {
let score = 50;
let normalized_score = 1.0;
let score_threshold = 20;
let score_percent = 0.5;
let equiv_class = vec![1, 2];

let (_, results) = super::filter_alignment_by_metrics(
equiv_class,
score,
normalized_score,
score_threshold,
score_percent,
false,
1,
2
);
let expected_results = Some((super::FilterReason::AboveMismatchThreshold, 1.0, 50));

assert_eq!(results, expected_results);
}
}
4 changes: 4 additions & 0 deletions src/output_header.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub struct OutputHeader {
tool_version: String,

}

0 comments on commit 2f8bac1

Please sign in to comment.