From f77cd51c44988b953b22c0719f07c9c71c6d5834 Mon Sep 17 00:00:00 2001 From: ivan-aksamentov Date: Fri, 12 Jan 2024 17:17:06 +0100 Subject: [PATCH] test: fix failing unit test The unit test `pads_missing_left()` is failing: https://github.com/nextstrain/nextclade/blob/cc9e817b2195ccc39c1094800857f512ed6ad82f/packages_rs/nextclade/src/align/score_matrix.rs#L241-L294 with this error: https://github.com/nextstrain/nextclade/actions/runs/7477824073/job/20351461502?pr=1377#step:7:398 Probably due to retying on the previous default value of the "gap alignment side" parameter ("right"). So I decided to make 2 tests instead of this one: - `pads_missing_left()` using the default "left" value for "gap alignment side" now got the new expectations. I copied them from the actual result, so they need to be scientifically checked. - `pads_missing_left_with_alignment_gap_right()` retained previous expectations, but is now using "right" in the "gap alignment side". Both tests are passing, but the expectations for the `pads_missing_left()` need to be checked by hand. --- .../nextclade/src/align/score_matrix.rs | 61 ++++++++++++++++++- 1 file changed, 59 insertions(+), 2 deletions(-) diff --git a/packages_rs/nextclade/src/align/score_matrix.rs b/packages_rs/nextclade/src/align/score_matrix.rs index fbb2256d8..01297bc24 100644 --- a/packages_rs/nextclade/src/align/score_matrix.rs +++ b/packages_rs/nextclade/src/align/score_matrix.rs @@ -269,6 +269,63 @@ mod tests { ], ); + #[rustfmt::skip] + let expected_paths = Band2d::::with_data( + &stripes, + &[ + 0, 10, 10, 10, + 20, 1, 9, 9, 41, + 20, 17, 17, 25, 9, + 20, 1, 25, 1, 25, 34, 42, + 20, 17, 1, 25, 4, 9, 2, 10, + 20, 17, 25, 2, 25, 12, 9, 2, + 20, 17, 4, 25, 18, 25, 12, 9, + 20, 17, 25, 4, 17, 18, 26, 12, + 52, 17, 4, 17, 18, 28, + 52, 20, 20, 4, 17, 18, + 20, 20, 20, 4, 1, + ], + ); + + assert_eq!(expected_scores, result.scores); + assert_eq!(expected_paths, result.paths); + + Ok(()) + } + + #[rstest] + fn pads_missing_left_with_alignment_gap_right(mut ctx: Context) -> Result<(), Report> { + let qry_seq = to_nuc_seq("CTCGCTG")?; + let ref_seq = to_nuc_seq("ACGCTCGCTG")?; + + let band_width = 5; + let mean_shift = 2; + + let mut stripes = simple_stripes(mean_shift, band_width, ref_seq.len(), qry_seq.len()); + stripes[2].end = stripes[2].end - 1; + stripes[8].begin = stripes[8].begin + 1; + + ctx.params.gap_alignment_side = GapAlignmentSide::Right; + let result = score_matrix(&qry_seq, &ref_seq, &ctx.gap_open_close, &stripes, &ctx.params); + + #[rustfmt::skip] + let expected_scores = Band2d::::with_data( + &stripes, + &[ + 0, 0, 0, 0, + 0, -1, -1, -1, -1, + 0, 3, -2, 2, -2, + 0, -1, 2, -3, 5, -1, -1, + 0, 3, -2, 5, -1, 8, 2, 2, + 0, -1, 6, 0, 4, 2, 11, 5, + 0, 3, 0, 9, 3, 7, 5, 10, + 0, -1, 2, 3, 12, 6, 6, 10, + 0, 5, 6, 15, 9, 10, + 0, 3, 6, 9, 18, 12, + 3, 6, 9, 12, 21, + ], + ); + #[rustfmt::skip] let expected_paths = Band2d::::with_data( &stripes, @@ -278,8 +335,8 @@ mod tests { 20, 17, 17, 25, 9, 20, 1, 25, 1, 25, 34, 42, 20, 17, 1, 25, 2, 9, 2, 10, - 20, 17, 25, 2, 25, 12, 9, 2, - 20, 17, 4, 25, 18, 25, 12, 9, + 20, 17, 25, 2, 25, 12, 9, 2, + 20, 17, 4, 25, 18, 25, 12, 9, 20, 17, 25, 4, 17, 18, 25, 12, 52, 17, 4, 17, 18, 28, 52, 20, 20, 4, 17, 18,