-
Notifications
You must be signed in to change notification settings - Fork 27
/
build.py
76 lines (67 loc) · 2.33 KB
/
build.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import itertools
import os
import platform
from subprocess import run
from cffi import FFI
samver = "1.15.1"
file_directory = os.path.dirname(os.path.realpath(__file__))
htslib_dir = os.path.join(file_directory, 'samtools-{}'.format(samver), 'htslib-{}'.format(samver))
libraries = ['m', 'z', 'lzma', 'bz2', 'pthread', 'curl', 'crypto']
extra_link_args = []
library_dirs = [htslib_dir]
src_dir = os.path.join(file_directory, 'src')
extra_compile_args = ['-std=c99', '-O3']
if platform.machine() in {"aarch64", "arm64"}:
if platform.system() == "Darwin":
pass
else:
extra_compile_args.append("-march=armv8-a+simd")
else:
extra_compile_args.append("-mtune=haswell")
libraries.append('deflate')
try:
conda_path = os.environ['CONDA_PREFIX']
extra_link_args = ['-Wl,-rpath={}/lib'.format(conda_path)]
except:
print("[WARNING] Conda prefix not found, please activate clair3 conda environment first!\n")
ffibuilder = FFI()
ffibuilder.set_source("libclair3",
r"""
#include "kvec.h"
#include "khash.h"
#include "levenshtein.h"
#include "medaka_bamiter.h"
#include "medaka_common.h"
#include "medaka_khcounter.h"
#include "clair3_pileup.h"
#include "clair3_full_alignment.h"
""",
libraries=libraries,
library_dirs=library_dirs,
include_dirs=[src_dir, htslib_dir],
sources=[
os.path.join(src_dir, x) for x in (
'levenshtein.c',
'medaka_bamiter.c',
'medaka_common.c',
'medaka_khcounter.c',
'clair3_pileup.c',
'clair3_full_alignment.c')],
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
extra_objects=[os.path.join(htslib_dir, 'libhts.a')]
)
cdef = [
"typedef struct { ...; } bam_fset;"
"bam_fset* create_bam_fset(char* fname, char* fasta_path);"
"void destroy_bam_fset(bam_fset* fset);"
]
for header in ('clair3_pileup.h', 'clair3_full_alignment.h'):
with open(os.path.join(src_dir, header), 'r') as fh:
# remove directives
lines = ''.join(x for x in fh.readlines() if not x.startswith('#'))
cdef.append(lines)
ffibuilder.cdef('\n\n'.join(cdef))
if __name__ == "__main__":
ffibuilder.compile(verbose=True)
run("cp {}/libclair3*.so {}/libclair3.so".format(file_directory, file_directory), shell=True)