Skip to content

Commit

Permalink
Merge pull request #91 from pjotrp/main
Browse files Browse the repository at this point in the history
Minor fixes for testing with vcflib
  • Loading branch information
smarco authored Apr 20, 2024
2 parents 6bf5ba0 + 151af8e commit cf3eb92
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 51 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
lib/
bin/
build/
Testing/

# Prerequisites
*.d
Expand Down Expand Up @@ -39,5 +40,5 @@ build/
tests/wfa.utest.log.correct
tests/wfa.utest.log.mem
tests/wfa.utest.log.time

tests/*.alg

52 changes: 47 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# For Debian currently with
#
# cd build
# cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo ..
# make
# make test
# cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DOPENMP=1 ..
# cmake --build .
# ctest .
# make install
# See below option statements and the README for build information

Expand Down Expand Up @@ -192,16 +192,58 @@ set(wfa2lib_LIBS
# add_dependencies(wfa2lib ${wfa2lib_DEPS})

# ---- Build all
# add_subdirectory(tools/align_benchmark)


add_executable(align_benchmark
tools/align_benchmark/align_benchmark_params.c
tools/align_benchmark/align_benchmark.c
tools/align_benchmark/benchmark/benchmark_check.c
tools/align_benchmark/benchmark/benchmark_edit.c
tools/align_benchmark/benchmark/benchmark_gap_affine2p.c
tools/align_benchmark/benchmark/benchmark_gap_affine.c
tools/align_benchmark/benchmark/benchmark_gap_linear.c
tools/align_benchmark/benchmark/benchmark_indel.c
tools/align_benchmark/benchmark/benchmark_utils.c
system/mm_allocator.c
system/mm_stack.c
system/profiler_counter.c
system/profiler_timer.c
utils/bitmap.c
utils/commons.c
utils/dna_text.c
utils/heatmap.c
utils/sequence_buffer.c
utils/vector.c
alignment/affine2p_penalties.c
alignment/affine_penalties.c
alignment/cigar.c
alignment/score_matrix.c
tools/align_benchmark/gap_affine/affine_matrix.c
tools/align_benchmark/gap_affine/swg.c
tools/align_benchmark/gap_linear/nw.c
tools/align_benchmark/gap_affine2p/affine2p_dp.c
tools/align_benchmark/gap_affine2p/affine2p_matrix.c
tools/align_benchmark/edit/edit_bpm.c
tools/align_benchmark/edit/edit_dp.c
tools/align_benchmark/indel/indel_dp.c
)
target_include_directories(align_benchmark PUBLIC . wavefront system utils tools/align_benchmark)
add_dependencies(align_benchmark wfa2)
target_link_libraries(align_benchmark m)
target_link_libraries(align_benchmark wfa2)
if(OPENMP)
target_link_libraries(align_benchmark OpenMP::OpenMP_C)
endif(OPENMP)

# ---- Test

enable_testing()


function(add_wfa_test)
add_test(
NAME wfa2lib
COMMAND ./tests/wfa.utest.sh
COMMAND ./tests/wfa.utest.sh ${CMAKE_CURRENT_BINARY_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
endfunction()
Expand Down
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The WFA2 library implements the WFA algorithm for different distance metrics and

### 1.3 Getting started

Git clone and compile the library, tools, and examples (by default, use cmake).
Git clone and compile the library, tools, and examples (by default, use cmake for the library and benchmark build).

```
git clone https://github.com/smarco/WFA2-lib
Expand All @@ -34,13 +34,7 @@ cmake .. -DOPENMP=TRUE
cmake .. -DCMAKE_BUILD_TYPE=Release -DEXTRA_FLAGS="-ftree-vectorizer-verbose=5"
```

To build a shared library (static is the default).

```
cmake -DBUILD_SHARED_LIBS=ON
```

Alternatively, the Makefile build system can be used.
Alternatively, the simple Makefile build system can be used.

```
$> git clone https://github.com/smarco/WFA2-lib
Expand Down
4 changes: 3 additions & 1 deletion guix.scm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
;; Set up build environment using GNU Guix packages
;;
;; CC0 license, Pjotr Prins (c) 2022-2023
;; CC0 license, Pjotr Prins (c) 2022-2024
;;
;; To use this file to build HEAD:
;;
Expand Down Expand Up @@ -44,6 +44,7 @@
(gnu packages llvm)
(gnu packages parallel)
(gnu packages pkg-config)
(gnu packages time)
(srfi srfi-1)
(ice-9 popen)
(ice-9 rdelim))
Expand All @@ -61,6 +62,7 @@
(build-system cmake-build-system)
(inputs
`(("bash" ,bash)
("time" ,time)
("gdb" ,gdb)))
(native-inputs
`(("pkg-config" ,pkg-config)))
Expand Down
2 changes: 1 addition & 1 deletion tests/wfa.utest.clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
OUTPUT="./tests"

# Clear
rm $OUTPUT/*.alg $OUTPUT/*.log* &> /dev/null
rm -f $OUTPUT/*.alg $OUTPUT/*.log* &> /dev/null

7 changes: 4 additions & 3 deletions tests/wfa.utest.cmp.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
# PROJECT: Wavefront Alignments Algorithms (Unitary Tests)
# LICENCE: MIT License
# LICENCE: MIT License
# AUTHOR(S): Santiago Marco-Sola <santiagomsola@gmail.com>
# DESCRIPTION: Compares alignments (*.alg) from two folders
# USAGE: ./wfa.utest.cmp.sh folder_1 folder_2 [--cmp-performance]
Expand All @@ -20,6 +20,7 @@ STATUS=0
echo "> Comparing $FOLDER1 vs $FOLDER2"
for FILE_ALG1 in $FOLDER1/*.alg
do
echo $FILE_ALG1
FILENAME=$(basename -- "$FILE_ALG1")
PREFIX=${FILENAME%.*}
FILE_ALG2="$FOLDER2/$FILENAME"
Expand All @@ -34,7 +35,7 @@ do
continue
fi
# Check diff
if [[ $(diff $FILE_ALG1 $FILE_ALG2) ]]
if [[ $(diff $FILE_ALG1 $FILE_ALG2) ]]
then
if [[ $(diff <(awk '{if ($1<0) print -$1; else print $1}' $FILE_ALG1) <(awk '{if ($1<0) print -$1; else print $1}' $FILE_ALG2)) ]]
then
Expand All @@ -52,7 +53,7 @@ do
if [[ $CMP_PERF == 1 ]]
then
T1=$(grep -m1 "Time.Alignment" $FOLDER1/$PREFIX.log | awk '{print $3" "$4}')
T2=$(grep -m1 "Time.Alignment" $FOLDER2/$PREFIX.log | awk '{print $3" "$4}')
T2=$(grep -m1 "Time.Alignment" $FOLDER2/$PREFIX.log | awk '{print $3" "$4}')
M1=$(grep -m1 "Maximum resident set size" $FOLDER1/$PREFIX.log | tr -d "(:)" | awk '{print $6" "$5}')
M2=$(grep -m1 "Maximum resident set size" $FOLDER2/$PREFIX.log | tr -d "(:)" | awk '{print $6" "$5}')
echo -e "\tTIME($T1,$T2)\tMEM($M1,$M2)"
Expand Down
4 changes: 2 additions & 2 deletions tests/wfa.utest.performance.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ LOWMEMORY="--wfa-memory-mode=med"
BIWFA="--wfa-memory-mode=ultralow"

# Clear
rm $OUTPUT/*.log $OUTPUT/*.alg
rm -f $OUTPUT/*.log $OUTPUT/*.alg

# Utest for length=100
\time -v ./bin/align_benchmark -a $ALGORITHM -i ../data/sim.l100.n100K.e2.seq -o $OUTPUT/sim.l100.e2.W.alg &> $OUTPUT/sim.l100.e2.W.log
Expand All @@ -41,4 +41,4 @@ rm $OUTPUT/*.log $OUTPUT/*.alg
echo ">>> "
echo ">>> Performance [base vs new]: "
echo ">>> "
./tests/wfa.utest.cmp.sh tests/wfa.utest.performance.check/ tests/ --cmp-performance
./tests/wfa.utest.cmp.sh tests/wfa.utest.performance.check/ tests/ --cmp-performance
62 changes: 33 additions & 29 deletions tests/wfa.utest.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash
# PROJECT: Wavefront Alignments Algorithms (Unitary Tests)
# LICENCE: MIT License
# LICENCE: MIT License
# AUTHOR(S): Santiago Marco-Sola <santiagomsola@gmail.com>
# DESCRIPTION: WFA unitary tests (correcness)
# DESCRIPTION: WFA unitary tests (correctness)
# USAGE: ./wfa.utest.sh

# Config
Expand All @@ -12,50 +12,55 @@ OUTPUT="$PREFIX"
LOG="$PREFIX/wfa.utest.log"

CMP_SCORE=$(readlink -f "$PREFIX/../scripts/wfa.alg.cmp.score.sh")
BIN=$(readlink -f "$PREFIX/../build/bin/align_benchmark")
if [ ! -f "$BIN" ]

BIN=$1/align_benchmark
if [ ! -f "$BIN" ]
then
BIN=$(readlink -f "$PREFIX/../bin/align_benchmark")
if [ ! -f "$BIN" ]
then
echo "[Error] Binaries not built. Please run cmake or make"
exit -1
fi
BIN=$(readlink -f "$PREFIX/../build/align_benchmark") # cmake
if [ ! -f "$BIN" ]
then
echo "[Error] Binaries not built. Please run cmake or make"
exit -1
fi
fi
fi

# Clear
rm $OUTPUT/*.alg $OUTPUT/*.log* &> /dev/null
rm -f $OUTPUT/*.alg $OUTPUT/*.log* &> /dev/null

# Run tests
for opt in "--check=correct","test" \
"--wfa-score-only","test.score" \
"--wfa-memory-mode=med --check=correct","test.pb" \
"--wfa-memory-mode=ultralow --check=correct","test.biwfa" \
"--wfa-memory-mode=ultralow --wfa-score-only","test.biwfa.score"
do
"--wfa-memory-mode=ultralow --wfa-score-only","test.biwfa.score"
do
# Config
IFS=','; set -- $opt
IFS=' '; MODE="$1"; NAME="$2"
echo ">>> Testing '$NAME' ($MODE)"

# Testing distance functions
\time -v $BIN -i $INPUT -o $OUTPUT/$NAME.indel.alg -a indel-wfa $MODE >> $LOG 2>&1
\time -v $BIN -i $INPUT -o $OUTPUT/$NAME.edit.alg -a edit-wfa $MODE >> $LOG 2>&1
\time -v $BIN -i $INPUT -o $OUTPUT/$NAME.affine.alg -a gap-affine-wfa $MODE >> $LOG 2>&1
\time -v $BIN -i $INPUT -o $OUTPUT/$NAME.affine2p.alg -a gap-affine2p-wfa $MODE >> $LOG 2>&1
\time -v $BIN -i $INPUT -o $OUTPUT/$NAME.indel.alg -a indel-wfa $MODE >> $LOG 2>&1
\time -v $BIN -i $INPUT -o $OUTPUT/$NAME.edit.alg -a edit-wfa $MODE >> $LOG 2>&1
\time -v $BIN -i $INPUT -o $OUTPUT/$NAME.affine.alg -a gap-affine-wfa $MODE >> $LOG 2>&1
\time -v $BIN -i $INPUT -o $OUTPUT/$NAME.affine2p.alg -a gap-affine2p-wfa $MODE >> $LOG 2>&1

# Testing penalty-scores
\time -v $BIN -i $INPUT -o $OUTPUT/$NAME.affine.p0.alg -a gap-affine-wfa $MODE --affine-penalties="0,1,2,1" >> $LOG 2>&1
\time -v $BIN -i $INPUT -o $OUTPUT/$NAME.affine.p1.alg -a gap-affine-wfa $MODE --affine-penalties="0,3,1,4" >> $LOG 2>&1
\time -v $BIN -i $INPUT -o $OUTPUT/$NAME.affine.p2.alg -a gap-affine-wfa $MODE --affine-penalties="0,5,3,2" >> $LOG 2>&1
\time -v $BIN -i $INPUT -o $OUTPUT/$NAME.affine.p3.alg -a gap-affine-wfa $MODE --affine-penalties="-5,1,2,1" >> $LOG 2>&1
\time -v $BIN -i $INPUT -o $OUTPUT/$NAME.affine.p4.alg -a gap-affine-wfa $MODE --affine-penalties="-2,3,1,4" >> $LOG 2>&1
\time -v $BIN -i $INPUT -o $OUTPUT/$NAME.affine.p5.alg -a gap-affine-wfa $MODE --affine-penalties="-3,5,3,2" >> $LOG 2>&1
\time -v $BIN -i $INPUT -o $OUTPUT/$NAME.affine.p0.alg -a gap-affine-wfa $MODE --affine-penalties="0,1,2,1" >> $LOG 2>&1
\time -v $BIN -i $INPUT -o $OUTPUT/$NAME.affine.p1.alg -a gap-affine-wfa $MODE --affine-penalties="0,3,1,4" >> $LOG 2>&1
\time -v $BIN -i $INPUT -o $OUTPUT/$NAME.affine.p2.alg -a gap-affine-wfa $MODE --affine-penalties="0,5,3,2" >> $LOG 2>&1

\time -v $BIN -i $INPUT -o $OUTPUT/$NAME.affine.p3.alg -a gap-affine-wfa $MODE --affine-penalties="-5,1,2,1" >> $LOG 2>&1
\time -v $BIN -i $INPUT -o $OUTPUT/$NAME.affine.p4.alg -a gap-affine-wfa $MODE --affine-penalties="-2,3,1,4" >> $LOG 2>&1
\time -v $BIN -i $INPUT -o $OUTPUT/$NAME.affine.p5.alg -a gap-affine-wfa $MODE --affine-penalties="-3,5,3,2" >> $LOG 2>&1

# Heuristics
\time -v $BIN -i $INPUT -o $OUTPUT/$NAME.affine.wfapt0.alg -a gap-affine-wfa $MODE --wfa-heuristic=wfa-adaptive --wfa-heuristic-parameters=10,50,1 >> $LOG 2>&1
\time -v $BIN -i $INPUT -o $OUTPUT/$NAME.affine.wfapt1.alg -a gap-affine-wfa $MODE --wfa-heuristic=wfa-adaptive --wfa-heuristic-parameters=10,50,10 >> $LOG 2>&1
\time -v $BIN -i $INPUT -o $OUTPUT/$NAME.affine.wfapt0.alg -a gap-affine-wfa $MODE --wfa-heuristic=wfa-adaptive --wfa-heuristic-parameters=10,50,1 >> $LOG 2>&1
\time -v $BIN -i $INPUT -o $OUTPUT/$NAME.affine.wfapt1.alg -a gap-affine-wfa $MODE --wfa-heuristic=wfa-adaptive --wfa-heuristic-parameters=10,50,10 >> $LOG 2>&1
done

# Intra-tests
Expand Down Expand Up @@ -91,9 +96,9 @@ grep "Maximum resident set size" $LOG | awk '{print $6}' | sort -n > $LOG.mem

# Display performance
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)
paste <(tail -n 4 $OUTPUT/wfa.utest.check/wfa.utest.log.time) <(tail -n 4 $OUTPUT/wfa.utest.log.time)
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)
paste <(tail -n 4 $OUTPUT/wfa.utest.check/wfa.utest.log.mem) <(tail -n 4 $OUTPUT/wfa.utest.log.mem)

# Display correct
./tests/wfa.utest.cmp.sh $OUTPUT $OUTPUT/wfa.utest.check
Expand All @@ -110,4 +115,3 @@ else
echo -e ">>>\n>>> ERROR\n>>>"
exit -1
fi

2 changes: 1 addition & 1 deletion tests/wfa.utest.valgrind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ OUTPUT="./tests"
LOG="./tests/wfa.utest.log.valgrind"

# Clear
rm $OUTPUT/*.alg $LOG
rm -f $OUTPUT/*.alg $LOG
touch $LOG

# Run tests
Expand Down
3 changes: 3 additions & 0 deletions tools/align_benchmark/align_benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -535,9 +535,11 @@ void align_benchmark_parallel() {
if (seqs_batch == 0) break;
// Parallel processing of the sequences batch
timer_start(&parameters.timer_global); // PROFILE
#ifdef WFA_PARALLEL
#pragma omp parallel num_threads(parameters.num_threads)
{
int tid = omp_get_thread_num();

#pragma omp for
for (int seq_idx=0;seq_idx<seqs_batch;++seq_idx) {
// Configure sequence
Expand All @@ -551,6 +553,7 @@ void align_benchmark_parallel() {
align_benchmark_run_algorithm(align_input+tid);
}
}
#endif
timer_stop(&parameters.timer_global); // PROFILE
// Update progress
seqs_processed += seqs_batch;
Expand Down

0 comments on commit cf3eb92

Please sign in to comment.