@@ -159,6 +159,7 @@ impl BiDArray {
159159 qual_j,
160160 true ,
161161 ) ;
162+
162163 let optimal_penalty = sdm. get_min_penalty (
163164 idx_mapped_to_read,
164165 full_pattern_length,
@@ -168,16 +169,25 @@ impl BiDArray {
168169 ) ;
169170 // The optimal penalty, conditioning on position and base, is subtracted because we
170171 // optimize the ratio `AS/optimal_AS` (in log space) to find the best mappings
171- best_penalty_mm_only - optimal_penalty
172+ let mm_retval = best_penalty_mm_only - optimal_penalty;
173+
174+ // Don't count gap penalties where they are not allowed.
175+ // Sadly this is not expected to have much of an effect.
176+ if idx_mapped_to_read. min ( full_pattern_length - idx_mapped_to_read - 1 )
177+ > alignment_parameters. gap_dist_ends as usize
178+ {
179+ mm_retval. max ( alignment_parameters. penalty_gap_extend )
180+ // The following is not needed, since we can assume
181+ // penalty_gap_extend > penalty_gap_open + penalty_gap_extend
182+ // .max(
183+ // alignment_parameters.penalty_gap_open
184+ // + alignment_parameters.penalty_gap_extend,
185+ // )
186+ } else {
187+ mm_retval
188+ }
172189 } )
173- . fold ( f32:: MIN , |acc, penalty| acc. max ( penalty) )
174- // The following is not needed, since we can assume
175- // penalty_gap_extend > penalty_gap_open + penalty_gap_extend
176- // .max(
177- // alignment_parameters.penalty_gap_open
178- // + alignment_parameters.penalty_gap_extend,
179- // )
180- . max ( alignment_parameters. penalty_gap_extend ) ;
190+ . fold ( f32:: MIN , |acc, penalty| acc. max ( penalty) ) ;
181191 * interval = fmd_index. init_interval ( ) ;
182192 * last_mismatch_pos = index as i16 ;
183193 }
0 commit comments