Skip to content

Commit

Permalink
Implemented heuristic additional methods
Browse files Browse the repository at this point in the history
  • Loading branch information
smarco committed Mar 7, 2022
1 parent bb9744a commit 684b6d4
Show file tree
Hide file tree
Showing 27 changed files with 1,859 additions and 1,153 deletions.
478 changes: 453 additions & 25 deletions README.md

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions alignment/cigar.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void cigar_add_mismatches(
++p;
break;
default:
fprintf(stderr,"Aband-gaba. Wrong edit operation\n");
fprintf(stderr,"[CIGAR] Wrong edit operation\n");
exit(1);
break;
}
Expand Down Expand Up @@ -171,7 +171,7 @@ int cigar_score_gap_affine(
score -= penalties->gap_extension + ((last_op=='I') ? 0 : penalties->gap_opening);
break;
default:
fprintf(stderr,"Computing CIGAR score: Unknown operation\n");
fprintf(stderr,"[CIGAR] Computing CIGAR score: Unknown operation\n");
exit(1);
}
last_op = cigar->operations[i];
Expand All @@ -194,7 +194,7 @@ int cigar_score_gap_affine2p_get_operations_score(
return MIN(score1,score2);
}
default:
fprintf(stderr,"Computing CIGAR score: Unknown operation\n");
fprintf(stderr,"[CIGAR] Computing CIGAR score: Unknown operation\n");
exit(1);
}
}
Expand Down Expand Up @@ -270,7 +270,7 @@ bool cigar_check_alignment(
if (pattern[pattern_pos] != text[text_pos]) {
if (verbose) {
fprintf(stream,
"Align Check. Alignment not matching (pattern[%d]=%c != text[%d]=%c)\n",
"[AlignCheck] Alignment not matching (pattern[%d]=%c != text[%d]=%c)\n",
pattern_pos,pattern[pattern_pos],text_pos,text[text_pos]);
}
return false;
Expand All @@ -283,7 +283,7 @@ bool cigar_check_alignment(
if (pattern[pattern_pos] == text[text_pos]) {
if (verbose) {
fprintf(stream,
"Align Check. Alignment not mismatching (pattern[%d]=%c == text[%d]=%c)\n",
"[AlignCheck] Alignment not mismatching (pattern[%d]=%c == text[%d]=%c)\n",
pattern_pos,pattern[pattern_pos],text_pos,text[text_pos]);
}
return false;
Expand All @@ -298,7 +298,7 @@ bool cigar_check_alignment(
++pattern_pos;
break;
default:
fprintf(stderr,"CIGAR check. Unknown edit operation '%c'\n",operations[i]);
fprintf(stderr,"[AlignCheck] Unknown edit operation '%c'\n",operations[i]);
exit(1);
break;
}
Expand All @@ -307,15 +307,15 @@ bool cigar_check_alignment(
if (pattern_pos != pattern_length) {
if (verbose) {
fprintf(stream,
"Align Check. Alignment incorrect length (pattern-aligned=%d,pattern-length=%d)\n",
"[AlignCheck] Alignment incorrect length (pattern-aligned=%d,pattern-length=%d)\n",
pattern_pos,pattern_length);
}
return false;
}
if (text_pos != text_length) {
if (verbose) {
fprintf(stream,
"Align Check. Alignment incorrect length (text-aligned=%d,text-length=%d)\n",
"[AlignCheck] Alignment incorrect length (text-aligned=%d,text-length=%d)\n",
text_pos,text_length);
}
return false;
Expand Down
81 changes: 52 additions & 29 deletions bindings/cpp/WFAligner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,41 +63,34 @@ WFAligner::~WFAligner() {
/*
* Align End-to-end
*/
int WFAligner::alignEnd2EndLambda(
WFAligner::AlignmentStatus WFAligner::alignEnd2EndLambda(
const int patternLength,
const int textLength) {
// Configure
wavefront_aligner_set_alignment_end_to_end(wfAligner);
// Align (using custom matching function)
return wavefront_align(wfAligner,
NULL,patternLength,
NULL,textLength);
return (WFAligner::AlignmentStatus) wavefront_align(wfAligner,NULL,patternLength,NULL,textLength);
}
int WFAligner::alignEnd2End(
WFAligner::AlignmentStatus WFAligner::alignEnd2End(
const char* const pattern,
const int patternLength,
const char* const text,
const int textLength) {
// Configure
wavefront_aligner_set_alignment_end_to_end(wfAligner);
// Align
return wavefront_align(wfAligner,
pattern,patternLength,
text,textLength);
return (WFAligner::AlignmentStatus) wavefront_align(wfAligner,pattern,patternLength,text,textLength);
}
int WFAligner::alignEnd2End(
WFAligner::AlignmentStatus WFAligner::alignEnd2End(
std::string& pattern,
std::string& text) {
// Delegate
return alignEnd2End(
pattern.c_str(),pattern.length(),
text.c_str(),text.length());
return alignEnd2End(pattern.c_str(),pattern.length(),text.c_str(),text.length());
}
/*
* Align Ends-free
*/
// Align Ends-free
int WFAligner::alignEndsFreeLambda(
WFAligner::AlignmentStatus WFAligner::alignEndsFreeLambda(
const int patternLength,
const int patternBeginFree,
const int patternEndFree,
Expand All @@ -109,11 +102,9 @@ int WFAligner::alignEndsFreeLambda(
patternBeginFree,patternEndFree,
textBeginFree,textEndFree);
// Align (using custom matching function)
return wavefront_align(wfAligner,
NULL,patternLength,
NULL,textLength);
return (WFAligner::AlignmentStatus) wavefront_align(wfAligner,NULL,patternLength,NULL,textLength);
}
int WFAligner::alignEndsFree(
WFAligner::AlignmentStatus WFAligner::alignEndsFree(
const char* const pattern,
const int patternLength,
const int patternBeginFree,
Expand All @@ -127,11 +118,9 @@ int WFAligner::alignEndsFree(
patternBeginFree,patternEndFree,
textBeginFree,textEndFree);
// Align
return wavefront_align(wfAligner,
pattern,patternLength,
text,textLength);
return (WFAligner::AlignmentStatus) wavefront_align(wfAligner,pattern,patternLength,text,textLength);
}
int WFAligner::alignEndsFree(
WFAligner::AlignmentStatus WFAligner::alignEndsFree(
std::string& pattern,
const int patternBeginFree,
const int patternEndFree,
Expand All @@ -144,16 +133,50 @@ int WFAligner::alignEndsFree(
text.c_str(),text.length());
}
/*
* Reduction
* Alignment resume
*/
WFAligner::AlignmentStatus WFAligner::alignResume() {
// Resume alignment
return (WFAligner::AlignmentStatus) wavefront_align_resume(wfAligner);
}
/*
* Heuristics
*/
void WFAligner::setReductionNone() {
wavefront_aligner_set_reduction_none(wfAligner);
void WFAligner::setHeuristicNone() {
wavefront_aligner_set_heuristic_none(wfAligner);
}
void WFAligner::setHeuristicBandedStatic(
const int band_min_k,
const int band_max_k) {
wavefront_aligner_set_heuristic_banded_static(
wfAligner,band_min_k,band_max_k);
}
void WFAligner::setHeuristicBandedAdaptive(
const int band_min_k,
const int band_max_k,
const int steps_between_cutoffs) {
wavefront_aligner_set_heuristic_banded_adaptive(
wfAligner,band_min_k,band_max_k,steps_between_cutoffs);
}
void WFAligner::setReductionAdaptive(
void WFAligner::setHeuristicWFadaptive(
const int min_wavefront_length,
const int max_distance_threshold) {
wavefront_aligner_set_reduction_adaptive(
wfAligner,min_wavefront_length,max_distance_threshold);
const int max_distance_threshold,
const int steps_between_cutoffs) {
wavefront_aligner_set_heuristic_wfadaptive(
wfAligner,min_wavefront_length,
max_distance_threshold,steps_between_cutoffs);
}
void WFAligner::setHeuristicXDrop(
const int xdrop,
const int steps_between_cutoffs) {
wavefront_aligner_set_heuristic_xdrop(
wfAligner,xdrop,steps_between_cutoffs);
}
void WFAligner::setHeuristicZDrop(
const int zdrop,
const int steps_between_cutoffs) {
wavefront_aligner_set_heuristic_zdrop(
wfAligner,zdrop,steps_between_cutoffs);
}
/*
* Custom extend-match function (lambda)
Expand Down
44 changes: 33 additions & 11 deletions bindings/cpp/WFAligner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,27 +59,33 @@ class WFAligner {
Score,
Alignment,
};
enum AlignmentStatus {
StatusSuccessful = WF_STATUS_SUCCESSFUL,
StatusDropped = WF_STATUS_HEURISTICALY_DROPPED,
StatusMaxScoreReached = WF_STATUS_MAX_SCORE_REACHED,
StatusOOM = WF_STATUS_OOM,
};
// Align End-to-end
int alignEnd2EndLambda(
AlignmentStatus alignEnd2EndLambda(
const int patternLength,
const int textLength);
int alignEnd2End(
AlignmentStatus alignEnd2End(
const char* const pattern,
const int patternLength,
const char* const text,
const int textLength);
int alignEnd2End(
AlignmentStatus alignEnd2End(
std::string& pattern,
std::string& text);
// Align Ends-free
int alignEndsFreeLambda(
AlignmentStatus alignEndsFreeLambda(
const int patternLength,
const int patternBeginFree,
const int patternEndFree,
const int textLength,
const int textBeginFree,
const int textEndFree);
int alignEndsFree(
AlignmentStatus alignEndsFree(
const char* const pattern,
const int patternLength,
const int patternBeginFree,
Expand All @@ -88,18 +94,34 @@ class WFAligner {
const int textLength,
const int textBeginFree,
const int textEndFree);
int alignEndsFree(
AlignmentStatus alignEndsFree(
std::string& pattern,
const int patternBeginFree,
const int patternEndFree,
std::string& text,
const int textBeginFree,
const int textEndFree);
// Reduction
void setReductionNone();
void setReductionAdaptive(
const int minWavefrontLength,
const int maxDistanceThreshold);
// Alignment resume
AlignmentStatus alignResume();
// Heuristics
void setHeuristicNone();
void setHeuristicBandedStatic(
const int band_min_k,
const int band_max_k);
void setHeuristicBandedAdaptive(
const int band_min_k,
const int band_max_k,
const int steps_between_cutoffs);
void setHeuristicWFadaptive(
const int min_wavefront_length,
const int max_distance_threshold,
const int steps_between_cutoffs);
void setHeuristicXDrop(
const int xdrop,
const int steps_between_cutoffs);
void setHeuristicZDrop(
const int zdrop,
const int steps_between_cutoffs);
// Custom extend-match function (lambda)
void setMatchFunct(
int (*matchFunct)(int,int,void*),
Expand Down
Loading

0 comments on commit 684b6d4

Please sign in to comment.