diff --git a/Makefile b/Makefile index 5188d2d6..fbc4c111 100644 --- a/Makefile +++ b/Makefile @@ -44,7 +44,7 @@ ifeq ($(BUILD_EXAMPLES),1) APPS+=examples endif -all: CC_FLAGS+=-O3 -march=native -flto +all: CC_FLAGS+=-O3 -march=native #-flto -ffat-lto-objects all: build debug: build diff --git a/alignment/cigar.c b/alignment/cigar.c index 46ed26b4..8a18ab93 100644 --- a/alignment/cigar.c +++ b/alignment/cigar.c @@ -251,6 +251,41 @@ void cigar_copy( cigar_src->operations+cigar_src->begin_offset, cigar_src->end_offset-cigar_src->begin_offset); } +void cigar_append( + cigar_t* const cigar_dst, + cigar_t* const cigar_src) { + // Append + const int cigar_length = cigar_src->end_offset - cigar_src->begin_offset; + char* const operations_src = cigar_src->operations + cigar_src->begin_offset; + char* const operations_dst = cigar_dst->operations + cigar_dst->end_offset; + memcpy(operations_dst,operations_src,cigar_length); + // Update offset + cigar_dst->end_offset += cigar_length; +} +void cigar_append_deletion( + cigar_t* const cigar, + const int length) { + // Append deletions + char* const operations = cigar->operations + cigar->end_offset; + int i; + for (i=0;iend_offset += length; +} +void cigar_append_insertion( + cigar_t* const cigar, + const int length) { + // Append insertions + char* const operations = cigar->operations + cigar->end_offset; + int i; + for (i=0;iend_offset += length; +} bool cigar_check_alignment( FILE* const stream, const char* const pattern, diff --git a/alignment/cigar.h b/alignment/cigar.h index d509c425..51cd7687 100644 --- a/alignment/cigar.h +++ b/alignment/cigar.h @@ -104,6 +104,17 @@ int cigar_cmp( void cigar_copy( cigar_t* const cigar_dst, cigar_t* const cigar_src); + +void cigar_append( + cigar_t* const cigar_dst, + cigar_t* const cigar_src); +void cigar_append_deletion( + cigar_t* const cigar, + const int length); +void cigar_append_insertion( + cigar_t* const cigar, + const int length); + bool cigar_check_alignment( FILE* const stream, const char* const pattern, diff --git a/scripts/wfa.alg.cmp.py b/scripts/wfa.alg.cmp.py index 6f82437c..2ccb8e1f 100644 --- a/scripts/wfa.alg.cmp.py +++ b/scripts/wfa.alg.cmp.py @@ -117,8 +117,9 @@ def plot_score_distribution(stats,input_path1,input_path2): # ax1.xaxis.grid(True) # ax1.yaxis.grid(True) # Plot score histogram - ax1.hist(stats.scores1,color="royalblue",edgecolor = 'black',alpha=0.75) - ax1.hist(stats.scores2,color="darkorange",edgecolor = 'black',alpha=0.75) + b=range(min(stats.scores1+stats.scores2), max(stats.scores1+stats.scores2) + 10, 10) + ax1.hist(stats.scores1,bins=b,color="royalblue",edgecolor = 'black',alpha=0.75) + ax1.hist(stats.scores2,bins=b,color="darkorange",edgecolor = 'black',alpha=0.75) # Leyend handles = [Rectangle((0,0),1,1,color=c,ec="k") for c in ["royalblue","darkorange"]] labels= [input_path1,input_path2] @@ -155,11 +156,11 @@ def compare_alignments(input_path1,input_path2,penalties,use_score,ignore_misms, if use_score: cigar1 = None cigar2 = None - score1 = fields1[0] if len(fields1)==2 else fields1[2] - score2 = fields2[0] if len(fields2)==2 else fields2[2] + score1 = fields1[0] if len(fields1)<=2 else fields1[2] + score2 = fields2[0] if len(fields2)<=2 else fields2[2] else: - cigar1 = fields1[1] if len(fields1)==2 else fields1[5] - cigar2 = fields2[1] if len(fields2)==2 else fields2[5] + cigar1 = fields1[1] if len(fields1)<=2 else fields1[5] + cigar2 = fields2[1] if len(fields2)<=2 else fields2[5] # Evaluate CIGAR's score score1 = cigar_compute_score(cigar1,penalties,ignore_misms) score2 = cigar_compute_score(cigar2,penalties,ignore_misms) diff --git a/scripts/wfa.utest.cmp.alignments.sh b/scripts/wfa.utest.cmp.alignments.sh index 80a4cc95..68b221e0 100644 --- a/scripts/wfa.utest.cmp.alignments.sh +++ b/scripts/wfa.utest.cmp.alignments.sh @@ -17,15 +17,21 @@ do FILE_ALG2="$FOLDER2/$FILENAME" echo -ne "[UTest::$PREFIX] \t" # Check existence - if [[ ! -f "$FILE_ALG2" ]]; then + if [[ ! -f "$FILE_ALG2" ]] + then echo "$FILE_ALG2 doesn't exist." continue fi # Check diff if [[ $(diff $FILE_ALG1 $FILE_ALG2) ]] then - echo "Error" - continue + if [[ $(diff <(awk '{print $1}' $FILE_ALG1) <(awk '{print $1}' $FILE_ALG2)) ]] + then + echo "Error" + continue + else + echo -n "OK-Score" + fi else echo -n "OK" fi diff --git a/tools/align_benchmark/align_benchmark.c b/tools/align_benchmark/align_benchmark.c index 9a66fb9d..4dd2e317 100644 --- a/tools/align_benchmark/align_benchmark.c +++ b/tools/align_benchmark/align_benchmark.c @@ -798,7 +798,7 @@ void parse_arguments(int argc,char** argv) { /* Other alignment parameters */ { "bandwidth", required_argument, 0, 2000 }, /* Misc */ - { "check", optional_argument, 0, 'c' }, + { "check", required_argument, 0, 'c' }, { "check-distance", required_argument, 0, 3001 }, { "check-bandwidth", required_argument, 0, 3002 }, { "plot", optional_argument, 0, 3003 }, @@ -996,9 +996,9 @@ void parse_arguments(int argc,char** argv) { * Misc */ case 'c': - if (optarg == NULL) { // default = score + if (optarg == NULL) { // default = correct parameters.check_correct = true; - parameters.check_score = true; + parameters.check_score = false; parameters.check_alignments = false; } else if (strcasecmp(optarg,"display")==0) { parameters.check_display = true; diff --git a/tools/align_benchmark/benchmark/benchmark_utils.c b/tools/align_benchmark/benchmark/benchmark_utils.c index 6aecbfe8..3b82a900 100644 --- a/tools/align_benchmark/benchmark/benchmark_utils.c +++ b/tools/align_benchmark/benchmark/benchmark_utils.c @@ -107,7 +107,7 @@ void benchmark_print_output_lite( const int score, cigar_t* const cigar) { // Retrieve CIGAR - char* const cigar_str = malloc(cigar->end_offset-cigar->begin_offset); + char* const cigar_str = malloc(2*(cigar->end_offset-cigar->begin_offset)); cigar_sprint(cigar_str,cigar,true); // Print fprintf(stream,"%d\t%s\n",score,cigar_str); @@ -120,7 +120,7 @@ void benchmark_print_output_full( const int score, cigar_t* const cigar) { // Retrieve CIGAR - char* const cigar_str = malloc(cigar->end_offset-cigar->begin_offset); + char* const cigar_str = malloc(2*(cigar->end_offset-cigar->begin_offset)); cigar_sprint(cigar_str,cigar,true); // Print fprintf(stream,"%d\t%d\t%d\t%s\t%s\t%s\n", diff --git a/utils/string_padded.c b/utils/string_padded.c index 41b05b55..4222d2fd 100644 --- a/utils/string_padded.c +++ b/utils/string_padded.c @@ -43,6 +43,7 @@ void strings_padded_add_padding( const char padding_value, char** const buffer_padded, char** const buffer_padded_begin, + const bool reverse_sequence, mm_allocator_t* const mm_allocator) { // Allocate const int buffer_padded_length = begin_padding_length + buffer_length + end_padding_length; @@ -51,7 +52,14 @@ void strings_padded_add_padding( memset(*buffer_padded,padding_value,begin_padding_length); // Copy buffer *buffer_padded_begin = *buffer_padded + begin_padding_length; - memcpy(*buffer_padded_begin,buffer,buffer_length); + if (reverse_sequence) { + int i; + for (i=0;ipattern_padded_buffer), - &(strings_padded->pattern_padded),mm_allocator); + &(strings_padded->pattern_padded), + reverse_sequences,mm_allocator); strings_padded_add_padding( text,text_length, text_begin_padding_length,text_end_padding_length,'!', &(strings_padded->text_padded_buffer), - &(strings_padded->text_padded),mm_allocator); + &(strings_padded->text_padded), + reverse_sequences,mm_allocator); // Return return strings_padded; } @@ -91,6 +102,7 @@ strings_padded_t* strings_padded_new_rhomb( const char* const text, const int text_length, const int padding_length, + const bool reverse_sequences, mm_allocator_t* const mm_allocator) { // Allocate strings_padded_t* const strings_padded = @@ -106,12 +118,14 @@ strings_padded_t* strings_padded_new_rhomb( pattern,pattern_length, pattern_begin_padding_length,pattern_end_padding_length,'?', &(strings_padded->pattern_padded_buffer), - &(strings_padded->pattern_padded),mm_allocator); + &(strings_padded->pattern_padded), + reverse_sequences,mm_allocator); strings_padded_add_padding( text,text_length, text_begin_padding_length,text_end_padding_length,'!', &(strings_padded->text_padded_buffer), - &(strings_padded->text_padded),mm_allocator); + &(strings_padded->text_padded), + reverse_sequences,mm_allocator); // Set lengths strings_padded->pattern_length = pattern_length; strings_padded->text_length = text_length; diff --git a/utils/string_padded.h b/utils/string_padded.h index a9a761a8..ee7a250a 100644 --- a/utils/string_padded.h +++ b/utils/string_padded.h @@ -63,6 +63,7 @@ strings_padded_t* strings_padded_new( const char* const text, const int text_length, const int padding_length, + const bool reverse_sequences, mm_allocator_t* const mm_allocator); strings_padded_t* strings_padded_new_rhomb( const char* const pattern, @@ -70,6 +71,7 @@ strings_padded_t* strings_padded_new_rhomb( const char* const text, const int text_length, const int padding_length, + const bool reverse_sequences, mm_allocator_t* const mm_allocator); void strings_padded_delete( strings_padded_t* const strings_padded); diff --git a/wavefront/wavefront.c b/wavefront/wavefront.c index 547e1344..eb4bfce1 100644 --- a/wavefront/wavefront.c +++ b/wavefront/wavefront.c @@ -92,7 +92,6 @@ void wavefront_init( wavefront->null = false; wavefront->lo = 1; wavefront->hi = -1; - wavefront->k_alignment_end = WAVEFRONT_DIAGONAL_NULL; wavefront->bt_occupancy_max = 0; // Setup elements wavefront->offsets = wavefront->offsets_mem - min_lo; // Center at k=0 @@ -114,7 +113,6 @@ void wavefront_init_null( wavefront->null = true; wavefront->lo = 1; wavefront->hi = -1; - wavefront->k_alignment_end = WAVEFRONT_DIAGONAL_NULL; wavefront->bt_occupancy_max = 0; // Setup elements wavefront->offsets = wavefront->offsets_mem - min_lo; // Center at k=0 diff --git a/wavefront/wavefront.h b/wavefront/wavefront.h index c9527bb4..c0c920cb 100644 --- a/wavefront/wavefront.h +++ b/wavefront/wavefront.h @@ -37,6 +37,15 @@ #include "wavefront_offset.h" #include "wavefront_backtrace_buffer.h" +/* + * Alignment position + */ +typedef struct { + int score; // Score + int k; // Diagonal + wf_offset_t offset; // Offset +} wavefront_pos_t; + /* * Wavefront */ @@ -50,7 +59,6 @@ typedef struct { bool null; // Is null interval? int lo; // Lowest diagonal (inclusive) int hi; // Highest diagonal (inclusive) - int k_alignment_end; // Mark WF's diagonal that reached the end of the alignment (semi-global) int bt_occupancy_max; // Maximum number of pcigar-ops stored on the Backtrace-block // Wavefront elements wf_offset_t* offsets; // Offsets (k-centered) diff --git a/wavefront/wavefront_align.c b/wavefront/wavefront_align.c index 2ab3bc38..0df59127 100644 --- a/wavefront/wavefront_align.c +++ b/wavefront/wavefront_align.c @@ -108,7 +108,7 @@ bool wavefront_align_reached_limits( return false; } /* - * Initialize end-to-end alignment (Global) + * Initialize alignment */ void wavefront_align_end2end_initialize( wavefront_aligner_t* const wf_aligner) { @@ -138,11 +138,12 @@ void wavefront_align_end2end_initialize( wf_components->d2wavefronts[0] = NULL; wf_components->i2wavefronts[0] = NULL; } -/* - * Initialize ends-free alignment (Semiglobal/glocal/...) - */ void wavefront_align_endsfree_initialize( - wavefront_aligner_t* const wf_aligner) { + wavefront_aligner_t* const wf_aligner, + const int pattern_length, + const int text_length) { + // Check + wavefront_check_endsfree_form(wf_aligner,pattern_length,text_length); // Parameters wavefront_components_t* const wf_components = &wf_aligner->wf_components; const distance_metric_t distance_metric = wf_aligner->penalties.distance_metric; @@ -166,8 +167,8 @@ void wavefront_align_endsfree_initialize( // Init text begin-free int h; for (h=1;h<=text_begin_free;++h) { - const int k = WAVEFRONT_DIAGONAL(h,0); - wf_components->mwavefronts[0]->offsets[k] = WAVEFRONT_OFFSET(h,0); + const int k = DPMATRIX_DIAGONAL(h,0); + wf_components->mwavefronts[0]->offsets[k] = DPMATRIX_OFFSET(h,0); if (wf_components->bt_piggyback) { const bt_block_idx_t block_idx = wf_backtrace_buffer_init_block(wf_components->bt_buffer,0,h); wf_components->mwavefronts[0]->bt_pcigar[k] = 0; @@ -177,8 +178,8 @@ void wavefront_align_endsfree_initialize( // Init pattern begin-free int v; for (v=1;v<=pattern_begin_free;++v) { - const int k = WAVEFRONT_DIAGONAL(0,v); - wf_components->mwavefronts[0]->offsets[k] = WAVEFRONT_OFFSET(0,v); + const int k = DPMATRIX_DIAGONAL(0,v); + wf_components->mwavefronts[0]->offsets[k] = DPMATRIX_OFFSET(0,v); if (wf_components->bt_piggyback) { const bt_block_idx_t block_idx = wf_backtrace_buffer_init_block(wf_components->bt_buffer,v,0); wf_components->mwavefronts[0]->bt_pcigar[k] = 0; @@ -198,36 +199,40 @@ void wavefront_align_endsfree_initialize( */ void wavefront_align_terminate( wavefront_aligner_t* const wf_aligner, - const int score_final) { - // Parameters - wavefront_components_t* const wf_components = &wf_aligner->wf_components; - int score = score_final; - // Fetch wavefront - if (wf_components->memory_modular) score = score % wf_components->max_score_scope; - wavefront_t* const mwavefront = wf_components->mwavefronts[score]; + const int score) { // Retrieve alignment if (wf_aligner->alignment_scope == compute_score) { cigar_clear(&wf_aligner->cigar); + wf_aligner->cigar.score = -score; } else { - const int alignment_k = mwavefront->k_alignment_end; - const wf_offset_t alignment_offset = mwavefront->offsets[alignment_k]; + // Parameters + wavefront_components_t* const wf_components = &wf_aligner->wf_components; + const int alignment_end_k = wf_aligner->alignment_end_pos.k; + const wf_offset_t alignment_end_offset = wf_aligner->alignment_end_pos.offset; if (wf_components->bt_piggyback) { + // Fetch wavefront + const bool memory_modular = wf_aligner->wf_components.memory_modular; + const int max_score_scope = wf_aligner->wf_components.max_score_scope; + const int score_mod = (memory_modular) ? score % max_score_scope : score; + wavefront_t* const mwavefront = wf_components->mwavefronts[score_mod]; // Backtrace alignment from buffer (unpacking pcigar) wavefront_backtrace_pcigar( - wf_aligner,alignment_k,alignment_offset, - mwavefront->bt_pcigar[alignment_k], - mwavefront->bt_prev[alignment_k]); + wf_aligner,alignment_end_k,alignment_end_offset, + mwavefront->bt_pcigar[alignment_end_k], + mwavefront->bt_prev[alignment_end_k]); } else { // Backtrace alignment if (wf_aligner->penalties.distance_metric <= gap_linear) { - wavefront_backtrace_linear(wf_aligner,score,alignment_k,alignment_offset); + wavefront_backtrace_linear(wf_aligner, + score,alignment_end_k,alignment_end_offset); } else { - wavefront_backtrace_affine(wf_aligner,score,alignment_k,alignment_offset); + wavefront_backtrace_affine(wf_aligner, + score,alignment_end_k,alignment_end_offset); } } + // Set score & finish + wf_aligner->cigar.score = -score; } - // Set score & finish - wf_aligner->cigar.score = -score_final; } /* * General Alignment @@ -237,12 +242,12 @@ int wavefront_align_sequences( // Parameters wavefront_align_status_t* const wf_align_status = &wf_aligner->align_status; void (*wf_align_compute)(wavefront_aligner_t* const,const int) = wf_align_status->wf_align_compute; - bool (*wf_align_extend)(wavefront_aligner_t* const,const int) = wf_align_status->wf_align_extend; + int (*wf_align_extend)(wavefront_aligner_t* const,const int) = wf_align_status->wf_align_extend; // Compute wavefronts of increasing score int score = wf_aligner->align_status.score; while (true) { // Exact extend s-wavefront - const bool finished = (*wf_align_extend)(wf_aligner,score); + const int finished = (*wf_align_extend)(wf_aligner,score); if (finished) { // DEBUG // wavefront_aligner_print(stderr,wf_aligner,0,score,7,0); @@ -283,9 +288,7 @@ void wavefront_align_begin( // DEBUG wavefront_debug_prologue(wf_aligner,pattern,pattern_length,text,text_length); // Resize wavefront aligner - wavefront_aligner_resize(wf_aligner,pattern,pattern_length,text,text_length); - // DEBUG - // mm_allocator_print(stderr,wf_aligner->mm_allocator,false); + wavefront_aligner_resize(wf_aligner,pattern,pattern_length,text,text_length,false); // Configure WF-compute function switch (wf_aligner->penalties.distance_metric) { case indel: @@ -316,11 +319,12 @@ void wavefront_align_begin( wf_align_status->wf_align_extend = &wavefront_extend_endsfree; } // Initialize wavefront + wf_aligner->alignment_end_pos.score = -1; // Not aligned + wf_aligner->alignment_end_pos.k = DPMATRIX_DIAGONAL_NULL; if (end2end) { wavefront_align_end2end_initialize(wf_aligner); } else { - wavefront_check_endsfree_form(wf_aligner,pattern_length,text_length); - wavefront_align_endsfree_initialize(wf_aligner); + wavefront_align_endsfree_initialize(wf_aligner,pattern_length,text_length); } // Plot WF-0 const bool plot = wf_aligner->plot_params.plot_enabled; diff --git a/wavefront/wavefront_align.h b/wavefront/wavefront_align.h index ccdf8d4f..40cddf4b 100644 --- a/wavefront/wavefront_align.h +++ b/wavefront/wavefront_align.h @@ -35,6 +35,16 @@ #include "wavefront_aligner.h" #include "wavefront_display.h" // For convenience +/* + * Initialize alignment + */ +void wavefront_align_end2end_initialize( + wavefront_aligner_t* const wf_aligner); +void wavefront_align_endsfree_initialize( + wavefront_aligner_t* const wf_aligner, + const int pattern_length, + const int text_length); + /* * Wavefront Alignment */ diff --git a/wavefront/wavefront_aligner.c b/wavefront/wavefront_aligner.c index f8460e86..c2807f76 100644 --- a/wavefront/wavefront_aligner.c +++ b/wavefront/wavefront_aligner.c @@ -178,9 +178,7 @@ wavefront_aligner_t* wavefront_aligner_new( wf_aligner->alignment_scope = attributes->alignment_scope; wf_aligner->alignment_form = attributes->alignment_form; wavefront_aligner_set_penalties(wf_aligner,attributes); - // Memory mode wf_aligner->memory_mode = attributes->memory_mode; - // Heuristic strategy wavefront_aligner_set_heuristic(wf_aligner,attributes); // Custom matching functions wf_aligner->match_funct = attributes->match_funct; @@ -190,7 +188,9 @@ wavefront_aligner_t* wavefront_aligner_new( &wf_aligner->wf_components,pattern_length,text_length, &wf_aligner->penalties,memory_modular,bt_piggyback,mm_allocator); // CIGAR - cigar_allocate(&wf_aligner->cigar,2*(pattern_length+text_length),mm_allocator); + if (!score_only) { + cigar_allocate(&wf_aligner->cigar,2*(pattern_length+text_length),mm_allocator); + } // Display wf_aligner->plot_params = attributes->plot_params; if (attributes->plot_params.plot_enabled) { @@ -209,7 +209,10 @@ void wavefront_aligner_resize( const char* const pattern, const int pattern_length, const char* const text, - const int text_length) { + const int text_length, + const bool reverse_sequences) { + // Parameters + const bool score_only = (wf_aligner->alignment_scope == compute_score); // Configure sequences and status wf_aligner->pattern_length = pattern_length; wf_aligner->text_length = text_length; @@ -217,7 +220,8 @@ void wavefront_aligner_resize( if (wf_aligner->sequences != NULL) strings_padded_delete(wf_aligner->sequences); wf_aligner->sequences = strings_padded_new_rhomb( pattern,pattern_length,text,text_length, - SEQUENCES_PADDING,wf_aligner->mm_allocator); + SEQUENCES_PADDING,reverse_sequences, + wf_aligner->mm_allocator); wf_aligner->pattern = wf_aligner->sequences->pattern_padded; wf_aligner->text = wf_aligner->sequences->text_padded; } else { @@ -232,7 +236,9 @@ void wavefront_aligner_resize( wavefront_components_resize(&wf_aligner->wf_components, pattern_length,text_length,&wf_aligner->penalties); // CIGAR - cigar_resize(&wf_aligner->cigar,2*(pattern_length+text_length)); + if (!score_only) { + cigar_resize(&wf_aligner->cigar,2*(pattern_length+text_length)); + } // Slab wavefront_slab_clear(wf_aligner->wavefront_slab); // Display @@ -260,6 +266,7 @@ void wavefront_aligner_reap( void wavefront_aligner_delete( wavefront_aligner_t* const wf_aligner) { // Parameters + const bool score_only = (wf_aligner->alignment_scope == compute_score); mm_allocator_t* const mm_allocator = wf_aligner->mm_allocator; // Padded sequences if (wf_aligner->sequences != NULL) { @@ -268,7 +275,9 @@ void wavefront_aligner_delete( // Wavefront components wavefront_components_free(&wf_aligner->wf_components); // CIGAR - cigar_free(&wf_aligner->cigar); + if (!score_only) { + cigar_free(&wf_aligner->cigar); + } // Slab wavefront_slab_delete(wf_aligner->wavefront_slab); // Display diff --git a/wavefront/wavefront_aligner.h b/wavefront/wavefront_aligner.h index f905801a..7618e014 100644 --- a/wavefront/wavefront_aligner.h +++ b/wavefront/wavefront_aligner.h @@ -67,7 +67,7 @@ typedef struct { int score; // Current WF-alignment score // Wavefront alignment functions void (*wf_align_compute)(wavefront_aligner_t* const,const int); // WF Compute function - bool (*wf_align_extend)(wavefront_aligner_t* const,const int); // WF Extend function + int (*wf_align_extend)(wavefront_aligner_t* const,const int); // WF Extend function } wavefront_align_status_t; /* @@ -93,6 +93,7 @@ typedef struct _wavefront_aligner_t { void* match_funct_arguments; // Generic arguments passed to matching function (args) // Wavefront components wavefront_components_t wf_components; // Wavefront components + wavefront_pos_t alignment_end_pos; // Alignment end position // CIGAR cigar_t cigar; // Alignment CIGAR // MM @@ -116,7 +117,8 @@ void wavefront_aligner_resize( const char* const pattern, const int pattern_length, const char* const text, - const int text_length); + const int text_length, + const bool reverse_sequences); void wavefront_aligner_reap( wavefront_aligner_t* const wf_aligner); void wavefront_aligner_delete( diff --git a/wavefront/wavefront_backtrace.c b/wavefront/wavefront_backtrace.c index 16123227..b7d6c5a8 100644 --- a/wavefront/wavefront_backtrace.c +++ b/wavefront/wavefront_backtrace.c @@ -58,26 +58,7 @@ typedef enum { } backtrace_type; /* - * Backtrace Detect Limits - */ -void wavefronts_backtrace_add_trailing_gap( - cigar_t* const cigar, - const int k, - const int alignment_k) { - // Parameters - char* const operations = cigar->operations; - int op_sentinel = cigar->begin_offset; - // Add trailing gap - int i; - if (k < alignment_k) { - for (i=k;i alignment_k) { - for (i=alignment_k;ibegin_offset = op_sentinel; -} -/* - * Backtrace Trace Patch Match/Mismatch + * Backtrace Trace Patch Match/Mismsmatch */ int64_t wavefronts_backtrace_misms( wavefront_aligner_t* const wf_aligner, diff --git a/wavefront/wavefront_display.c b/wavefront/wavefront_display.c index baf659c9..e7bc747e 100644 --- a/wavefront/wavefront_display.c +++ b/wavefront/wavefront_display.c @@ -172,7 +172,7 @@ void wavefront_display_print_header_component( wavefront_t* const wavefront, char* const wavefront_id, const int bt_length) { - fprintf(stream,"[ %s]",wavefront_id); + fprintf(stream,"[%s]",wavefront_id); if (bt_length > 0) { if (wavefront!=NULL && bt_length >= 10) { PRINT_CHAR_REP(stream,' ',bt_length-10); diff --git a/wavefront/wavefront_extend.c b/wavefront/wavefront_extend.c index d1165b74..b6e3d13e 100644 --- a/wavefront/wavefront_extend.c +++ b/wavefront/wavefront_extend.c @@ -40,31 +40,34 @@ #endif /* - * Wavefront check termination (detect end of alignment) + * Termination (detect end of alignment) */ bool wavefront_extend_end2end_check_termination( wavefront_aligner_t* const wf_aligner, - wavefront_t* const mwavefront) { + wavefront_t* const mwavefront, + const int score, + const int score_mod) { // Parameters const int pattern_length = wf_aligner->pattern_length; const int text_length = wf_aligner->text_length; - // Check wavefront limits - wf_offset_t* const offsets = mwavefront->offsets; - const int alignment_k = WAVEFRONT_DIAGONAL(text_length,pattern_length); + const int alignment_k = DPMATRIX_DIAGONAL(text_length,pattern_length); + const wf_offset_t alignment_offset = DPMATRIX_OFFSET(text_length,pattern_length); + // Check diagonal/offset if (mwavefront->lo > alignment_k || alignment_k > mwavefront->hi) return false; // Not done - // Check offset - const wf_offset_t offset = offsets[alignment_k]; - const wf_offset_t alignment_offset = WAVEFRONT_OFFSET(text_length,pattern_length); - if (offset < alignment_offset) return false; // Not done + const wf_offset_t moffset = mwavefront->offsets[alignment_k]; + if (moffset < alignment_offset) return false; // Not done // We are done - mwavefront->k_alignment_end = alignment_k; + wf_aligner->alignment_end_pos.score = score; + wf_aligner->alignment_end_pos.k = alignment_k; + wf_aligner->alignment_end_pos.offset = alignment_offset; return true; } bool wavefront_extend_endsfree_check_termination( wavefront_aligner_t* const wf_aligner, wavefront_t* const mwavefront, - const wf_offset_t offset, - const int k) { + const int score, + const int k, + const wf_offset_t offset) { // Parameters const int pattern_length = wf_aligner->pattern_length; const int text_length = wf_aligner->text_length; @@ -80,7 +83,9 @@ bool wavefront_extend_endsfree_check_termination( #pragma omp critical #endif { - mwavefront->k_alignment_end = k; + wf_aligner->alignment_end_pos.score = score; + wf_aligner->alignment_end_pos.k = k; + wf_aligner->alignment_end_pos.offset = offset; } return true; // Quit (we are done) } @@ -94,7 +99,9 @@ bool wavefront_extend_endsfree_check_termination( #pragma omp critical #endif { - mwavefront->k_alignment_end = k; + wf_aligner->alignment_end_pos.score = score; + wf_aligner->alignment_end_pos.k = k; + wf_aligner->alignment_end_pos.offset = offset; } return true; // Quit (we are done) } @@ -102,6 +109,9 @@ bool wavefront_extend_endsfree_check_termination( // Not done return false; } +/* + * Extend kernel + */ FORCE_INLINE wf_offset_t wavefront_extend_matches_packed_kernel( wavefront_aligner_t* const wf_aligner, const int k, @@ -136,7 +146,6 @@ FORCE_INLINE wf_offset_t wavefront_extend_matches_packed_kernel( FORCE_NO_INLINE void wavefront_extend_matches_packed_end2end( wavefront_aligner_t* const wf_aligner, wavefront_t* const mwavefront, - const int score, const int lo, const int hi) { wf_offset_t* const offsets = mwavefront->offsets; @@ -149,6 +158,26 @@ FORCE_NO_INLINE void wavefront_extend_matches_packed_end2end( offsets[k] = wavefront_extend_matches_packed_kernel(wf_aligner,k,offset); } } +FORCE_NO_INLINE wf_offset_t wavefront_extend_matches_packed_max( + wavefront_aligner_t* const wf_aligner, + wavefront_t* const mwavefront, + const int lo, + const int hi) { + wf_offset_t* const offsets = mwavefront->offsets; + wf_offset_t max_antidiag = 0; + int k; + for (k=lo;k<=hi;++k) { + // Fetch offset + const wf_offset_t offset = offsets[k]; + if (offset == WAVEFRONT_OFFSET_NULL) continue; + // Extend offset + offsets[k] = wavefront_extend_matches_packed_kernel(wf_aligner,k,offset); + // Compute max + const wf_offset_t antidiag = WAVEFRONT_ANTIDIAGONAL(k,offset); + if (max_antidiag < antidiag) max_antidiag = antidiag; + } + return max_antidiag; +} FORCE_NO_INLINE bool wavefront_extend_matches_packed_endsfree( wavefront_aligner_t* const wf_aligner, wavefront_t* const mwavefront, @@ -165,7 +194,7 @@ FORCE_NO_INLINE bool wavefront_extend_matches_packed_endsfree( offset = wavefront_extend_matches_packed_kernel(wf_aligner,k,offset); offsets[k] = offset; // Check ends-free reaching boundaries - if (wavefront_extend_endsfree_check_termination(wf_aligner,mwavefront,offset,k)) { + if (wavefront_extend_endsfree_check_termination(wf_aligner,mwavefront,score,k,offset)) { return true; // Quit (we are done) } } @@ -198,7 +227,7 @@ bool wavefront_extend_matches_custom( // Update offset offsets[k] = offset; // Check ends-free reaching boundaries - if (endsfree && wavefront_extend_endsfree_check_termination(wf_aligner,mwavefront,offset,k)) { + if (endsfree && wavefront_extend_endsfree_check_termination(wf_aligner,mwavefront,score,k,offset)) { return true; // Quit (we are done) } } @@ -208,14 +237,63 @@ bool wavefront_extend_matches_custom( /* * Wavefront exact "extension" */ -bool wavefront_extend_end2end( +int wavefront_extend_end2end_max( wavefront_aligner_t* const wf_aligner, - int score) { - // Modular wavefront - if (wf_aligner->wf_components.memory_modular) score = score % wf_aligner->wf_components.max_score_scope; + const int score) { + // Compute score + const bool memory_modular = wf_aligner->wf_components.memory_modular; + const int max_score_scope = wf_aligner->wf_components.max_score_scope; + const int score_mod = (memory_modular) ? score % max_score_scope : score; // Fetch m-wavefront - wavefront_t* const mwavefront = wf_aligner->wf_components.mwavefronts[score]; - if (mwavefront==NULL) return false; + wavefront_t* const mwavefront = wf_aligner->wf_components.mwavefronts[score_mod]; + if (mwavefront==NULL) return 0; // Not done + // Multithreading dispatcher + const int lo = mwavefront->lo; + const int hi = mwavefront->hi; + wf_offset_t max_antidiag = 0; + const int num_threads = wavefront_compute_num_threads(wf_aligner,lo,hi); + if (num_threads == 1) { + // Extend wavefront + max_antidiag = wavefront_extend_matches_packed_max(wf_aligner,mwavefront,lo,hi); + } else { +#ifdef WFA_PARALLEL + // Extend wavefront in parallel + #pragma omp parallel num_threads(num_threads) + { + int t_lo, t_hi; + wavefront_compute_thread_limits( + omp_get_thread_num(),omp_get_num_threads(),lo,hi,&t_lo,&t_hi); + wf_offset_t t_max_antidiag = wavefront_extend_matches_packed_max(wf_aligner,mwavefront,t_lo,t_hi); + #ifdef WFA_PARALLEL + #pragma omp critical + #endif + { + if (t_max_antidiag > max_antidiag) max_antidiag = t_max_antidiag; + } + } +#endif + } + // Cut-off wavefront heuristically + if (wf_aligner->heuristic.strategy != wf_heuristic_none) { + const bool alignment_dropped = wavefront_heuristic_cufoff(wf_aligner,score,score_mod); + if (alignment_dropped) { + wf_aligner->align_status.status = WF_STATUS_HEURISTICALY_DROPPED; + fprintf(stderr,"[WFA:Extend_max] Heuristically dropped error \n"); + exit(-1); + } + } + return max_antidiag; +} +int wavefront_extend_end2end( + wavefront_aligner_t* const wf_aligner, + const int score) { + // Compute score + const bool memory_modular = wf_aligner->wf_components.memory_modular; + const int max_score_scope = wf_aligner->wf_components.max_score_scope; + const int score_mod = (memory_modular) ? score % max_score_scope : score; + // Fetch m-wavefront + wavefront_t* const mwavefront = wf_aligner->wf_components.mwavefronts[score_mod]; + if (mwavefront==NULL) return 0; // Not done // Multithreading dispatcher const int lo = mwavefront->lo; const int hi = mwavefront->hi; @@ -223,9 +301,7 @@ bool wavefront_extend_end2end( const int num_threads = wavefront_compute_num_threads(wf_aligner,lo,hi); if (num_threads == 1) { // Extend wavefront - wavefront_extend_matches_packed_end2end(wf_aligner,mwavefront,score,lo,hi); - // Check end-to-end finished - end_reached = wavefront_extend_end2end_check_termination(wf_aligner,mwavefront); + wavefront_extend_matches_packed_end2end(wf_aligner,mwavefront,lo,hi); } else { #ifdef WFA_PARALLEL // Extend wavefront in parallel @@ -234,34 +310,36 @@ bool wavefront_extend_end2end( int t_lo, t_hi; wavefront_compute_thread_limits( omp_get_thread_num(),omp_get_num_threads(),lo,hi,&t_lo,&t_hi); - wavefront_extend_matches_packed_end2end(wf_aligner,mwavefront,score,t_lo,t_hi); + wavefront_extend_matches_packed_end2end(wf_aligner,mwavefront,t_lo,t_hi); } - // Check end-to-end finished - end_reached = wavefront_extend_end2end_check_termination(wf_aligner,mwavefront); #endif } + // Check end-to-end finished + end_reached = wavefront_extend_end2end_check_termination(wf_aligner,mwavefront,score,score_mod); if (end_reached) { wf_aligner->align_status.status = WF_STATUS_SUCCESSFUL; - return true; // Done + return 1; // Done } // Cut-off wavefront heuristically if (wf_aligner->heuristic.strategy != wf_heuristic_none) { - const bool alignment_dropped = wavefront_heuristic_cufoff(wf_aligner,score); + const bool alignment_dropped = wavefront_heuristic_cufoff(wf_aligner,score,score_mod); if (alignment_dropped) { wf_aligner->align_status.status = WF_STATUS_HEURISTICALY_DROPPED; - return true; // Done + return 1; // Done } } - return false; // Not done + return 0; // Not done } -bool wavefront_extend_endsfree( +int wavefront_extend_endsfree( wavefront_aligner_t* const wf_aligner, - int score) { + const int score) { // Modular wavefront - if (wf_aligner->wf_components.memory_modular) score = score % wf_aligner->wf_components.max_score_scope; + const bool memory_modular = wf_aligner->wf_components.memory_modular; + const int max_score_scope = wf_aligner->wf_components.max_score_scope; + const int score_mod = (memory_modular) ? score % max_score_scope : score; // Fetch m-wavefront - wavefront_t* const mwavefront = wf_aligner->wf_components.mwavefronts[score]; - if (mwavefront==NULL) return false; + wavefront_t* const mwavefront = wf_aligner->wf_components.mwavefronts[score_mod]; + if (mwavefront==NULL) return 0; // Not done // Multithreading dispatcher const int lo = mwavefront->lo; const int hi = mwavefront->hi; @@ -286,26 +364,28 @@ bool wavefront_extend_endsfree( } if (end_reached) { wf_aligner->align_status.status = WF_STATUS_SUCCESSFUL; - return true; // Done + return 1; // Done } // Cut-off wavefront heuristically if (wf_aligner->heuristic.strategy != wf_heuristic_none) { - const bool alignment_dropped = wavefront_heuristic_cufoff(wf_aligner,score); + const bool alignment_dropped = wavefront_heuristic_cufoff(wf_aligner,score,score_mod); if (alignment_dropped) { wf_aligner->align_status.status = WF_STATUS_HEURISTICALY_DROPPED; - return true; // Done + return 1; // Done } } - return false; // Not done + return 0; // Not done } -bool wavefront_extend_custom( +int wavefront_extend_custom( wavefront_aligner_t* const wf_aligner, - int score) { - // Modular wavefront - if (wf_aligner->wf_components.memory_modular) score = score % wf_aligner->wf_components.max_score_scope; + const int score) { + // Compute score + const bool memory_modular = wf_aligner->wf_components.memory_modular; + const int max_score_scope = wf_aligner->wf_components.max_score_scope; + const int score_mod = (memory_modular) ? score % max_score_scope : score; // Fetch m-wavefront wavefront_t* const mwavefront = wf_aligner->wf_components.mwavefronts[score]; - if (mwavefront==NULL) return false; + if (mwavefront==NULL) return 0; // Not done // Multithreading dispatcher const bool endsfree = (wf_aligner->alignment_form.span == alignment_endsfree); const int lo = mwavefront->lo; @@ -331,21 +411,21 @@ bool wavefront_extend_custom( } // Check end-to-end finished if (!endsfree) { - end_reached = wavefront_extend_end2end_check_termination(wf_aligner,mwavefront); + end_reached = wavefront_extend_end2end_check_termination(wf_aligner,mwavefront,score,score_mod); } if (end_reached) { wf_aligner->align_status.status = WF_STATUS_SUCCESSFUL; - return true; // Done + return 1; // Done } // Cut-off wavefront heuristically if (wf_aligner->heuristic.strategy != wf_heuristic_none) { - const bool alignment_dropped = wavefront_heuristic_cufoff(wf_aligner,score); + const bool alignment_dropped = wavefront_heuristic_cufoff(wf_aligner,score,score_mod); if (alignment_dropped) { wf_aligner->align_status.status = WF_STATUS_HEURISTICALY_DROPPED; - return true; // Done + return 1; // Done } } - return false; // Not done + return 0; // Not done } diff --git a/wavefront/wavefront_extend.h b/wavefront/wavefront_extend.h index 3f2b1ec1..92401014 100644 --- a/wavefront/wavefront_extend.h +++ b/wavefront/wavefront_extend.h @@ -37,14 +37,17 @@ /* * Wavefront exact "extension" */ -bool wavefront_extend_end2end( +int wavefront_extend_end2end( wavefront_aligner_t* const wf_aligner, - int score); -bool wavefront_extend_endsfree( + const int score); +int wavefront_extend_end2end_max( wavefront_aligner_t* const wf_aligner, - int score); -bool wavefront_extend_custom( + const int score); +int wavefront_extend_endsfree( wavefront_aligner_t* const wf_aligner, - int score); + const int score); +int wavefront_extend_custom( + wavefront_aligner_t* const wf_aligner, + const int score); #endif /* WAVEFRONT_EXTEND_H_ */ diff --git a/wavefront/wavefront_heuristic.c b/wavefront/wavefront_heuristic.c index eb8c180b..2e05da06 100644 --- a/wavefront/wavefront_heuristic.c +++ b/wavefront/wavefront_heuristic.c @@ -82,7 +82,7 @@ void wavefront_heuristic_set_xdrop( wf_heuristic->steps_wait = steps_between_cutoffs; wf_heuristic->max_sw_score = 0; wf_heuristic->max_sw_score_offset = WAVEFRONT_OFFSET_NULL; - wf_heuristic->max_sw_score_k = WAVEFRONT_DIAGONAL_NULL; + wf_heuristic->max_sw_score_k = DPMATRIX_DIAGONAL_NULL; } void wavefront_heuristic_set_zdrop( wavefront_heuristic_t* const wf_heuristic, @@ -95,7 +95,7 @@ void wavefront_heuristic_set_zdrop( wf_heuristic->steps_wait = steps_between_cutoffs; wf_heuristic->max_sw_score = 0; wf_heuristic->max_sw_score_offset = WAVEFRONT_OFFSET_NULL; - wf_heuristic->max_sw_score_k = WAVEFRONT_DIAGONAL_NULL; + wf_heuristic->max_sw_score_k = DPMATRIX_DIAGONAL_NULL; } void wavefront_heuristic_clear( wavefront_heuristic_t* const wf_heuristic) { @@ -103,7 +103,7 @@ void wavefront_heuristic_clear( wf_heuristic->steps_wait = wf_heuristic->steps_between_cutoffs; wf_heuristic->max_sw_score = 0; wf_heuristic->max_sw_score_offset = WAVEFRONT_OFFSET_NULL; - wf_heuristic->max_sw_score_k = WAVEFRONT_DIAGONAL_NULL; + wf_heuristic->max_sw_score_k = DPMATRIX_DIAGONAL_NULL; } /* * Utils @@ -308,7 +308,7 @@ void wavefront_cufoff_wfadaptive( const int min_distance = wavefront_compute_distance_end2end( wavefront,pattern_length,text_length,distances); // Cut-off wavefront - const int alignment_k = WAVEFRONT_DIAGONAL(text_length,pattern_length); + const int alignment_k = DPMATRIX_DIAGONAL(text_length,pattern_length); wavefront_cufoff_wfadaptive_reduce( wavefront,distances,min_distance,max_distance_threshold, alignment_k,alignment_k); @@ -318,7 +318,7 @@ void wavefront_cufoff_wfadaptive( // wavefront,pattern_length,text_length, // pattern_end_free,text_end_free,distances); // // Cut-off wavefront -// const int alignment_k = WAVEFRONT_DIAGONAL(text_length,pattern_length); +// const int alignment_k = DPMATRIX_DIAGONAL(text_length,pattern_length); // wavefront_cufoff_wfadaptive_reduce( // wavefront,distances,min_distance,max_distance_threshold, // alignment_k-text_end_free,alignment_k+pattern_end_free); @@ -331,16 +331,16 @@ void wavefront_cufoff_wfadaptive( */ void wavefront_compute_sw_scores( wavefront_t* const wavefront, - const int wf_score, + const int score, wf_offset_t* const sw_scores, wf_offset_t* const max_sw_score, wf_offset_t* const max_sw_score_k) { // Compute min-distance const wf_offset_t* const offsets = wavefront->offsets; - int k, score_max = -wf_score, score_max_k = 0; + int k, score_max = -score, score_max_k = 0; PRAGMA_LOOP_VECTORIZE for (k=wavefront->lo;k<=wavefront->hi;++k) { - const int sw_score = wf_compute_sw_score(wf_score,offsets[k],k); + const int sw_score = wf_compute_sw_score(score,offsets[k],k); sw_scores[k] = sw_score; if (score_max < sw_score) { score_max = sw_score; @@ -353,7 +353,7 @@ void wavefront_compute_sw_scores( void wavefront_cufoff_xdrop( wavefront_aligner_t* const wf_aligner, wavefront_t* const wavefront, - const int wf_score) { + const int score) { // Parameters wavefront_heuristic_t* const wf_heuristic = &wf_aligner->heuristic; const int base_hi = wavefront->hi; @@ -367,13 +367,13 @@ void wavefront_cufoff_xdrop( wf_offset_t current_max_sw_score; wf_offset_t current_max_sw_score_k; wavefront_compute_sw_scores( - wavefront,wf_score,sw_scores, + wavefront,score,sw_scores, ¤t_max_sw_score,¤t_max_sw_score_k); // Apply X-Drop const int xdrop = wf_heuristic->xdrop; const int max_sw_score = wf_heuristic->max_sw_score; const int max_sw_score_k = wf_heuristic->max_sw_score_k; - if (max_sw_score_k != WAVEFRONT_DIAGONAL_NULL) { + if (max_sw_score_k != DPMATRIX_DIAGONAL_NULL) { // Reduce from bottom int k, lo_reduced = wavefront->lo; for (k=wavefront->lo;k<=wavefront->hi;++k) { @@ -398,7 +398,7 @@ void wavefront_cufoff_xdrop( void wavefront_cufoff_zdrop( wavefront_aligner_t* const wf_aligner, wavefront_t* const wavefront, - const int wf_score) { + const int score) { // Parameters wavefront_heuristic_t* const wf_heuristic = &wf_aligner->heuristic; const int base_hi = wavefront->hi; @@ -412,7 +412,7 @@ void wavefront_cufoff_zdrop( wf_offset_t current_max_sw_score; wf_offset_t current_max_sw_score_k; wavefront_compute_sw_scores( - wavefront,wf_score,sw_scores, + wavefront,score,sw_scores, ¤t_max_sw_score,¤t_max_sw_score_k); // Apply X-Drop const wf_offset_t* const offsets = wavefront->offsets; @@ -422,7 +422,7 @@ void wavefront_cufoff_zdrop( const int max_sw_score = wf_heuristic->max_sw_score; const int max_sw_score_k = wf_heuristic->max_sw_score_k; const int max_sw_score_offset = wf_heuristic->max_sw_score_offset; - if (max_sw_score_k != WAVEFRONT_DIAGONAL_NULL) { + if (max_sw_score_k != DPMATRIX_DIAGONAL_NULL) { // Reduce from bottom int k, lo_reduced = wavefront->lo; for (k=wavefront->lo;k<=wavefront->hi;++k) { @@ -469,13 +469,14 @@ void wavefront_cufoff_zdrop( */ bool wavefront_heuristic_cufoff( wavefront_aligner_t* const wf_aligner, - const int score) { + const int score, + const int score_mod) { // Parameters wavefront_components_t* const wf_components = &wf_aligner->wf_components; const distance_metric_t distance_metric = wf_aligner->penalties.distance_metric; wavefront_heuristic_t* const wf_heuristic = &wf_aligner->heuristic; // Fetch m-wavefront - wavefront_t* const mwavefront = wf_components->mwavefronts[score]; + wavefront_t* const mwavefront = wf_components->mwavefronts[score_mod]; if (mwavefront==NULL || mwavefront->lo > mwavefront->hi) return false; // Not dropped // Cut-off m-wavefront --(wf_heuristic->steps_wait); @@ -502,13 +503,13 @@ bool wavefront_heuristic_cufoff( // Equate other wavefronts if (distance_metric <= gap_linear) return false; // Not dropped // Cut-off the other wavefronts (same dimensions as M) - wavefront_t* const i1wavefront = wf_components->i1wavefronts[score]; - wavefront_t* const d1wavefront = wf_components->d1wavefronts[score]; + wavefront_t* const i1wavefront = wf_components->i1wavefronts[score_mod]; + wavefront_t* const d1wavefront = wf_components->d1wavefronts[score_mod]; wavefront_heuristic_cutoff_equate(i1wavefront,mwavefront); wavefront_heuristic_cutoff_equate(d1wavefront,mwavefront); if (distance_metric == gap_affine) return false; // Not dropped - wavefront_t* const i2wavefront = wf_components->i2wavefronts[score]; - wavefront_t* const d2wavefront = wf_components->d2wavefronts[score]; + wavefront_t* const i2wavefront = wf_components->i2wavefronts[score_mod]; + wavefront_t* const d2wavefront = wf_components->d2wavefronts[score_mod]; wavefront_heuristic_cutoff_equate(i2wavefront,mwavefront); wavefront_heuristic_cutoff_equate(d2wavefront,mwavefront); // Return diff --git a/wavefront/wavefront_heuristic.h b/wavefront/wavefront_heuristic.h index 40aa584e..6945a10e 100644 --- a/wavefront/wavefront_heuristic.h +++ b/wavefront/wavefront_heuristic.h @@ -104,7 +104,8 @@ void wavefront_heuristic_clear( */ bool wavefront_heuristic_cufoff( wavefront_aligner_t* const wf_aligner, - const int score); + const int score, + const int score_mod); /* * Display diff --git a/wavefront/wavefront_offset.h b/wavefront/wavefront_offset.h index b1b005c7..42d59b72 100644 --- a/wavefront/wavefront_offset.h +++ b/wavefront/wavefront_offset.h @@ -48,12 +48,16 @@ typedef uint32_t wf_unsigned_offset_t; /* * Translate k and offset to coordinates h,v */ -#define WAVEFRONT_V(k,offset) ((offset)-(k)) -#define WAVEFRONT_H(k,offset) (offset) -#define WAVEFRONT_DIAGONAL(h,v) ((h)-(v)) -#define WAVEFRONT_OFFSET(h,v) (h) -#define WAVEFRONT_LENGTH(lo,hi) ((hi)-(lo)+1) // (lo/hi inclusive and +1 for WF[0]) +#define WAVEFRONT_LENGTH(lo,hi) ((hi)-(lo)+1) // (lo/hi inclusive and +1 for WF[0]) +#define WAVEFRONT_V(k,offset) ((offset)-(k)) +#define WAVEFRONT_H(k,offset) (offset) +#define WAVEFRONT_ANTIDIAGONAL(k,offset) (2*(offset)-(k)) -#define WAVEFRONT_DIAGONAL_NULL INT_MAX +#define DPMATRIX_DIAGONAL_NULL INT_MAX +#define DPMATRIX_DIAGONAL(h,v) ((h)-(v)) +#define DPMATRIX_ANTIDIAGONAL(h,v) ((h)+(v)) +#define DPMATRIX_OFFSET(h,v) (h) + +#define WAVEFRONT_K_INVERSE(k,plen,tlen) ((tlen)-(plen)-(k)) #endif /* WAVEFRONT_OFFSET_H_ */