42 #define SW_F_INITIALIZED_TO_INF
46 template <u
int32 BAND_LEN, AlignmentType TYPE,
typename H_band_type,
typename F_band_type,
typename scoring_type,
typename score_type>
51 const scoring_type& scoring,
52 const score_type infimum)
56 for (
uint32 j = 1; j < BAND_LEN; ++j)
57 H_band[j] =
TYPE ==
GLOBAL ? scoring.text_gap_open() + (j-1)*scoring.text_gap_extension() : 0;
59 #if defined(SW_F_INITIALIZED_TO_INF)
62 for (
uint32 j = 0; j < BAND_LEN; ++j)
67 for (
uint32 j = 0; j < BAND_LEN; ++j)
87 template <u
int32 BAND_LEN, AlignmentType TYPE>
90 template <
typename H_band_type,
typename F_band_type,
typename scoring_type,
typename score_type>
96 const scoring_type& scoring,
97 const score_type infimum)
99 init_row_zero<BAND_LEN,TYPE>( H_band, F_band, scoring, infimum );
102 template <
typename H_band_type,
typename F_band_type>
106 const H_band_type& H_band,
107 const F_band_type& F_band) {}
109 template <
typename H_band_type,
typename F_band_type>
113 const H_band_type& H_band,
114 const F_band_type& F_band) {}
117 template <
typename score_type>
122 const score_type score,
132 template <u
int32 BAND_LEN, AlignmentType TYPE,
typename checkpo
int_type>
139 template <
typename H_band_type,
typename F_band_type,
typename scoring_type,
typename score_type>
145 const scoring_type& scoring,
146 const score_type infimum)
150 init_row_zero<BAND_LEN,TYPE>( H_band, F_band, scoring, infimum );
155 for (
uint32 j = 0; j < BAND_LEN; ++j)
163 template <
typename H_band_type,
typename F_band_type>
167 const H_band_type& H_band,
168 const F_band_type& F_band) {}
170 template <
typename H_band_type,
typename F_band_type>
174 const H_band_type& H_band,
175 const F_band_type& F_band)
181 for (
uint32 j = 0; j < BAND_LEN; ++j)
188 template <
typename score_type>
193 const score_type score,
205 template <u
int32 BAND_LEN, AlignmentType TYPE, u
int32 CHECKPOINTS,
typename checkpo
int_type>
212 template <
typename H_band_type,
typename F_band_type,
typename scoring_type,
typename score_type>
218 const scoring_type& scoring,
219 const score_type infimum)
221 init_row_zero<BAND_LEN,TYPE>( H_band, F_band, scoring, infimum );
224 template <
typename H_band_type,
typename F_band_type>
228 const H_band_type& H_band,
229 const F_band_type& F_band)
232 if ((i & (CHECKPOINTS-1)) == 0u)
236 for (
uint32 j = 0; j < BAND_LEN; ++j)
243 template <
typename H_band_type,
typename F_band_type>
247 const H_band_type& H_band,
248 const F_band_type& F_band)
253 const uint32 checkpoint_row = (i+CHECKPOINTS-1)/CHECKPOINTS;
254 for (
uint32 j = 0; j < BAND_LEN; ++j)
261 template <
typename score_type>
266 const score_type score,
278 template <u
int32 BAND_LEN, AlignmentType TYPE, u
int32 CHECKPOINTS,
typename checkpo
int_type,
typename submatrix_type>
284 const uint32 checkpoint_id,
285 submatrix_type submatrix) :
290 template <
typename H_band_type,
typename F_band_type,
typename scoring_type,
typename score_type>
296 const scoring_type& scoring,
297 const score_type infimum)
301 for (
uint32 j = 0; j < BAND_LEN; ++j)
309 template <
typename H_band_type,
typename F_band_type>
313 const H_band_type& H_band,
314 const F_band_type& F_band) {}
316 template <
typename H_band_type,
typename F_band_type>
320 const H_band_type& H_band,
321 const F_band_type& F_band) {}
323 template <
typename score_type>
328 const score_type score,
335 (
TYPE ==
LOCAL ? (score == 0 ?
SINK : hdir) : hdir) | edir | fdir;
349 template <u
int32 BAND_LEN, AlignmentType TYPE>
407 typename pattern_type,
410 typename scoring_type,
411 typename context_type,
416 const scoring_type& scoring,
417 pattern_type pattern,
420 const uint32 window_begin,
423 const int32 min_score,
424 context_type& context,
427 const uint32 pattern_len = pattern.length();
428 const uint32 text_len = text.length();
431 if (text_len < pattern_len)
434 typedef int32 score_type;
438 text_cache_type text_cache( text_cache_storage );
441 for (
uint32 j = 0; j < BAND_LEN-1; ++j)
442 text_cache[j] = text[start+window_begin+j];
444 const score_type G_o = scoring.pattern_gap_open();
445 const score_type G_e = scoring.pattern_gap_extension();
448 nvbio::max( scoring.text_gap_open(), scoring.text_gap_extension() ) );
451 score_type H_band[BAND_LEN];
452 score_type F_band[BAND_LEN];
463 for (
uint32 i = window_begin; i < window_end; ++i)
466 context.previous_row( i, H_band, F_band );
469 const uint8 q = pattern[i];
470 const uint8 qq = quals[i];
485 const score_type ftop = F_band[1] + G_e;
486 const score_type htop = H_band[1] + G_o;
490 const uint8 g = text_cache[0];
492 const score_type S_ij = scoring.substitution( i+0, i, g, q, qq );
493 const score_type diagonal = H_band[0] + S_ij;
494 const score_type top = F_band[0];
500 hdir = ( hi == score_type(0) ) ?
SINK : hdir;
501 sink.report( hi, make_uint2( i+1, i+1 ) );
517 score_type E_j = H_band[0] + G_o;
520 for (
uint32 j = 1; j < BAND_LEN-1; ++j)
523 const score_type ftop = F_band[j+1] + G_e;
524 const score_type htop = H_band[j+1] + G_o;
542 const uint32 g = text_cache[j]; text_cache[j-1] = g;
544 const score_type S_ij = scoring.substitution( i+j, i, g, q, qq );
545 const score_type diagonal = H_band[j] + S_ij;
546 const score_type top = F_band[j];
547 const score_type left = E_j;
548 score_type hi =
nvbio::max3( top, left, diagonal );
553 hdir = ( hi == score_type(0) ) ?
SINK : hdir;
554 sink.report( hi, make_uint2( i + j + 1, i+1 ) );
568 (left > diagonal ?
DELETION : SUBSTITUTION)),
573 const score_type eleft = E_j + G_e;
574 const score_type ediagonal = hi + G_o;
580 const uint8 g = start+i+BAND_LEN-1 < text_len ? text[start+i+BAND_LEN-1] : 255u;
581 text_cache[ BAND_LEN-2 ] = g;
586 F_band[ BAND_LEN-1 ] = infimum;
591 const score_type S_ij = scoring.substitution( i+BAND_LEN-1, i, g, q, qq );
592 const score_type diagonal = H_band[BAND_LEN-1] + S_ij;
593 const score_type left = E_j;
599 hdir = ( hi == score_type(0) ) ?
SINK : hdir;
600 sink.report( hi, make_uint2( i + BAND_LEN, i+1 ) );
602 H_band[ BAND_LEN-1 ] = hi;
622 if (window_end < pattern_len)
625 score_type max_score = H_band[0];
627 for (
uint32 j = 1; j < BAND_LEN; ++j)
628 max_score =
nvbio::max( max_score, H_band[j] );
631 const score_type threshold_score = score_type( min_score ) + score_type(pattern_len - window_end)*scoring.match(0);
632 if (max_score < threshold_score)
637 context.last_row( window_end, H_band, F_band );
639 if (window_end == pattern_len)
642 sink.report( H_band[ BAND_LEN-1 ], make_uint2( pattern_len + BAND_LEN-1, pattern_len ) );
645 const uint32 m =
nvbio::min( pattern_len + BAND_LEN - 1u, text_len ) - (pattern_len-1u);
648 sink.report( H_band[0], make_uint2( pattern_len + 0, pattern_len ) );
650 for (
uint32 j = 1; j < BAND_LEN; ++j)
653 sink.report( H_band[j], make_uint2( pattern_len + j, pattern_len ) );
683 typename scoring_type,
684 typename pattern_type,
691 pattern_type pattern,
694 const int32 min_score,
699 return priv::banded::gotoh_alignment_score_dispatch<BAND_LEN,TYPE>::run( aligner.
scheme, pattern, quals, text, 0u, pattern.length(), 0u, min_score, context, sink );
718 typename scoring_type,
719 typename pattern_type,
723 typename checkpoint_type>
727 pattern_type pattern,
730 const int32 min_score,
731 const uint32 window_begin,
734 checkpoint_type checkpoint)
738 return priv::banded::gotoh_alignment_score_dispatch<BAND_LEN,TYPE>::run( aligner.
scheme, pattern, quals, text, window_begin, window_end, 0u, min_score, context, sink );
767 typename scoring_type,
768 typename pattern_type,
772 typename checkpoint_type>
776 pattern_type pattern,
779 const int32 min_score,
785 return priv::banded::gotoh_alignment_score_dispatch<BAND_LEN,TYPE>::run( aligner.
scheme, pattern, quals, text, 0u, pattern.length(), 0u, min_score, context, sink );
824 typename scoring_type,
825 typename pattern_string,
826 typename qual_string,
827 typename text_string,
828 typename checkpoint_type,
829 typename submatrix_type>
833 pattern_string pattern,
836 const int32 min_score,
838 const uint32 checkpoint_id,
839 submatrix_type submatrix)
842 const uint32 window_begin = checkpoint_id * CHECKPOINTS;
846 priv::banded::gotoh_alignment_score_dispatch<BAND_LEN,TYPE>::run( aligner.
scheme, pattern, quals, text, window_begin, window_end, 0u, min_score, context, sink );
848 return window_end - window_begin;
890 typename scoring_type,
891 typename checkpoint_type,
892 typename submatrix_type,
893 typename backtracer_type>
898 const uint32 checkpoint_id,
899 submatrix_type submatrix,
900 const uint32 submatrix_height,
903 backtracer_type& backtracer)
908 int32 current_entry = sink.x - sink.y;
909 int32 current_row = sink.y - checkpoint_id*CHECKPOINTS - 1u;
912 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 );
913 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 );
914 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 );
916 while (current_row >= 0)
918 const uint32 submatrix_cell = current_row * BAND_LEN + current_entry;
919 const uint8 op = submatrix[ submatrix_cell ];
926 sink.y = current_row + checkpoint_id*CHECKPOINTS + 1u;
927 sink.x = current_entry + sink.y;
941 ++current_entry; --current_row;
959 sink.y = checkpoint_id*CHECKPOINTS;
960 sink.x = current_entry + sink.y;