44 template <u
int32 BAND_LEN, AlignmentType TYPE,
typename band_type,
typename scoring_type,
typename score_type>
48 const scoring_type& scoring,
49 const score_type infimum)
52 for (
uint32 j = 0; j < BAND_LEN; ++j)
53 band[j] =
TYPE ==
GLOBAL ? j * scoring.deletion() : 0;
64 template <u
int32 BAND_LEN, AlignmentType TYPE>
67 template <
typename band_type,
typename scoring_type,
typename score_type>
72 const scoring_type& scoring,
73 const score_type infimum)
75 init_row_zero<BAND_LEN,TYPE>( band, scoring, infimum );
78 template <
typename band_type>
82 const band_type& band) {}
84 template <
typename band_type>
88 const band_type& band) {}
90 template <
typename score_type>
95 const score_type score,
103 template <u
int32 BAND_LEN, AlignmentType TYPE,
typename checkpo
int_type>
110 template <
typename band_type,
typename scoring_type,
typename score_type>
115 const scoring_type& scoring,
116 const score_type infimum)
120 init_row_zero<BAND_LEN,TYPE>( band, scoring, infimum );
125 for (
uint32 j = 0; j < BAND_LEN; ++j)
130 template <
typename band_type>
134 const band_type& band) {}
136 template <
typename band_type>
140 const band_type& band)
146 for (
uint32 j = 0; j < BAND_LEN; ++j)
151 template <
typename score_type>
156 const score_type score,
166 template <u
int32 BAND_LEN, AlignmentType TYPE, u
int32 CHECKPOINTS,
typename checkpo
int_type>
173 template <
typename band_type,
typename scoring_type,
typename score_type>
178 const scoring_type& scoring,
179 const score_type infimum)
181 init_row_zero<BAND_LEN,TYPE>( band, scoring, infimum );
184 template <
typename band_type>
188 const band_type& band)
191 if ((i & (CHECKPOINTS-1)) == 0u)
195 for (
uint32 j = 0; j < BAND_LEN; ++j)
200 template <
typename band_type>
204 const band_type& band)
209 const uint32 checkpoint_row = (i+CHECKPOINTS-1)/CHECKPOINTS;
210 for (
uint32 j = 0; j < BAND_LEN; ++j)
215 template <
typename score_type>
220 const score_type score,
230 template <u
int32 BAND_LEN, AlignmentType TYPE, u
int32 CHECKPOINTS,
typename checkpo
int_type,
typename submatrix_type>
236 const uint32 checkpoint_id,
237 submatrix_type submatrix) :
242 template <
typename band_type,
typename scoring_type,
typename score_type>
247 const scoring_type& scoring,
248 const score_type infimum)
252 for (
uint32 j = 0; j < BAND_LEN; ++j)
256 template <
typename band_type>
260 const band_type& band) {}
262 template <
typename band_type>
266 const band_type& band) {}
268 template <
typename score_type>
273 const score_type score,
289 template <u
int32 BAND_LEN, AlignmentType TYPE>
341 typename pattern_type,
344 typename scoring_type,
345 typename context_type,
350 const scoring_type& scoring,
351 pattern_type pattern,
354 const uint32 window_begin,
357 const int32 min_score,
358 context_type& context,
361 const uint32 pattern_len = pattern.length();
362 const uint32 text_len = text.length();
365 if (text_len < pattern_len)
368 typedef int32 score_type;
372 text_cache_type text_cache( &text_cache_storage[0] );
375 for (
uint32 j = 0; j < BAND_LEN-1; ++j)
376 text_cache[j] = text[start+window_begin+j];
378 const score_type
G = scoring.deletion();
379 const score_type
I = scoring.insertion();
383 score_type band[BAND_LEN];
393 for (
uint32 i = window_begin; i < window_end; ++i)
396 context.previous_row( i, band );
399 const uint8 q = pattern[i];
400 const uint8 qq = quals[i];
402 const score_type V = scoring.match(qq);
404 score_type top, left, diagonal, hi;
408 const uint8 g = text_cache[0];
409 const score_type S_ij = (g == q) ? V : scoring.mismatch( g, q, qq );
410 diagonal = band[0] + S_ij;
416 sink.report( hi, make_uint2( i+1, i+1 ) );
428 for (
uint32 j = 1; j < BAND_LEN-1; ++j)
430 const uint8 g = text_cache[j]; text_cache[j-1] = g;
431 const score_type S_ij = (g == q) ? V : scoring.mismatch( g, q, qq );
432 diagonal = band[j] + S_ij;
434 left = band[j-1] +
I;
439 sink.report( hi, make_uint2( i + j + 1, i+1 ) );
449 (left > diagonal ?
DELETION : SUBSTITUTION) );
453 const uint8 g = start+i+BAND_LEN-1 < text_len ? text[start+i+BAND_LEN-1] : 255u;
454 text_cache[ BAND_LEN-2 ] = g;
458 const score_type S_ij = (g == q) ? V : scoring.mismatch( g, q, qq );
459 diagonal = band[BAND_LEN-1] + S_ij;
460 left = band[BAND_LEN-2] +
I;
465 sink.report( hi, make_uint2( i + BAND_LEN, i+1 ) );
467 band[ BAND_LEN-1 ] = hi;
477 if (window_end < pattern_len)
480 score_type max_score = band[0];
482 for (
uint32 j = 1; j < BAND_LEN; ++j)
486 const score_type threshold_score = score_type( min_score ) + score_type(pattern_len - window_end)*scoring.match(0);
487 if (max_score < threshold_score)
492 context.last_row( window_end, band );
494 if (window_end == pattern_len)
497 sink.report( band[BAND_LEN-1], make_uint2( pattern_len + BAND_LEN-1, pattern_len ) );
500 const uint32 m =
nvbio::min( pattern_len + BAND_LEN - 1u, text_len ) - (pattern_len-1u);
503 sink.report( band[0], make_uint2( pattern_len + 0, pattern_len ) );
505 for (
uint32 j = 1; j < BAND_LEN; ++j)
508 sink.report( band[j], make_uint2( pattern_len + j, pattern_len ) );
538 typename scoring_type,
539 typename pattern_type,
546 pattern_type pattern,
549 const int32 min_score,
554 return priv::banded::sw_alignment_score_dispatch<BAND_LEN,TYPE>::run( aligner.
scheme, pattern, quals, text, 0u, pattern.length(), 0u, min_score, context, sink );
573 typename scoring_type,
574 typename pattern_type,
578 typename checkpoint_type>
582 pattern_type pattern,
585 const int32 min_score,
586 const uint32 window_begin,
589 checkpoint_type checkpoint)
593 return priv::banded::sw_alignment_score_dispatch<BAND_LEN,TYPE>::run( aligner.
scheme, pattern, quals, text, window_begin, window_end, 0u, min_score, context, sink );
622 typename scoring_type,
623 typename pattern_type,
627 typename checkpoint_type>
631 pattern_type pattern,
634 const int32 min_score,
640 return priv::banded::sw_alignment_score_dispatch<BAND_LEN,TYPE>::run( aligner.
scheme, pattern, quals, text, 0u, pattern.length(), 0u, min_score, context, sink );
679 typename scoring_type,
680 typename pattern_string,
681 typename qual_string,
682 typename text_string,
683 typename checkpoint_type,
684 typename submatrix_type>
688 pattern_string pattern,
691 const int32 min_score,
693 const uint32 checkpoint_id,
694 submatrix_type submatrix)
697 const uint32 window_begin = checkpoint_id * CHECKPOINTS;
701 priv::banded::sw_alignment_score_dispatch<BAND_LEN,TYPE>::run( aligner.
scheme, pattern, quals, text, window_begin, window_end, 0u, min_score, context, sink );
703 return window_end - window_begin;
744 typename scoring_type,
745 typename checkpoint_type,
746 typename submatrix_type,
747 typename backtracer_type>
752 const uint32 checkpoint_id,
753 submatrix_type submatrix,
754 const uint32 submatrix_height,
757 backtracer_type& backtracer)
761 int32 current_entry = sink.x - sink.y;
762 int32 current_row = sink.y - checkpoint_id*CHECKPOINTS - 1u;
765 current_entry < BAND_LEN,
"sw::banded_alignment_backtrack(): sink (%u,%u) -> local x coordinate %d not in [0,%d[\n", sink.x, sink.y, current_entry, BAND_LEN );
766 NVBIO_CUDA_DEBUG_ASSERT( current_row >= 0,
"sw::banded_alignment_backtrack(): sink (%u,%u) -> local y coordinate %d not in [0,%u[\n", sink.x, sink.y, current_row, submatrix_height );
767 NVBIO_CUDA_DEBUG_ASSERT( current_row < submatrix_height,
"sw::banded_alignment_backtrack(): sink (%u,%u) -> local y coordinate %d not in [0,%u[\n", sink.x, sink.y, current_row, submatrix_height );
769 while (current_row >= 0)
771 const uint32 submatrix_cell = current_row * BAND_LEN + current_entry;
772 const uint8 op = submatrix[ submatrix_cell ];
778 sink.y = current_row + checkpoint_id*CHECKPOINTS + 1u;
779 sink.x = current_entry + sink.y;
791 ++current_entry; --current_row;
802 sink.y = checkpoint_id*CHECKPOINTS;
803 sink.x = current_entry + sink.y;