55 template <u
int32 BAND_LEN, AlignmentType TYPE,
typename algorithm_tag = PatternBlockingTag>
66 template <
typename column_type,
typename scoring_type,
typename score_type>
72 const scoring_type& scoring,
73 const score_type zero)
77 for (
uint32 i = 0; i < N; ++i)
87 template <
typename column_type>
99 template <
typename column_type>
115 template <
typename score_type>
122 const score_type score,
130 template <u
int32 BAND_LEN, AlignmentType TYPE,
typename algorithm_tag,
typename checkpo
int_type = PatternBlockingTag>
147 template <
typename column_type,
typename scoring_type,
typename score_type>
153 const scoring_type& scoring,
154 const score_type zero)
158 for (
uint32 i = 0; i < N; ++i)
163 for (
uint32 i = 0; i < N; ++i)
173 template <
typename column_type>
185 template <
typename column_type>
193 for (
uint32 i = 0; i < N; ++i)
208 template <
typename score_type>
215 const score_type score,
224 template <u
int32 BAND_LEN, AlignmentType TYPE, u
int32 CHECKPOINTS,
typename checkpo
int_type>
238 template <
typename column_type,
typename scoring_type,
typename score_type>
244 const scoring_type& scoring,
245 const score_type zero)
247 for (
uint32 i = 0; i < N; ++i)
256 template <
typename column_type>
264 if ((j & (CHECKPOINTS-1)) == 0u)
266 const uint32 checkpoint_id = j / CHECKPOINTS;
268 for (
uint32 i = 0; i < N; ++i)
278 template <
typename column_type>
294 template <
typename score_type>
301 const score_type score,
311 template <u
int32 BAND_LEN, AlignmentType TYPE, u
int32 CHECKPOINTS,
typename checkpo
int_type,
typename submatrix_type>
317 const uint32 checkpoint_id,
318 const submatrix_type submatrix) :
330 template <
typename column_type,
typename scoring_type,
typename score_type>
336 const scoring_type& scoring,
337 const score_type zero)
340 for (
uint32 i = 0; i < N; ++i)
349 template <
typename column_type>
361 template <
typename column_type>
377 template <
typename score_type>
384 const score_type score,
393 m_submatrix[ i * CHECKPOINTS + (j - offset) ] = dir;
403 template <u
int32 BAND_LEN, AlignmentType TYPE,
typename algorithm_tag,
typename symbol_type>
413 template <u
int32 BAND_LEN, AlignmentType TYPE,
typename symbol_type>
418 typename context_type,
419 typename query_cache,
421 typename temp_iterator,
423 typename scoring_type>
426 context_type& context,
431 const symbol_type r_i,
432 const query_cache q_cache,
437 score_type& max_score,
438 const score_type zero,
439 const scoring_type scoring)
442 score_type prev = temp_i;
445 band[0] = temp_i = temp[i];
449 for (
uint32 j = 1; j <= BAND_LEN; ++j)
451 const symbol_type q_j = q_cache[ j-1 ].x;
452 const uint8 qq_j = q_cache[ j-1 ].y;
453 const score_type S_ij = (r_i == q_j) ? scoring.match(qq_j) : scoring.mismatch( r_i, q_j, qq_j );
454 score_type hi = prev + S_ij;
459 if ((CHECK_M ==
false) || (block + j <= M))
470 temp[i] = band[ BAND_LEN ];
472 max_score =
nvbio::max( max_score, band[ BAND_LEN ] );
479 for (
uint32 j = 1; j <= BAND_LEN; ++j)
482 sink.report( band[j], make_uint2( i+1, block+j ) );
488 for (
uint32 j = 1; j <= BAND_LEN; ++j)
489 sink.report( band[j], make_uint2( i+1, block+j ) );
497 save_boundary<BAND_LEN>( block, M, band, i, sink );
575 typename context_type,
576 typename string_type,
579 typename scoring_type,
585 const scoring_type& scoring,
586 context_type& context,
590 const int32 min_score,
592 const uint32 window_begin,
596 const uint32 M = query.length();
597 const uint32 N = ref.length();
599 typedef int32 score_type;
600 score_type band[BAND_LEN+1];
602 const score_type zero = score_type(0);
609 uint2 q_cache[ BAND_LEN ];
612 context.init( window_begin, N, temp, scoring, zero );
614 const uint32 end_block = (window_end == M) ?
615 nvbio::max( BAND_LEN, BAND_LEN * ((M + BAND_LEN-1) / BAND_LEN) ) :
616 window_end + BAND_LEN;
619 for (
uint32 block = window_begin; block + BAND_LEN < end_block; block += BAND_LEN)
622 context.previous_column( block, N, temp );
626 for (
uint32 j = 0; j <= BAND_LEN; ++j)
631 for (
uint32 t = 0; t < BAND_LEN; ++t)
632 q_cache[ t ] = make_uint2( query[ block + t ], quals[ block + t ] );
636 score_type temp_i = band[0];
639 for (
uint32 i = 0; i < N; ++i)
642 const uint8 r_i = ref[i];
661 const score_type missing_cols = score_type(M - block - BAND_LEN);
662 if (max_score + missing_cols * scoring.match(255) < score_type( min_score ))
668 const uint32 block = end_block - BAND_LEN;
671 context.previous_column( block, N, temp );
674 for (
uint32 j = 0; j <= BAND_LEN; ++j)
680 for (
uint32 t = 0; t < BAND_LEN; ++t)
682 if (block + t < block_end)
683 q_cache[ t ] = make_uint2( query[ block + t ], quals[ block + t ] );
688 score_type temp_i = band[0];
691 for (
uint32 i = 0; i < N; ++i)
694 const uint8 r_i = ref[i];
713 context.last_column( window_end, M, N, temp );
716 save_Mth<BAND_LEN>( M, band, N-1, sink );
797 typename context_type,
798 typename string_type,
801 typename scoring_type,
806 const scoring_type& scoring,
807 context_type& context,
811 const int32 min_score,
813 const uint32 window_begin,
817 int16 temp[MAX_REF_LEN];
818 int16* temp_ptr = temp;
841 template <u
int32 BAND_LEN, AlignmentType TYPE,
typename symbol_type>
846 typename context_type,
849 typename temp_iterator,
851 typename scoring_type>
854 context_type& context,
859 const symbol_type q_i,
861 const score_type m_i,
862 const ref_cache r_cache,
867 score_type& max_score,
868 const score_type zero,
869 const scoring_type scoring)
872 score_type prev = temp_i;
875 band[0] = temp_i = temp[i];
879 for (
uint32 j = 1; j <= BAND_LEN; ++j)
881 const symbol_type r_j = r_cache[ j-1 ];
882 const score_type S_ij = (r_j == q_i) ? m_i : scoring.mismatch( r_j, q_i, qq_i );
883 score_type hi = prev + S_ij;
888 if ((CHECK_N ==
false) || (block + j <= N))
899 temp[i] = band[ BAND_LEN ];
901 max_score =
nvbio::max( max_score, band[ BAND_LEN ] );
908 for (
uint32 j = 1; j <= BAND_LEN; ++j)
911 sink.report( band[j], make_uint2( block+j, i+1 ) );
917 for (
uint32 j = 1; j <= BAND_LEN; ++j)
918 sink.report( band[j], make_uint2( block+j, i+1 ) );
996 typename context_type,
997 typename string_type,
1000 typename scoring_type,
1006 const scoring_type& scoring,
1007 context_type& context,
1011 const int32 min_score,
1013 const uint32 window_begin,
1017 const uint32 M = query.length();
1018 const uint32 N = ref.length();
1020 typedef int32 score_type;
1021 score_type band[BAND_LEN+1];
1023 const score_type zero = score_type(0);
1029 uint8 r_cache[ BAND_LEN ];
1032 context.init( window_begin, M, temp, scoring, zero );
1034 const uint32 end_block = (window_end == N) ?
1035 nvbio::max( BAND_LEN, BAND_LEN * ((N + BAND_LEN-1) / BAND_LEN) ) :
1036 window_end + BAND_LEN;
1039 for (
uint32 block = window_begin; block + BAND_LEN < end_block; block += BAND_LEN)
1042 context.previous_column( block, M, temp );
1046 for (
uint32 j = 0; j <= BAND_LEN; ++j)
1051 for (
uint32 t = 0; t < BAND_LEN; ++t)
1052 r_cache[ t ] = ref[ block + t ];
1056 score_type temp_i = band[0];
1059 for (
uint32 i = 0; i < M; ++i)
1062 const uint8 q_i = query[i];
1063 const uint8 qq_i = quals[i];
1065 const int32 m_i = scoring.match(qq_i);
1086 for (
uint32 j = 1; j <= BAND_LEN; ++j)
1087 sink.report( band[j], make_uint2( block+j, M ) );
1091 if (window_end == N)
1093 const uint32 block = end_block - BAND_LEN;
1096 context.previous_column( block, M, temp );
1100 for (
uint32 j = 0; j <= BAND_LEN; ++j)
1106 for (
uint32 t = 0; t < BAND_LEN; ++t)
1108 if (block + t < block_end)
1109 r_cache[ t ] = ref[ block + t ];
1114 score_type temp_i = band[0];
1117 for (
uint32 i = 0; i < M; ++i)
1120 const uint8 q_i = query[i];
1121 const uint8 qq_i = quals[i];
1123 const int32 m_i = scoring.match(qq_i);
1145 for (
uint32 j = 1; j <= BAND_LEN; ++j)
1148 sink.report( band[j], make_uint2( block+j, M ) );
1154 for (
uint32 j = 1; j <= BAND_LEN; ++j)
1157 sink.report( band[j], make_uint2( block+j, M ) );
1163 context.last_column( window_end, N, M, temp );
1243 typename context_type,
1244 typename string_type,
1247 typename scoring_type,
1252 const scoring_type& scoring,
1253 context_type& context,
1257 const int32 min_score,
1259 const uint32 window_begin,
1263 int16 temp[MAX_PATTERN_LEN];
1264 int16* temp_ptr = temp;
1280 template <AlignmentType TYPE, u
int32 DIM,
typename symbol_type>
1286 template <AlignmentType TYPE, u
int32 DIM>
1289 #if __CUDA_ARCH__ >= 300
1307 typename scoring_type,
1308 typename algorithm_tag,
1309 typename pattern_string,
1310 typename qual_string,
1311 typename text_string,
1334 template <
typename sink_type>
1338 const pattern_string pattern,
1339 const qual_string quals,
1340 const text_string
text,
1341 const int32 min_score,
1345 typedef typename pattern_string::value_type symbol_type;
1351 const uint32 length = equal<algorithm_tag,PatternBlockingTag>() ? pattern.length() : text.length();
1353 return hamming_alignment_score_dispatch<BAND_LEN,TYPE,algorithm_tag,symbol_type>::run( aligner.
scheme, context, pattern, quals, text, min_score, sink, 0, length, column );
1373 typename checkpoint_type>
1377 const pattern_string pattern,
1378 const qual_string quals,
1379 const text_string
text,
1380 const int32 min_score,
1381 const uint32 window_begin,
1384 checkpoint_type checkpoint,
1387 typedef typename pattern_string::value_type symbol_type;
1393 return hamming_alignment_score_dispatch<BAND_LEN,TYPE,algorithm_tag,symbol_type>::run( aligner.
scheme, context, pattern, quals, text, min_score, sink, window_begin, window_end, column );
1409 template <
typename sink_type>
1413 const pattern_string pattern,
1414 const qual_string quals,
1415 const text_string
text,
1416 const int32 min_score,
1417 const uint32 window_begin,
1422 typedef typename pattern_string::value_type symbol_type;
1428 return hamming_alignment_score_dispatch<BAND_LEN,TYPE,algorithm_tag,symbol_type>::run( aligner.
scheme, context, pattern, quals, text, min_score, sink, window_begin, window_end, column );
1445 typename scoring_type,
1446 typename pattern_string,
1447 typename qual_string,
1448 typename text_string,
1481 typename checkpoint_type>
1486 const pattern_string pattern,
1487 const qual_string quals,
1488 const text_string
text,
1489 const int32 min_score,
1494 typedef typename pattern_string::value_type symbol_type;
1500 hamming_alignment_score_dispatch<BAND_LEN,TYPE,PatternBlockingTag,symbol_type>::run( aligner.
scheme, context, pattern, quals, text, min_score, sink, 0, pattern.length(),
column );
1528 typename checkpoint_type,
1529 typename submatrix_type>
1534 const pattern_string pattern,
1535 const qual_string quals,
1536 const text_string
text,
1537 const int32 min_score,
1539 const uint32 checkpoint_id,
1540 submatrix_type submatrix,
1543 typedef typename pattern_string::value_type symbol_type;
1548 context( checkpoints, checkpoint_id, submatrix );
1550 const uint32 window_begin = checkpoint_id * CHECKPOINTS;
1554 hamming_alignment_score_dispatch<BAND_LEN,TYPE,PatternBlockingTag,symbol_type>::run( aligner.
scheme, context, pattern, quals, text, min_score, null_sink, window_begin, window_end, column );
1556 return window_end - window_begin;
1598 typename scoring_type,
1599 typename checkpoint_type,
1600 typename submatrix_type,
1601 typename output_type>
1606 const uint32 checkpoint_id,
1607 submatrix_type submatrix,
1608 const uint32 submatrix_width,
1609 const uint32 submatrix_height,
1612 output_type& output)
1617 int32 current_row = sink.x;
1618 int32 current_col = sink.y - checkpoint_id*CHECKPOINTS - 1u;
1621 current_row <= submatrix_height,
"hamming::alignment_backtrack(): sink (%u,%u) -> local x coordinate %d not in [0,%d[\n", sink.x, sink.y, current_row, submatrix_height );
1622 NVBIO_CUDA_DEBUG_ASSERT( current_col >= 0,
"hamming::alignment_backtrack(): sink (%u,%u) -> local y coordinate %d not in [0,%u[ (checkpt %u)\n", sink.x, sink.y, current_col, submatrix_width, checkpoint_id );
1623 NVBIO_CUDA_DEBUG_ASSERT( current_col < submatrix_width,
"hamming::alignment_backtrack(): sink (%u,%u) -> local y coordinate %d not in [0,%u[ (checkpt %u)\n", sink.x, sink.y, current_col, submatrix_width, checkpoint_id );
1625 while (current_row > 0 &&
1628 const uint32 submatrix_cell = (current_row-1u) * CHECKPOINTS + current_col;
1629 const uint8 op = submatrix[ submatrix_cell ];
1635 sink.x = current_row;
1636 sink.y = current_col + checkpoint_id*CHECKPOINTS + 1u;
1643 sink.x = current_row;
1644 sink.y = current_col + checkpoint_id*CHECKPOINTS + 1u;
1645 return current_row ?
false :
true;