Skip to content

Commit

Permalink
Patching WFA2-lib to prevent C macros from bleeding into the environm…
Browse files Browse the repository at this point in the history
…ent. See

- WFA2-lib smarco#35

and

- vcflib vcflib/vcflib#359

External tools will no longer include files wavefront_align.h or wavefront_aligner.h.
That includes the bindings that come with WFA2-lib itself - they included wavefront_aligner.h wrapped as external "C".
These no longer include files, such as commons.h, that define macros and variables that are mostly internal to WFA.

To bind external tools I have introduced a new include file 'wfa.h' that contains the function definitions and minimal data structures. This file is now included by wavefront_aligner.h so WFA2-lib sees the same definitions. Also I included wfa.hpp that uses a C calling convention for C++, so there is no need to wrap the include file in extern "C".

To make it work I had to remove almost all includes to utils/commons.h from the headers. If this causes compile errors in other tools, have them include the file at the .c level (not .h). I also merged wavefront_align.h into wfa.h, so as not to have to include wavefront_alignment.h fully every time.

To validate that it works I called some macros by vcflib - after this patch they no longer are seen.

Finally I included a guix.scm file that allows us to create an isolated build environment using different versions of C compilers etc. See the header of guix.scm for instructions.

Notes: it is better to use newer `#pragma once' for header files that the ifndef construct
  • Loading branch information
pjotrp committed Nov 26, 2022
1 parent 4600d5d commit 8f66ddf
Show file tree
Hide file tree
Showing 79 changed files with 412 additions and 297 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


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
3 changes: 1 addition & 2 deletions alignment/cigar.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* DESCRIPTION: Edit cigar data-structure (match/mismatch/insertion/deletion)
*/

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

/*
Expand Down Expand Up @@ -506,5 +507,3 @@ void cigar_print_pretty(
mm_allocator_free(mm_allocator,ops_alg);
mm_allocator_free(mm_allocator,text_alg);
}


1 change: 0 additions & 1 deletion 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 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
4 changes: 1 addition & 3 deletions bindings/cpp/WFAligner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@

#include <string>

extern "C" {
#include "../../wavefront/wavefront_aligner.h"
}
#include "../../wavefront/wfa.hpp"

/*
* Namespace
Expand Down
1 change: 1 addition & 0 deletions examples/wfa_adapt.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* DESCRIPTION: WFA Sample-Code
*/

#include "utils/commons.h"
#include "wavefront/wavefront_align.h"

int main(int argc,char* argv[]) {
Expand Down
1 change: 1 addition & 0 deletions examples/wfa_basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* DESCRIPTION: WFA Sample-Code
*/

#include "utils/commons.h"
#include "wavefront/wavefront_align.h"

int main(int argc,char* argv[]) {
Expand Down
1 change: 1 addition & 0 deletions examples/wfa_repeated.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* DESCRIPTION: WFA Sample-Code
*/

#include "utils/commons.h"
#include "wavefront/wavefront_align.h"

int main(int argc,char* argv[]) {
Expand Down
66 changes: 66 additions & 0 deletions guix.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
;; Set up build environment using GNU Guix packages
;;
;; CC0 license, Pjotr Prins (c) 2022
;;
;; To use this file to build HEAD:
;;
;; guix build -f guix.scm
;;
;; To get a development container (emacs shell will work)
;;
;; guix shell -C -D -f guix.scm
;;
;; For the tests you need /bin/bash. In a container create it with
;;
;; mkdir -p /bin ; ln -s $GUIX_ENVIRONMENT/bin/bash /bin/bash
;;
;; and run the tests with
;;
;; env CC=gcc make
;; ./tests/wfa.utest.sh

(use-modules
((guix licenses) #:prefix license:)
(guix gexp)
(guix packages)
(guix git-download)
(guix build-system cmake)
(gnu packages algebra)
(gnu packages autotools)
(gnu packages base)
(gnu packages bash)
(gnu packages compression)
(gnu packages build-tools)
(gnu packages check)
(gnu packages curl)
(gnu packages gcc)
(gnu packages gdb)
(gnu packages llvm)
(gnu packages parallel)
(gnu packages pkg-config)
(srfi srfi-1)
(ice-9 popen)
(ice-9 rdelim))

(define %source-dir (dirname (current-filename)))

(define %git-commit
(read-string (open-pipe "git show HEAD | head -1 | cut -d ' ' -f 2" OPEN_READ)))

(define-public wfa2-lib-git
(package
(name "wfa2-lib-git")
(version (git-version "1.3" "HEAD" %git-commit))
(source (local-file %source-dir #:recursive? #f))
(build-system cmake-build-system)
(inputs
`(("bash" ,bash)
("gdb" ,gdb)))
(native-inputs
`(("pkg-config" ,pkg-config)))
(home-page "https://github.com/smarco/WFA2-lib/")
(synopsis "Library for wavefront aligner")
(description "The wavefront alignment (WFA) algorithm is an **exact** gap-affine algorithm that takes advantage of homologous regions between the sequences to accelerate the alignment process. Unlike to traditional dynamic programming algorithms that run in quadratic time, the WFA runs in time `O(ns+s^2)`, proportional to the sequence length `n` and the alignment score `s`, using `O(s^2)` memory (or `O(s)` using the ultralow/BiWFA mode).")
(license license:expat))) ;; MIT license

wfa2-lib-git
4 changes: 1 addition & 3 deletions system/mm_allocator.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
* and dispatching memory segments in order.
*/

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

/*
Expand Down Expand Up @@ -611,6 +612,3 @@ void mm_allocator_print(
mm_allocator_print_allocator_requests(stream,mm_allocator,false);
}
}



3 changes: 1 addition & 2 deletions system/mm_stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
* requested at once.
*/

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

/*
Expand Down Expand Up @@ -265,5 +266,3 @@ void mm_stack_print(
fprintf(stream," => Segments.size %" PRIu64 " MB\n",segment_size/(1024*1024));
fprintf(stream," => Memory.available %" PRIu64 " MB\n",num_segments*(segment_size/(1024*1024)));
}


1 change: 1 addition & 0 deletions system/profiler_counter.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
* DESCRIPTION: Simple profile counter
*/

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

/*
Expand Down
2 changes: 0 additions & 2 deletions system/profiler_counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
#ifndef PROFILER_COUNTER_H_
#define PROFILER_COUNTER_H_

#include "utils/commons.h"

/*
* Counters
*/
Expand Down
1 change: 1 addition & 0 deletions system/profiler_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
* DESCRIPTION: Simple time profiler
*/

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

#ifdef __MACH__
Expand Down
1 change: 0 additions & 1 deletion system/profiler_timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#ifndef PROFILER_TIMER_H
#define PROFILER_TIMER_H

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

/*
Expand Down
2 changes: 2 additions & 0 deletions tools/align_benchmark/edit/edit_bpm.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
* DESCRIPTION: Edit-Distance based BPM alignment algorithm
*/

#include "utils/commons.h"
#include "system/mm_allocator.h"
#include "edit/edit_bpm.h"
#include "utils/dna_text.h"

Expand Down
1 change: 0 additions & 1 deletion tools/align_benchmark/edit/edit_bpm.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#ifndef EDIT_BPM_H_
#define EDIT_BPM_H_

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

Expand Down
2 changes: 2 additions & 0 deletions tools/align_benchmark/edit/edit_dp.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
* DESCRIPTION: Dynamic-programming algorithm to compute Levenshtein alignment (edit)
*/

#include "utils/commons.h"
#include "system/mm_allocator.h"
#include "edit_dp.h"

/*
Expand Down
1 change: 0 additions & 1 deletion tools/align_benchmark/edit/edit_dp.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#ifndef EDIT_DP_H_
#define EDIT_DP_H_

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

/*
Expand Down
2 changes: 2 additions & 0 deletions tools/align_benchmark/gap_affine/affine_matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
* DESCRIPTION: Gap-affine Matrix
*/

#include "utils/commons.h"
#include "system/mm_allocator.h"
#include "gap_affine/affine_matrix.h"

/*
Expand Down
1 change: 0 additions & 1 deletion tools/align_benchmark/gap_affine/affine_matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#ifndef AFFINE_MATRIX_H_
#define AFFINE_MATRIX_H_

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

/*
Expand Down
2 changes: 2 additions & 0 deletions tools/align_benchmark/gap_affine/swg.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
* pairwise alignment (Smith-Waterman-Gotoh - SWG)
*/

#include "utils/commons.h"
#include "system/mm_allocator.h"
#include "gap_affine/swg.h"

/*
Expand Down
1 change: 0 additions & 1 deletion tools/align_benchmark/gap_affine/swg.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#ifndef SWG_H_
#define SWG_H_

#include "utils/commons.h"
#include "gap_affine/affine_matrix.h"

/*
Expand Down
4 changes: 1 addition & 3 deletions utils/bitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* DESCRIPTION: Basic bitmap datastructure (static)
*/

#include "utils/commons.h"
#include "utils/bitmap.h"
#include "system/mm_allocator.h"

Expand Down Expand Up @@ -122,6 +123,3 @@ uint64_t bitmap_erank(
const uint64_t bitmap_count = POPCOUNT_64(bitmap_masked);
return bitmap_block->counter + bitmap_count;
}



1 change: 0 additions & 1 deletion utils/bitmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
/*
* Includes
*/
#include "utils/commons.h"
#include "system/mm_allocator.h"

#define BITMAP_BLOCK_ELEMENTS 64
Expand Down
5 changes: 1 addition & 4 deletions utils/commons.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
* DESCRIPTION: Common functions/utilities and headers for C development
*/

#ifndef COMMONS_H_
#define COMMONS_H_
#pragma once

#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -278,5 +277,3 @@ uint64_t nominal_prop_u64(const uint64_t base,const double factor);
int i; \
for (i=0;i<times;++i) fprintf(stream,"%c",character); \
}

#endif /* COMMONS_H_ */
2 changes: 1 addition & 1 deletion utils/dna_text.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
/*
* Include
*/
#include "utils/commons.h"
#include "utils/dna_text.h"

/*
Expand All @@ -58,4 +59,3 @@ const char dna_decode_table[DNA_EXTENDED_RANGE] =
[ENC_DNA_CHAR_T] = DNA_CHAR_T,
[ENC_DNA_CHAR_N] = DNA_CHAR_N,
};

2 changes: 0 additions & 2 deletions utils/dna_text.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
#ifndef DNA_TEXT_H_
#define DNA_TEXT_H_

#include "utils/commons.h"

/*
* Range of DNA Nucleotides
*/
Expand Down
4 changes: 1 addition & 3 deletions utils/heatmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* AUTHOR(S): Santiago Marco-Sola <[email protected]>
*/

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

/*
Expand Down Expand Up @@ -168,6 +169,3 @@ void heatmap_print(
fprintf(stream,"\n");
}
}



2 changes: 0 additions & 2 deletions utils/heatmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
#ifndef HEATMAP_H_
#define HEATMAP_H_

#include "utils/commons.h"

/*
* Heatmap
*/
Expand Down
Loading

0 comments on commit 8f66ddf

Please sign in to comment.