From 46fb6dac6d49617a2604aa6ff3071df31df77428 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Tue, 20 May 2025 09:48:55 +0300 Subject: [PATCH 1/3] Add log message. --- lib_tsalign/src/a_star_aligner.rs | 1 + perf.data | 0 2 files changed, 1 insertion(+) create mode 100644 perf.data diff --git a/lib_tsalign/src/a_star_aligner.rs b/lib_tsalign/src/a_star_aligner.rs index 51864fa7..cedd10d5 100644 --- a/lib_tsalign/src/a_star_aligner.rs +++ b/lib_tsalign/src/a_star_aligner.rs @@ -190,6 +190,7 @@ where )); debug!("CIGAR before extending: {}", result.cigar()); + info!("Extending template switches"); let mut range = range; result.extend_beyond_range_with_equal_cost(reference, query, &mut range, &config); let range = range; diff --git a/perf.data b/perf.data new file mode 100644 index 00000000..e69de29b From b02d47cd6994d589ccd5aa2d67b92bf5467af4e1 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Tue, 20 May 2025 13:04:10 +0300 Subject: [PATCH 2/3] Fix various edge cases in TS extension. --- .../alignment/template_switch_specifics.rs | 24 +++++++++++++------ test_files/twin_double_gap.fa | 4 ++++ test_files/twin_perf.fa | 4 ++++ 3 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 test_files/twin_double_gap.fa create mode 100644 test_files/twin_perf.fa diff --git a/lib_tsalign/src/a_star_aligner/alignment_result/alignment/template_switch_specifics.rs b/lib_tsalign/src/a_star_aligner/alignment_result/alignment/template_switch_specifics.rs index fbc48f27..43d5c831 100644 --- a/lib_tsalign/src/a_star_aligner/alignment_result/alignment/template_switch_specifics.rs +++ b/lib_tsalign/src/a_star_aligner/alignment_result/alignment/template_switch_specifics.rs @@ -77,7 +77,7 @@ impl Alignment { ) .unwrap(); - // Check if first indices can be moved while staying in bounds. + // Check if indices can be moved while staying in bounds. match direction { TemplateSwitchDirection::Forward => { if ts_inner_secondary_index == 0 { @@ -202,6 +202,11 @@ impl Alignment { let ts_outer_reference_index = stream.head_coordinates().reference() + reference_offset; let ts_outer_query_index = stream.head_coordinates().query() + query_offset; + // Check if indices can be moved while staying in bounds. + if ts_outer_reference_index == reference.len() || ts_outer_query_index == query.len() { + return false; + } + // Remove one match or substitution from inside the TS. let multiplicity = &mut self.alignment[*compact_index + 1].0; assert!(*multiplicity > 0); @@ -222,7 +227,7 @@ impl Alignment { }; // Insert new outer alignment. - if self.alignment[*compact_index - 1].1 == outer_alignment_type { + if self.alignment.get(*compact_index - 1).map(|t| t.1) == Some(outer_alignment_type) { self.alignment[*compact_index - 1].0 += 1; } else { self.alignment @@ -349,7 +354,7 @@ impl Alignment { let ts_inner_secondary_index = ts_inner_secondary_index .checked_add(inner_secondary_length) .unwrap(); - // Check if first indices can be moved while staying in bounds. + // Check if indices can be moved while staying in bounds. if ts_inner_secondary_index >= secondary.get(reference, query).len() { return false; } @@ -359,7 +364,7 @@ impl Alignment { let ts_inner_secondary_index = ts_inner_secondary_index .checked_sub(inner_secondary_length) .unwrap(); - // Check if first indices can be moved while staying in bounds. + // Check if indices can be moved while staying in bounds. if ts_inner_secondary_index == 0 { return false; } @@ -474,6 +479,11 @@ impl Alignment { let ts_outer_reference_index = stream.head_coordinates().reference() + reference_offset; let ts_outer_query_index = stream.head_coordinates().query() + query_offset; + // Check if indices can be moved while staying in bounds. + if ts_outer_reference_index == 0 || ts_outer_query_index == 0 { + return false; + } + // Remove one match or substitution from inside the TS. let multiplicity = &mut self.alignment[exit_index - 1].0; assert!(*multiplicity > 0); @@ -486,8 +496,8 @@ impl Alignment { } // Check if the new outer pair is a match or a substitution. - let reference_char = reference[ts_outer_reference_index].clone(); - let query_char = query[ts_outer_query_index].clone(); + let reference_char = reference[ts_outer_reference_index - 1].clone(); + let query_char = query[ts_outer_query_index - 1].clone(); let outer_alignment_type = if reference_char == query_char { AlignmentType::PrimaryMatch } else { @@ -495,7 +505,7 @@ impl Alignment { }; // Insert new outer alignment. - if self.alignment[exit_index + 1].1 == outer_alignment_type { + if self.alignment.get(exit_index + 1).map(|t| t.1) == Some(outer_alignment_type) { self.alignment[exit_index + 1].0 += 1; } else { self.alignment diff --git a/test_files/twin_double_gap.fa b/test_files/twin_double_gap.fa new file mode 100644 index 00000000..48681cf5 --- /dev/null +++ b/test_files/twin_double_gap.fa @@ -0,0 +1,4 @@ +>reference +AGATCCGTCGTA +>query +AGATGTCGTA \ No newline at end of file diff --git a/test_files/twin_perf.fa b/test_files/twin_perf.fa new file mode 100644 index 00000000..d7fbb711 --- /dev/null +++ b/test_files/twin_perf.fa @@ -0,0 +1,4 @@ +>reference +ACTGTGTGAGTAGCGGATAGGATAGAGGATCGACGTCTCGACGATCTGCACTTAC +>query +ACTGTGTGAGTAGCGGATAGGATAGAGTCGCGATCGACGTCTCGACGATCTGCACTTAC \ No newline at end of file From be6a639a6538c4ffabfac60a68063a0626278874 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Tue, 20 May 2025 13:13:28 +0300 Subject: [PATCH 3/3] Make benchmark example. --- test_files/twin_perf.fa | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test_files/twin_perf.fa b/test_files/twin_perf.fa index d7fbb711..3861aa3a 100644 --- a/test_files/twin_perf.fa +++ b/test_files/twin_perf.fa @@ -1,4 +1,4 @@ >reference -ACTGTGTGAGTAGCGGATAGGATAGAGGATCGACGTCTCGACGATCTGCACTTAC +ACCCCCCCCCCCTGTGTGAGTTAGCGGATAGGATAGAGATCGACGTCTCGACGATCTGCACCCTAAGGC >query -ACTGTGTGAGTAGCGGATAGGATAGAGTCGCGATCGACGTCTCGACGATCTGCACTTAC \ No newline at end of file +ACCCCCCCCCCCTGTGTGAGTAGCGGATAGGATAGAGTCGCGATCGACGTCTCGACGATCTGCACTTAA \ No newline at end of file