From 309b516cbaadee9757b1f92476be4e0530a4494f Mon Sep 17 00:00:00 2001 From: Jasper Krauter <12259417+jeeeesper@users.noreply.github.com> Date: Mon, 3 Aug 2026 14:35:50 +0300 Subject: [PATCH] feat: Add range prune strategy selector to Aligner struct --- .../configurable_a_star_align.rs | 65 +++++++++++++++++-- 1 file changed, 58 insertions(+), 7 deletions(-) diff --git a/lib_tsalign/src/a_star_aligner/configurable_a_star_align.rs b/lib_tsalign/src/a_star_aligner/configurable_a_star_align.rs index e397627..3d989d7 100644 --- a/lib_tsalign/src/a_star_aligner/configurable_a_star_align.rs +++ b/lib_tsalign/src/a_star_aligner/configurable_a_star_align.rs @@ -20,7 +20,10 @@ use crate::{ AnyTemplateSwitchDescendantStrategy, OnlyEqualTemplateSwitchDescendantStrategy, TemplateSwitchDescendantStrategy, }, - primary_range::RangePrunePrimaryRangeStrategy, + primary_range::{ + NoPrunePrimaryRangeStrategy, PrimaryRangeStrategy, + RangePrunePrimaryRangeStrategy, + }, secondary_deletion::AllowSecondaryDeletionStrategy, shortcut::NoShortcutStrategy, template_switch_min_length::{ @@ -111,6 +114,19 @@ pub enum DescendantStrategySelector { AllowOnlyAllEqual, } +/// Select whether the primary alignment is restricted to the alignment range. +#[derive(Debug, Default)] +#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))] +pub enum PrimaryRangeStrategySelector { + /// The primary alignment is restricted to the alignment range. + #[default] + Prune, + /// The primary alignment is restricted to the input sequences only, and may hence leave the + /// alignment range. + NoPrune, +} + /// Just used in this file to bundle the query parameters to make the code more readable struct QueryData<'a> { reference_name: &'a str, @@ -135,6 +151,7 @@ pub struct Aligner { total_length_strategy: TotalLengthStrategySelector, descendant_strategy: DescendantStrategySelector, ts_14_out_of_range_strategy: Ts14OutOfRangeStrategy, + primary_range_strategy: PrimaryRangeStrategySelector, no_ts: bool, } @@ -156,6 +173,7 @@ impl Default for Aligner { total_length_strategy: Default::default(), descendant_strategy: Default::default(), ts_14_out_of_range_strategy: Default::default(), + primary_range_strategy: Default::default(), no_ts: false, } } @@ -221,6 +239,14 @@ impl Aligner { self } + pub fn set_primary_range_strategy( + &mut self, + primary_range_strategy: PrimaryRangeStrategySelector, + ) -> &mut Self { + self.primary_range_strategy = primary_range_strategy; + self + } + /// Perform the actual alignment. /// /// Special gap characters can be specified in order to interpret the given sequences as an alignment with gaps instead of raw sequences. @@ -335,16 +361,40 @@ impl Aligner { ) -> AlignmentResult { match self.descendant_strategy { DescendantStrategySelector::AllowAny => self - .align_call::( + .align_select_primary_range_strategy::( data, count_strategy_memory, ), - DescendantStrategySelector::AllowOnlyAllEqual => { - self.align_call::( + DescendantStrategySelector::AllowOnlyAllEqual => self + .align_select_primary_range_strategy::( data, count_strategy_memory, - ) - } + ), + } + } + + fn align_select_primary_range_strategy< + ML: TemplateSwitchMinLengthStrategy, + CH: ChainingStrategy, + TL: TemplateSwitchTotalLengthStrategy, + TC: TemplateSwitchCountStrategy, + DS: TemplateSwitchDescendantStrategy, + >( + &self, + data: QueryData, + count_strategy_memory: TC::Memory, + ) -> AlignmentResult { + match self.primary_range_strategy { + PrimaryRangeStrategySelector::Prune => self + .align_call::( + data, + count_strategy_memory, + ), + PrimaryRangeStrategySelector::NoPrune => self + .align_call::( + data, + count_strategy_memory, + ), } } @@ -354,6 +404,7 @@ impl Aligner { TL: TemplateSwitchTotalLengthStrategy, TC: TemplateSwitchCountStrategy, DS: TemplateSwitchDescendantStrategy, + PR: PrimaryRangeStrategy, >( &self, data: QueryData, @@ -413,7 +464,7 @@ impl Aligner { AllowSecondaryDeletionStrategy, NoShortcutStrategy, AllowPrimaryMatchStrategy, - RangePrunePrimaryRangeStrategy, + PR, TL, DS, >,