Skip to content

Commit

Permalink
Fixed bug on internal-score conversion and refactor error-codes
Browse files Browse the repository at this point in the history
  • Loading branch information
smarco committed Jul 13, 2022
1 parent 7659ccb commit 6189f70
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 28 deletions.
10 changes: 4 additions & 6 deletions wavefront/wavefront_align.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,13 @@ void wavefront_align_terminate(
wavefront_aligner_t* const wf_aligner,
const int score) {
// Parameters
const distance_metric_t distance_metric = wf_aligner->penalties.distance_metric;
const int pattern_length = wf_aligner->pattern_length;
const int text_length = wf_aligner->text_length;
const int swg_match_score = -(wf_aligner->penalties.match);
// Retrieve alignment
if (wf_aligner->alignment_scope == compute_score) {
cigar_clear(&wf_aligner->cigar);
wf_aligner->cigar.score = (distance_metric <= edit) ? score :
WF_PENALTIES_GET_SW_SCORE(swg_match_score,pattern_length,text_length,score);
wf_aligner->cigar.score =
wavefront_get_classic_score(wf_aligner,pattern_length,text_length,score);
} else {
// Parameters
wavefront_components_t* const wf_components = &wf_aligner->wf_components;
Expand Down Expand Up @@ -289,8 +287,8 @@ void wavefront_align_terminate(
}
}
// Set score & finish
wf_aligner->cigar.score = (distance_metric <= edit) ? score :
WF_PENALTIES_GET_SW_SCORE(swg_match_score,pattern_length,text_length,score);
wf_aligner->cigar.score =
wavefront_get_classic_score(wf_aligner,pattern_length,text_length,score);
}
// Set successful
wf_aligner->align_status.status = WF_STATUS_SUCCESSFUL;
Expand Down
33 changes: 26 additions & 7 deletions wavefront/wavefront_aligner.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,22 @@ char* wf_error_msg[] =
/* WF_STATUS_OOM == -3 */ "[WFA] Alignment failed. Maximum memory threshold reached",
/* WF_STATUS_MAX_SCORE_REACHED == -2 */ "[WFA] Alignment failed. Maximum score reached",
/* WF_STATUS_UNFEASIBLE == -1 */ "[WFA] Alignment unfeasible (possible due to heuristic parameters)",
/* WF_STATUS_SUCCESSFUL == 0 */ "[WFA] Alignment successful",
/* WF_STATUS_IN_PROGRESS == 1 */ "[WFA] Alignment in progress",
/* WF_STATUS_SUCCESSFUL == 0 */ "[WFA] Alignment finished successfully",
};
char* wavefront_align_strerror(const int wf_error_code) {
return wf_error_msg[wf_error_code+3];
char* wavefront_align_strerror(const int error_code) {
if (error_code > 0) {
fprintf(stderr,"[WFA] Internal alignment error code (%d)",error_code);
exit(1);
}
return wf_error_msg[error_code+3];
}
/*
* Alignment status
*/
void wavefront_align_status_clear(
wavefront_align_status_t* const wf_align_status) {
wf_align_status->status = WF_STATUS_IN_PROGRESS;
wf_align_status->score = 0;
wavefront_align_status_t* const align_status) {
align_status->status = WF_STATUS_SUCCESSFUL;
align_status->score = 0;
}
/*
* Setup
Expand Down Expand Up @@ -344,6 +347,22 @@ void wavefront_aligner_delete(
mm_allocator_delete(mm_allocator);
}
}
/*
* Accessors
*/
int wavefront_get_classic_score(
wavefront_aligner_t* const wf_aligner,
const int pattern_length,
const int text_length,
const int wf_score) {
// Parameters
const int plen = wf_aligner->pattern_length;
const int tlen = wf_aligner->text_length;
const int swg_match = -(wf_aligner->penalties.match);
const distance_metric_t distance_metric = wf_aligner->penalties.distance_metric;
// Adapt score
return (distance_metric <= edit) ? wf_score : WF_SCORE_TO_SW_SCORE(swg_match,plen,tlen,wf_score);
}
/*
* Span configuration
*/
Expand Down
18 changes: 15 additions & 3 deletions wavefront/wavefront_aligner.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,17 @@
/*
* Error codes & messages
*/
// Success
#define WF_STATUS_SUCCESSFUL 0
#define WF_STATUS_IN_PROGRESS 1
#define WF_STATUS_END_REACHED 2 /* Internal */
// Errors
#define WF_STATUS_UNFEASIBLE -1
#define WF_STATUS_MAX_SCORE_REACHED -2
#define WF_STATUS_OOM -3
// Internal
#define WF_STATUS_END_REACHED 1
// Error messages
extern char* wf_error_msg[5];
char* wavefront_align_strerror(const int wf_error_code);
char* wavefront_align_strerror(const int error_code);

/*
* Alignment status
Expand Down Expand Up @@ -142,6 +145,15 @@ void wavefront_aligner_reap(
void wavefront_aligner_delete(
wavefront_aligner_t* const wf_aligner);

/*
* Accessors
*/
int wavefront_get_classic_score(
wavefront_aligner_t* const wf_aligner,
const int pattern_length,
const int text_length,
const int wf_score);

/*
* Span configuration
*/
Expand Down
10 changes: 2 additions & 8 deletions wavefront/wavefront_bialign.c
Original file line number Diff line number Diff line change
Expand Up @@ -605,10 +605,7 @@ void wavefront_bialign_alignment(
breakpoint.score_reverse,cigar,rlevel+1);
if (wf_aligner->align_status.status != WF_STATUS_SUCCESSFUL) return;
// Set score
const distance_metric_t distance_metric = wf_aligner->penalties.distance_metric;
const int swg_match_score = wf_aligner->penalties.match;
cigar->score = (distance_metric <= edit) ? breakpoint.score :
WF_PENALTIES_GET_SW_SCORE(swg_match_score,pattern_length,text_length,breakpoint.score);
cigar->score = wavefront_get_classic_score(wf_aligner,pattern_length,text_length,breakpoint.score);
}
/*
* Bidirectional compute score
Expand Down Expand Up @@ -638,11 +635,8 @@ void wavefront_bialign_compute_score(
}
}
// Report score
const distance_metric_t distance_metric = wf_aligner->penalties.distance_metric;
const int swg_match_score = wf_aligner->penalties.match;
cigar_clear(&wf_aligner->cigar);
wf_aligner->cigar.score = (distance_metric <= edit) ? breakpoint.score :
WF_PENALTIES_GET_SW_SCORE(swg_match_score,pattern_length,text_length,breakpoint.score);
wf_aligner->cigar.score = wavefront_get_classic_score(wf_aligner,pattern_length,text_length,breakpoint.score);
wf_aligner->align_status.status = WF_STATUS_SUCCESSFUL;
}
/*
Expand Down
4 changes: 2 additions & 2 deletions wavefront/wavefront_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ void wavefront_report_lite(
// Banner
fprintf(stream,"[WFA::Debug]");
// Sequences
fprintf(stream,"\t%d",-wf_aligner->cigar.score);
fprintf(stream,"\t%d",wf_aligner->cigar.score);
fprintf(stream,"\t%d\t%d",pattern_length,text_length);
fprintf(stream,"\t%s",(status==0) ? "OK" : "FAIL");
fprintf(stream,"\t%2.3f",TIMER_GET_TOTAL_MS(&wf_aligner->system.timer));
Expand Down Expand Up @@ -207,7 +207,7 @@ void wavefront_report_verbose_end(
fprintf(stream,"\n");
fprintf(stream,"[WFA::Debug]\tMemory.used\t%luMB\n",
CONVERT_B_TO_MB(wf_aligner->align_status.memory_used));
fprintf(stream,"[WFA::Debug]\tWFA.score\t%d\n",-(wf_aligner->cigar.score));
fprintf(stream,"[WFA::Debug]\tWFA.score\t%d\n",wf_aligner->cigar.score);
fprintf(stream,"[WFA::Debug]\tWFA.cigar\t");
cigar_print(stream,&wf_aligner->cigar,true);
fprintf(stream,"\n");
Expand Down
3 changes: 1 addition & 2 deletions wavefront/wavefront_penalties.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ typedef struct {
/*
* Compute SW-score equivalent (thanks to Eizenga's formula)
*/
#define WF_PENALTIES_GET_SW_SCORE(swg_match_score,plen,tlen,wf_score) \
(swg_match_score*(plen+tlen))/2 - wf_score
#define WF_SCORE_TO_SW_SCORE(swg_match,plen,tlen,wf_score) ((swg_match*(plen+tlen) - wf_score)/2)

/*
* Penalties adjustment
Expand Down

0 comments on commit 6189f70

Please sign in to comment.