Skip to content

Commit

Permalink
Added extension mode to align_benchmark (for testing)
Browse files Browse the repository at this point in the history
  • Loading branch information
smarco committed Sep 25, 2023
1 parent 9fdf46e commit d09e0b2
Show file tree
Hide file tree
Showing 13 changed files with 77 additions and 60 deletions.
1 change: 1 addition & 0 deletions alignment/cigar.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#ifndef CIGAR_H_
#define CIGAR_H_

#include <stdbool.h>
#include "system/mm_allocator.h"
#include "alignment/linear_penalties.h"
#include "alignment/affine_penalties.h"
Expand Down
1 change: 1 addition & 0 deletions system/mm_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#ifndef MM_ALLOCATOR_H_
#define MM_ALLOCATOR_H_

#include <stdbool.h>
#include "utils/vector.h"

/*
Expand Down
5 changes: 4 additions & 1 deletion tests/wfa.utest.performance.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,7 @@ rm $OUTPUT/*.log $OUTPUT/*.alg
\time -v ./bin/align_benchmark -a $ALGORITHM -i ../data/sim.l100K.n1.e10.seq -o $OUTPUT/sim.l100K.e10.Wb.alg $BIWFA &> $OUTPUT/sim.l100K.e10.Wb.log

# Run the check
./tests/wfa.utest.cmp.sh tests/ tests/wfa.utest.performance.check/ --cmp-performance
echo ">>> "
echo ">>> Performance [base vs new]: "
echo ">>> "
./tests/wfa.utest.cmp.sh tests/wfa.utest.performance.check/ tests/ --cmp-performance
4 changes: 2 additions & 2 deletions tests/wfa.utest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ grep "Time.Alignment" $LOG | awk '{if ($4 != "ms") print $3" "$4}' | sort -n > $
grep "Maximum resident set size" $LOG | awk '{print $6}' | sort -n > $LOG.mem

# Display performance
echo ">>> Performance Time (s): "
echo ">>> Performance Time (s) [base vs new]: "
paste <(tail -n 4 $OUTPUT/wfa.utest.check/wfa.utest.log.time) <(tail -n 4 $OUTPUT/wfa.utest.log.time)
echo ">>> Performance Mem (KB): "
echo ">>> Performance Mem (KB) [base vs new]: "
paste <(tail -n 4 $OUTPUT/wfa.utest.check/wfa.utest.log.mem) <(tail -n 4 $OUTPUT/wfa.utest.log.mem)

# Display correct
Expand Down
15 changes: 11 additions & 4 deletions tools/align_benchmark/align_benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,16 @@ wavefront_aligner_t* align_input_configure_wavefront(
break;
}
// Select alignment form
attributes.alignment_form.span = (parameters.endsfree) ? alignment_endsfree : alignment_end2end;
if (parameters.align_span_extension) {
attributes.alignment_form.span = alignment_endsfree;
attributes.alignment_form.extension = true;
} else if (parameters.align_span_endsfree) {
attributes.alignment_form.span = alignment_endsfree;
attributes.alignment_form.extension = false;
} else { // Global
attributes.alignment_form.span = alignment_end2end;
attributes.alignment_form.extension = false;
}
// Misc
attributes.plot.enabled = (parameters.plot != 0);
attributes.plot.align_level = (parameters.plot < 0) ? -1 : parameters.plot - 1;
Expand All @@ -236,8 +245,6 @@ void align_input_configure_global(
align_input->linear_penalties = parameters.linear_penalties;
align_input->affine_penalties = parameters.affine_penalties;
align_input->affine2p_penalties = parameters.affine2p_penalties;
// Alignment form
align_input->ends_free = parameters.endsfree;
// Output
align_input->output_file = parameters.output_file;
align_input->output_full = parameters.output_full;
Expand Down Expand Up @@ -271,7 +278,7 @@ void align_input_configure_global(
void align_input_configure_local(
align_input_t* const align_input) {
// Ends-free configuration
if (parameters.endsfree) {
if (parameters.align_span_endsfree) {
const int plen = align_input->pattern_length;
const int tlen = align_input->text_length;
align_input->pattern_begin_free = nominal_prop_u32(plen,parameters.pattern_begin_free);
Expand Down
74 changes: 46 additions & 28 deletions tools/align_benchmark/align_benchmark_params.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ align_bench_params_t parameters = {
.gap_extension2 = 1,
},
// Alignment form
.endsfree = false,
.align_span_global = true,
.align_span_extension = false,
.align_span_endsfree = false,
.pattern_begin_free = 0.0,
.text_begin_free = 0.0,
.pattern_end_free = 0.0,
Expand Down Expand Up @@ -134,10 +136,10 @@ void usage() {
" --linear-penalties|p M,X,I \n"
" --affine-penalties|g M,X,O,E \n"
" --affine2p-penalties M,X,O1,E1,O2,E2 \n"
" --ends-free P0,Pf,T0,Tf \n"
" [Wavefront parameters] \n"
" --wfa-score-only \n"
" --wfa-memory-mode 'high'|'med'|'low'|'ultralow' \n"
" --wfa-span 'global'|'extension'|'ends-free[,P0,Pf,T0,Tf]' \n"
" --wfa-memory 'high'|'med'|'low'|'ultralow' \n"
" --wfa-heuristic STRATEGY \n"
" --wfa-heuristic-parameters P1,P2[,P3] \n"
" [STRATEGY='banded-static'] \n"
Expand Down Expand Up @@ -191,12 +193,12 @@ void parse_arguments(
{ "linear-penalties", required_argument, 0, 'p' },
{ "affine-penalties", required_argument, 0, 'g' },
{ "affine2p-penalties", required_argument, 0, 900 },
{ "ends-free", required_argument, 0, 901 },
/* Wavefront parameters */
{ "wfa-score-only", no_argument, 0, 1000 },
{ "wfa-memory-mode", required_argument, 0, 1001 },
{ "wfa-heuristic", required_argument, 0, 1002 },
{ "wfa-heuristic-parameters", required_argument, 0, 1003 },
{ "wfa-span", required_argument, 0, 1001 },
{ "wfa-memory", required_argument, 0, 1002 },
{ "wfa-heuristic", required_argument, 0, 1003 },
{ "wfa-heuristic-parameters", required_argument, 0, 1004 },
{ "wfa-max-memory", required_argument, 0, 1005 },
{ "wfa-max-steps", required_argument, 0, 1006 },
{ "wfa-max-threads", required_argument, 0, 1007 },
Expand Down Expand Up @@ -322,25 +324,44 @@ void parse_arguments(
parameters.affine2p_penalties.gap_extension2 = atoi(sentinel);
break;
}
case 901: { // --ends-free P0,Pf,T0,Tf
parameters.endsfree = true;
char* sentinel = strtok(optarg,",");
parameters.pattern_begin_free = atof(sentinel);
sentinel = strtok(NULL,",");
parameters.pattern_end_free = atof(sentinel);
sentinel = strtok(NULL,",");
parameters.text_begin_free = atof(sentinel);
sentinel = strtok(NULL,",");
parameters.text_end_free = atof(sentinel);
break;
}
/*
* Wavefront parameters
*/
case 1000: // --wfa-score-only
parameters.wfa_score_only = true;
break;
case 1001: // --wfa-memory-mode in {'high','med','low'}
case 1001: { // --wfa-span P0,Pf,T0,Tf
if (strcmp(optarg,"global")==0) {
parameters.align_span_global = true;
parameters.align_span_extension = false;
parameters.align_span_endsfree = false;
} else if (strcmp(optarg,"extension")==0 ||
strcmp(optarg,"extend")==0) {
parameters.align_span_global = false;
parameters.align_span_extension = true;
parameters.align_span_endsfree = false;
} else if (strcmp(optarg,"ends-free")==0 ||
strcmp(optarg,"endsfree")==0) {
parameters.align_span_global = false;
parameters.align_span_extension = false;
parameters.align_span_endsfree = true;
// Parse arguments
char* sentinel = strtok(optarg,",");
sentinel = strtok(NULL,","); // Skip span-keyword
parameters.pattern_begin_free = atof(sentinel);
sentinel = strtok(NULL,",");
parameters.pattern_end_free = atof(sentinel);
sentinel = strtok(NULL,",");
parameters.text_begin_free = atof(sentinel);
sentinel = strtok(NULL,",");
parameters.text_end_free = atof(sentinel);
} else {
fprintf(stderr,"Option '--wfa-span' must be in {'global','extension','ends-free'}\n");
exit(1);
}
break;
}
case 1002: // --wfa-memory in {'high','med','low'}
if (strcmp(optarg,"high")==0) {
parameters.wfa_memory_mode = wavefront_memory_high;
} else if (strcmp(optarg,"med")==0) {
Expand All @@ -350,11 +371,11 @@ void parse_arguments(
} else if (strcmp(optarg,"ultralow")==0) {
parameters.wfa_memory_mode = wavefront_memory_ultralow;
} else {
fprintf(stderr,"Option '--wfa-memory-mode' must be in {'high','med','low','ultralow'}\n");
fprintf(stderr,"Option '--wfa-memory' must be in {'high','med','low','ultralow'}\n");
exit(1);
}
break;
case 1002: // --wfa-heuristic in {'none'|'banded-static'|'banded-adaptive'|'wfa-adaptive'|'xdrop'|'zdrop'}
case 1003: // --wfa-heuristic in {'none'|'banded-static'|'banded-adaptive'|'wfa-adaptive'|'xdrop'|'zdrop'}
if (strcmp(optarg,"none")==0) {
parameters.wfa_heuristic = wf_heuristic_none;
} else if (strcmp(optarg,"banded-static")==0 || strcmp(optarg,"banded")==0) {
Expand All @@ -372,7 +393,7 @@ void parse_arguments(
exit(1);
}
break;
case 1003: { // --wfa-heuristic-parameters <P1>,<P2>[,<P3>]
case 1004: { // --wfa-heuristic-parameters <P1>,<P2>[,<P3>]
char* sentinel = strtok(optarg,",");
const int p1 = atoi(sentinel);
parameters.wfa_heuristic_p1 = p1;
Expand Down Expand Up @@ -493,19 +514,16 @@ void parse_arguments(
exit(1);
}
// Check 'ends-free' parameter
if (parameters.endsfree) {
if (parameters.align_span_endsfree || parameters.align_span_extension) {
switch (parameters.algorithm) {
case alignment_gap_affine_swg:
parameters.algorithm = alignment_gap_affine_swg_endsfree;
break;
case alignment_indel_wavefront:
case alignment_edit_wavefront:
case alignment_gap_linear_wavefront:
case alignment_gap_affine_wavefront:
case alignment_gap_affine2p_wavefront:
break;
default:
fprintf(stderr,"Ends-free variant not implemented for the selected algorithm\n");
fprintf(stderr,"Ends-free/Extension variant not implemented for the selected algorithm\n");
exit(1);
break;
}
Expand Down
6 changes: 4 additions & 2 deletions tools/align_benchmark/align_benchmark_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ typedef struct {
linear_penalties_t linear_penalties;
affine_penalties_t affine_penalties;
affine2p_penalties_t affine2p_penalties;
// Alignment form
bool endsfree;
// Alignment span
bool align_span_global;
bool align_span_extension;
bool align_span_endsfree;
double pattern_begin_free;
double text_begin_free;
double pattern_end_free;
Expand Down
1 change: 0 additions & 1 deletion tools/align_benchmark/benchmark/benchmark_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
void benchmark_align_input_clear(
align_input_t* const align_input) {
// Alignment form
align_input->ends_free = false;
align_input->pattern_begin_free = 0;
align_input->text_begin_free = 0;
align_input->pattern_end_free = 0;
Expand Down
1 change: 0 additions & 1 deletion tools/align_benchmark/benchmark/benchmark_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ typedef struct {
affine_penalties_t affine_penalties;
affine2p_penalties_t affine2p_penalties;
// Alignment form
bool ends_free;
int pattern_begin_free;
int text_begin_free;
int pattern_end_free;
Expand Down
1 change: 1 addition & 0 deletions utils/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#define VECTOR_H_

#include <stdint.h>
#include <stdbool.h>

/*
* Checkers
Expand Down
7 changes: 6 additions & 1 deletion wavefront/wavefront_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ void wavefront_report_lite(
const int text_length = sequences->text_length;
const int status = wf_aligner->align_status.status;
const uint64_t memory_used = wf_aligner->align_status.memory_used;
const bool has_cigar = alignment_completed && !cigar_is_null(wf_aligner->cigar);
// BANNER (#0)
if (alignment_completed) {
fprintf(stream,"[WFA::Debug]");
Expand All @@ -145,6 +146,10 @@ void wavefront_report_lite(
const int score = wf_aligner->cigar->score;
if (alignment_completed && score!=INT32_MIN) {
fprintf(stream,"\t%d",score);
if (has_cigar) {
const int edit_dist = cigar_score_edit(wf_aligner->cigar);
fprintf(stream,"/%1.2f",(float)edit_dist/(float)MAX(pattern_length,text_length));
}
} else {
fprintf(stream,"\t*");
}
Expand Down Expand Up @@ -184,7 +189,7 @@ void wavefront_report_lite(
wf_aligner->wf_components.historic_max_hi);
fprintf(stream,"]\t");
// CIGAR (#8)
if (!alignment_completed || cigar_is_null(wf_aligner->cigar)) {
if (!has_cigar) {
fprintf(stream,"-");
} else {
cigar_print(stream,wf_aligner->cigar,true);
Expand Down
19 changes: 0 additions & 19 deletions wavefront/wavefront_penalties.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,25 +89,6 @@ void wavefront_penalties_set_affine2p(
wavefront_penalties_t* const wf_penalties,
affine2p_penalties_t* const affine2p_penalties);

/*
* Score conversion
*/
int wavefront_penalties_get_score_indel(
wavefront_penalties_t* const wf_penalties,
const int score);
int wavefront_penalties_get_score_edit(
wavefront_penalties_t* const wf_penalties,
const int score);
int wavefront_penalties_get_score_linear(
wavefront_penalties_t* const wf_penalties,
const int score);
int wavefront_penalties_get_score_affine(
wavefront_penalties_t* const wf_penalties,
const int score);
int wavefront_penalties_get_score_affine2p(
wavefront_penalties_t* const wf_penalties,
const int score);

/*
* Display
*/
Expand Down
2 changes: 1 addition & 1 deletion wavefront/wavefront_sequences.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void wavefront_sequences_init_allocate(
if (wf_sequences->seq_buffer != NULL) free(wf_sequences->seq_buffer);
// Allocate
const int proposed_size = buffer_size + buffer_size/2;
wf_sequences->seq_buffer = calloc(proposed_size, 1);
wf_sequences->seq_buffer = calloc(proposed_size,1);
wf_sequences->seq_buffer_allocated = proposed_size;
}
// Assign memory
Expand Down

0 comments on commit d09e0b2

Please sign in to comment.