Skip to content

Commit

Permalink
Merge branch 'pjotrp'
Browse files Browse the repository at this point in the history
  • Loading branch information
pjotrp committed Jan 12, 2023
2 parents a8d5cdd + 8f66ddf commit 0d77c88
Show file tree
Hide file tree
Showing 194 changed files with 27,951 additions and 3,280 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,9 @@ build/
*.out
*.app

# Test output files
tests/wfa.utest.log.correct
tests/wfa.utest.log.mem
tests/wfa.utest.log.time


24 changes: 15 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ FOLDER_BIN=bin
FOLDER_BUILD=build
FOLDER_BUILD_CPP=build/cpp
FOLDER_LIB=lib
FOLDER_TESTS=tests

UNAME=$(shell uname)

CC:=gcc
CPP:=g++
CC:=$(CC)
CPP:=$(CXX)

CC_FLAGS=-Wall -g

Expand All @@ -19,10 +20,13 @@ AR_FLAGS=-rsc
ifndef BUILD_EXAMPLES
BUILD_EXAMPLES=1
endif

ifndef BUILD_TOOLS
BUILD_TOOLS=1
endif
ifndef BUILD_WFA_PARALLEL
BUILD_WFA_PARALLEL=1
endif

###############################################################################
# Configuration rules
###############################################################################
Expand All @@ -41,16 +45,17 @@ ifeq ($(BUILD_EXAMPLES),1)
APPS+=examples
endif

release: CC_FLAGS+=-O3 -march=native -flto
release: build

all: CC_FLAGS+=-O3 -march=native
all: CC_FLAGS+=-O3 -march=native #-flto -ffat-lto-objects
all: build

debug: build

ASAN_OPT=-fsanitize=address -fsanitize=undefined -fsanitize=shift -fsanitize=alignment
ASAN_OPT+=-fsanitize=signed-integer-overflow -fsanitize=bool -fsanitize=enum
ASAN_OPT+=-fsanitize=pointer-compare -fsanitize=pointer-overflow -fsanitize=builtin

# ASAN: ASAN_OPTIONS=detect_leaks=1:symbolize=1 LSAN_OPTIONS=verbosity=2:log_threads=1
asan: CC_FLAGS+=-fsanitize=address -fno-omit-frame-pointer -fno-common
asan: CC_FLAGS+=$(ASAN_OPT) -fno-omit-frame-pointer -fno-common
asan: build

###############################################################################
Expand All @@ -69,9 +74,10 @@ lib_wfa: $(SUBDIRS)
$(AR) $(AR_FLAGS) $(LIB_WFA_CPP) $(FOLDER_BUILD)/*.o $(FOLDER_BUILD_CPP)/*.o 2> /dev/null

clean:
rm -rf $(FOLDER_BIN) $(FOLDER_BUILD) $(FOLDER_LIB)
rm -rf $(FOLDER_BIN) $(FOLDER_BUILD) $(FOLDER_LIB) 2> /dev/null
$(MAKE) --directory=tools/align_benchmark clean
$(MAKE) --directory=examples clean
rm -rf $(FOLDER_TESTS)/*.alg $(FOLDER_TESTS)/*.log* 2> /dev/null

###############################################################################
# Subdir rule
Expand Down
141 changes: 92 additions & 49 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v2.1
v2.3
2 changes: 0 additions & 2 deletions alignment/affine2p_penalties.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
#ifndef AFFINE2P_PENALTIES_H_
#define AFFINE2P_PENALTIES_H_

#include "utils/commons.h"

/*
* Affine 2-piece penalties
*/
Expand Down
2 changes: 0 additions & 2 deletions alignment/affine_penalties.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
#ifndef AFFINE_PENALTIES_H_
#define AFFINE_PENALTIES_H_

#include "utils/commons.h"

/*
* Affine penalties
*/
Expand Down
46 changes: 42 additions & 4 deletions alignment/cigar.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,17 @@
* DESCRIPTION: Edit cigar data-structure (match/mismatch/insertion/deletion)
*/

#include "utils/commons.h"
#include "cigar.h"

/*
* Setup
*/
void cigar_allocate(
cigar_t* const cigar,
cigar_t* cigar_new(
const int max_operations,
mm_allocator_t* const mm_allocator) {
// Allocate
cigar_t* const cigar = mm_allocator_alloc(mm_allocator,cigar_t);
// Allocate buffer
cigar->max_operations = max_operations;
cigar->operations = mm_allocator_malloc(mm_allocator,cigar->max_operations);
Expand All @@ -46,6 +48,8 @@ void cigar_allocate(
cigar->score = INT32_MIN;
// MM
cigar->mm_allocator = mm_allocator;
// Return
return cigar;
}
void cigar_clear(
cigar_t* const cigar) {
Expand All @@ -70,6 +74,7 @@ void cigar_resize(
void cigar_free(
cigar_t* const cigar) {
mm_allocator_free(cigar->mm_allocator,cigar->operations);
mm_allocator_free(cigar->mm_allocator,cigar);
}
/*
* Accessors
Expand Down Expand Up @@ -251,6 +256,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;i<length;++i) {
operations[i] = 'D';
}
// Update offset
cigar->end_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;i<length;++i) {
operations[i] = 'I';
}
// Update offset
cigar->end_offset += length;
}
bool cigar_check_alignment(
FILE* const stream,
const char* const pattern,
Expand Down Expand Up @@ -467,5 +507,3 @@ void cigar_print_pretty(
mm_allocator_free(mm_allocator,ops_alg);
mm_allocator_free(mm_allocator,text_alg);
}


15 changes: 12 additions & 3 deletions alignment/cigar.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#ifndef CIGAR_H_
#define CIGAR_H_

#include "utils/commons.h"
#include "system/mm_allocator.h"
#include "alignment/linear_penalties.h"
#include "alignment/affine_penalties.h"
Expand All @@ -56,8 +55,7 @@ typedef struct {
/*
* Setup
*/
void cigar_allocate(
cigar_t* const cigar,
cigar_t* cigar_new(
const int max_operations,
mm_allocator_t* const mm_allocator);
void cigar_clear(
Expand Down Expand Up @@ -104,6 +102,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,
Expand Down
6 changes: 2 additions & 4 deletions alignment/score_matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
* DESCRIPTION: Score matrix for alignment using dynamic programming
*/

#include "utils/commons.h"
#include "score_matrix.h"


/*
* Setup
*/
Expand Down Expand Up @@ -114,7 +116,3 @@ void score_matrix_print(
}
fprintf(stream,"\n");
}




1 change: 0 additions & 1 deletion alignment/score_matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#ifndef SCORE_MATRIX_H_
#define SCORE_MATRIX_H_

#include "utils/commons.h"
#include "system/mm_allocator.h"
#include "alignment/cigar.h"

Expand Down
85 changes: 77 additions & 8 deletions bindings/cpp/WFAligner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ WFAligner::WFAligner(
case MemoryHigh: this->attributes.memory_mode = wavefront_memory_high; break;
case MemoryMed: this->attributes.memory_mode = wavefront_memory_med; break;
case MemoryLow: this->attributes.memory_mode = wavefront_memory_low; break;
case MemoryUltralow: this->attributes.memory_mode = wavefront_memory_ultralow; break;
default: this->attributes.memory_mode = wavefront_memory_high; break;
}
this->attributes.alignment_scope = (alignmentScope==Score) ? compute_score : compute_alignment;
//this->attributes.system.verbose = 2;
this->wfAligner = nullptr;
}
WFAligner::~WFAligner() {
Expand Down Expand Up @@ -127,9 +129,11 @@ WFAligner::AlignmentStatus WFAligner::alignEndsFree(
const int textBeginFree,
const int textEndFree) {
// Delegate
return alignEnd2End(
return alignEndsFree(
pattern.c_str(),pattern.length(),
text.c_str(),text.length());
patternBeginFree,patternEndFree,
text.c_str(),text.length(),
textBeginFree,textEndFree);
}
/*
* Alignment resume
Expand Down Expand Up @@ -165,6 +169,14 @@ void WFAligner::setHeuristicWFadaptive(
wfAligner,min_wavefront_length,
max_distance_threshold,steps_between_cutoffs);
}
void WFAligner::setHeuristicWFmash(
const int min_wavefront_length,
const int max_distance_threshold,
const int steps_between_cutoffs) {
wavefront_aligner_set_heuristic_wfmash(
wfAligner,min_wavefront_length,
max_distance_threshold,steps_between_cutoffs);
}
void WFAligner::setHeuristicXDrop(
const int xdrop,
const int steps_between_cutoffs) {
Expand Down Expand Up @@ -194,23 +206,33 @@ void WFAligner::setMaxAlignmentScore(
wfAligner,maxAlignmentScore);
}
void WFAligner::setMaxMemory(
const uint64_t maxMemoryCompact,
const uint64_t maxMemoryResident,
const uint64_t maxMemoryAbort) {
wavefront_aligner_set_max_memory(wfAligner,
maxMemoryCompact,maxMemoryResident,maxMemoryAbort);
wavefront_aligner_set_max_memory(wfAligner,maxMemoryResident,maxMemoryAbort);
}
// Parallelization
void WFAligner::setMaxNumThreads(
const int maxNumThreads) {
wavefront_aligner_set_max_num_threads(wfAligner, maxNumThreads);
}
void WFAligner::setMinOffsetsPerThread(
const int minOffsetsPerThread) {
wavefront_aligner_set_min_offsets_per_thread(wfAligner, minOffsetsPerThread);
}
/*
* Accessors
*/
int WFAligner::getAlignmentScore() {
return wfAligner->cigar.score;
return wfAligner->cigar->score;
}
int WFAligner::getAlignmentStatus() {
return wfAligner->align_status.status;
}
void WFAligner::getAlignmentCigar(
char** const cigarOperations,
int* cigarLength) {
*cigarOperations = wfAligner->cigar.operations + wfAligner->cigar.begin_offset;
*cigarLength = wfAligner->cigar.end_offset - wfAligner->cigar.begin_offset;
*cigarOperations = wfAligner->cigar->operations + wfAligner->cigar->begin_offset;
*cigarLength = wfAligner->cigar->end_offset - wfAligner->cigar->begin_offset;
}
std::string WFAligner::getAlignmentCigar() {
// Fetch CIGAR
Expand Down Expand Up @@ -266,6 +288,19 @@ WFAlignerGapLinear::WFAlignerGapLinear(
attributes.linear_penalties.indel = indel;
wfAligner = wavefront_aligner_new(&attributes);
}
WFAlignerGapLinear::WFAlignerGapLinear(
const int match,
const int mismatch,
const int indel,
const AlignmentScope alignmentScope,
const MemoryModel memoryModel) :
WFAligner(alignmentScope,memoryModel) {
attributes.distance_metric = gap_linear;
attributes.linear_penalties.match = match;
attributes.linear_penalties.mismatch = mismatch;
attributes.linear_penalties.indel = indel;
wfAligner = wavefront_aligner_new(&attributes);
}
/*
* Gap-Affine Aligner (a.k.a Smith-Waterman-Gotoh)
*/
Expand All @@ -283,6 +318,21 @@ WFAlignerGapAffine::WFAlignerGapAffine(
attributes.affine_penalties.gap_extension = gapExtension;
wfAligner = wavefront_aligner_new(&attributes);
}
WFAlignerGapAffine::WFAlignerGapAffine(
const int match,
const int mismatch,
const int gapOpening,
const int gapExtension,
const AlignmentScope alignmentScope,
const MemoryModel memoryModel) :
WFAligner(alignmentScope,memoryModel) {
attributes.distance_metric = gap_affine;
attributes.affine_penalties.match = match;
attributes.affine_penalties.mismatch = mismatch;
attributes.affine_penalties.gap_opening = gapOpening;
attributes.affine_penalties.gap_extension = gapExtension;
wfAligner = wavefront_aligner_new(&attributes);
}
/*
* Gap-Affine Dual-Cost Aligner (a.k.a. concave 2-pieces)
*/
Expand All @@ -304,6 +354,25 @@ WFAlignerGapAffine2Pieces::WFAlignerGapAffine2Pieces(
attributes.affine2p_penalties.gap_extension2 = gapExtension2;
wfAligner = wavefront_aligner_new(&attributes);
}
WFAlignerGapAffine2Pieces::WFAlignerGapAffine2Pieces(
const int match,
const int mismatch,
const int gapOpening1,
const int gapExtension1,
const int gapOpening2,
const int gapExtension2,
const AlignmentScope alignmentScope,
const MemoryModel memoryModel) :
WFAligner(alignmentScope,memoryModel) {
attributes.distance_metric = gap_affine_2p;
attributes.affine2p_penalties.match = match;
attributes.affine2p_penalties.mismatch = mismatch;
attributes.affine2p_penalties.gap_opening1 = gapOpening1;
attributes.affine2p_penalties.gap_extension1 = gapExtension1;
attributes.affine2p_penalties.gap_opening2 = gapOpening2;
attributes.affine2p_penalties.gap_extension2 = gapExtension2;
wfAligner = wavefront_aligner_new(&attributes);
}

} /* namespace wfa */

Loading

0 comments on commit 0d77c88

Please sign in to comment.