Skip to content

Commit

Permalink
Merge pull request #13 from ilia-kats/updates
Browse files Browse the repository at this point in the history
update WFA2-lib, expose more options to Python
  • Loading branch information
kcleal authored Feb 27, 2024
2 parents db26570 + 02cb9a8 commit 734c970
Show file tree
Hide file tree
Showing 92 changed files with 7,118 additions and 3,317 deletions.
2 changes: 1 addition & 1 deletion _custom_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def get_extra_args(flags):
# this has happened on multiple OS with/without `libomp-dev`
# compiler = ccompiler.new_compiler()
omp = 0 #1 if has_flag(compiler, "-fopenmp") else 0
ret = run(f"cd pywfa/WFA2_lib; make clean all BUILD_WFA_PARALLEL={omp} BUILD_MINIMAL=1",
ret = run(f"cd pywfa/WFA2_lib; make clean all BUILD_WFA_PARALLEL={omp} BUILD_TOOLS=0 BUILD_EXAMPLES=0",
shell=True)
if ret.returncode != 0:
print("Unable to build WFA2_lib")
Expand Down
43 changes: 43 additions & 0 deletions pywfa/WFA2_lib/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
lib/
bin/
build/

# Prerequisites
*.d

# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app

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


226 changes: 226 additions & 0 deletions pywfa/WFA2_lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
# For Debian currently with
#
# cd build
# cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo ..
# make
# make test
# make install
# See below option statements and the README for build information

cmake_minimum_required(VERSION 3.16)
project(wfa2lib)

set(CMAKE_CXX_STANDARD 17)

include(FeatureSummary)
include(GNUInstallDirs)

find_package(PkgConfig REQUIRED)

feature_summary(
FATAL_ON_MISSING_REQUIRED_PACKAGES
WHAT REQUIRED_PACKAGES_NOT_FOUND)

# ---- Options

option(OPENMP "Enable OpenMP" OFF) # enables WFA_PARALLEL
option(PROFILING "Enable profiling" OFF)
option(ASAN "Use address sanitiser" OFF)
option(EXTRA_FLAGS "Add optimization flags for C/C++ compiler" OFF)

# include(CheckIPOSupported) # adds lto
# check_ipo_supported(RESULT ipo_supported OUTPUT output)

# ---- Dependencies

if(OPENMP)
include(FindOpenMP)
set(OPTIMIZE_FLAGS "-DWFA_PARALLEL")
endif(OPENMP)

if(EXTRA_FLAGS)
set(OPTIMIZE_FLAGS "${OPTIMIZE_FLAGS} ${EXTRA_FLAGS}")
endif(EXTRA_FLAGS)

find_package(Threads)
set_package_properties(Threads PROPERTIES TYPE REQUIRED)

# ---- Build switches
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ${ipo_supported})

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING
"Choose the type of build, options are: Release|Debug|RelWithDebInfo (for distros)." FORCE)
endif()

if (${CMAKE_BUILD_TYPE} MATCHES Release)
set(OPTIMIZE_FLAGS "${OPTIMIZE_FLAGS} -march=native -D_FILE_OFFSET_BITS=64")
endif()

if ((${CMAKE_BUILD_TYPE} MATCHES Release) OR (${CMAKE_BUILD_TYPE} MATCHES RelWithDebInfo))
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OPTIMIZE_FLAGS}")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OPTIMIZE_FLAGS}")
endif ()

if (${CMAKE_BUILD_TYPE} MATCHES "Debug")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OPTIMIZE_FLAGS}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OPTIMIZE_FLAGS}")
add_definitions(-Wfatal-errors)
endif ()

if (ASAN)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fno-omit-frame-pointer -fno-common")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer -fno-common")
endif(ASAN)

if(PROFILING)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
endif(PROFILING)

if(GPROF)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg")
endif(GPROF)

# ---- Include files

file(GLOB INCLUDES
wavefront/*.h*
)
file(GLOB UTILS_INCLUDES
utils/*.h*
)
file(GLOB ALIGNMENT_INCLUDES
alignment/*.h*
)
file(GLOB SYSTEM_INCLUDES
system/*.h*
)

set(wfa2lib_SOURCE
wavefront/wavefront_align.c
wavefront/wavefront_aligner.c
wavefront/wavefront_attributes.c
wavefront/wavefront_backtrace_buffer.c
wavefront/wavefront_backtrace.c
wavefront/wavefront_backtrace_offload.c
wavefront/wavefront_bialign.c
wavefront/wavefront_bialigner.c
wavefront/wavefront.c
wavefront/wavefront_components.c
wavefront/wavefront_compute_affine2p.c
wavefront/wavefront_compute_affine.c
wavefront/wavefront_compute.c
wavefront/wavefront_compute_edit.c
wavefront/wavefront_compute_linear.c
wavefront/wavefront_debug.c
wavefront/wavefront_display.c
wavefront/wavefront_extend.c
wavefront/wavefront_heuristic.c
wavefront/wavefront_pcigar.c
wavefront/wavefront_penalties.c
wavefront/wavefront_plot.c
wavefront/wavefront_sequences.c
wavefront/wavefront_slab.c
wavefront/wavefront_unialign.c
wavefront/wavefront_termination.c
wavefront/wavefront_extend_kernels_avx.c
wavefront/wavefront_extend_kernels.c
system/mm_stack.c
system/mm_allocator.c
system/profiler_counter.c
system/profiler_timer.c
utils/bitmap.c
utils/dna_text.c
utils/sequence_buffer.c
utils/vector.c
utils/commons.c
utils/heatmap.c
alignment/affine2p_penalties.c
alignment/affine_penalties.c
alignment/cigar.c
alignment/score_matrix.c
)

add_library(wfa2_static
${wfa2lib_SOURCE}
)
add_library(wfa2 SHARED ${wfa2lib_SOURCE})
set_target_properties(wfa2_static PROPERTIES OUTPUT_NAME wfa2)
set_target_properties(wfa2 PROPERTIES SOVERSION 0)
target_include_directories(wfa2 PUBLIC . wavefront utils)
target_include_directories(wfa2_static PUBLIC . wavefront utils)
add_library(wfa2::wfa2 ALIAS wfa2)
add_library(wfa2::wfa2_static ALIAS wfa2_static)

if(OPENMP)
target_link_libraries(wfa2_static PRIVATE OpenMP::OpenMP_C)
target_link_libraries(wfa2 PRIVATE OpenMP::OpenMP_C)
endif(OPENMP)

# ---- C++ binding library

set(wfa2cpp_SOURCE
bindings/cpp/WFAligner.cpp
)
file(GLOB CPP_INCLUDES
bindings/cpp/*.h*
)
add_library(wfa2cpp_static STATIC ${wfa2cpp_SOURCE})
add_library(wfa2cpp SHARED ${wfa2cpp_SOURCE})
set_target_properties(wfa2cpp PROPERTIES SOVERSION 0)
set_target_properties(wfa2cpp_static PROPERTIES OUTPUT_NAME wfa2cpp)
target_link_libraries(wfa2cpp PUBLIC wfa2)
target_link_libraries(wfa2cpp_static PUBLIC wfa2_static)
add_library(wfa2::wfa2cpp ALIAS wfa2cpp)
add_library(wfa2::wfa2cpp_static ALIAS wfa2cpp_static)

if(OPENMP)
target_link_libraries(wfa2cpp_static PRIVATE OpenMP::OpenMP_CXX)
target_link_libraries(wfa2cpp PRIVATE OpenMP::OpenMP_CXX)
endif(OPENMP)

# ---- Get version

file (STRINGS "VERSION.txt" BUILD_NUMBER)
add_definitions(-DWFA2LIB_VERSION="${BUILD_NUMBER}")
add_definitions(-DVERSION="${BUILD_NUMBER}")

set(wfa2lib_LIBS
)

# add_dependencies(wfa2lib ${wfa2lib_DEPS})

# ---- Build all

# ---- Test

enable_testing()


function(add_wfa_test)
add_test(
NAME wfa2lib
COMMAND ./tests/wfa.utest.sh
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
endfunction()

add_wfa_test()

# ---- Install

# Do not install anything when used with FetchContent
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
install(TARGETS wfa2_static ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} )
install(TARGETS wfa2 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} )

install(FILES ${INCLUDES} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/wfa2lib/wavefront)
install(FILES ${UTILS_INCLUDES} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/wfa2lib/utils)
install(FILES ${ALIGNMENT_INCLUDES} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/wfa2lib/alignment)
install(FILES ${SYSTEM_INCLUDES} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/wfa2lib/system)

install(TARGETS wfa2cpp ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(TARGETS wfa2cpp_static ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(FILES ${CPP_INCLUDES} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/wfa2lib/bindings/cpp)
endif()
45 changes: 17 additions & 28 deletions pywfa/WFA2_lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ FOLDER_BIN=bin
FOLDER_BUILD=build
FOLDER_BUILD_CPP=build/cpp
FOLDER_LIB=lib
FOLDER_TESTS=tests

UNAME=$(shell uname)

Expand All @@ -16,17 +17,14 @@ CC_FLAGS=-Wall -g -fPIC
AR=ar
AR_FLAGS=-rsc

ifndef BUILD_EXAMPLES
BUILD_EXAMPLES=0
ifndef BUILD_EXAMPLES
BUILD_EXAMPLES=1
endif
ifndef BUILD_TOOLS
ifndef BUILD_TOOLS
BUILD_TOOLS=1
endif
ifndef BUILD_WFA_PARALLEL
BUILD_WFA_PARALLEL=1
endif
ifndef BUILD_MINIMAL
BUILD_MINIMAL=0
BUILD_WFA_PARALLEL=0
endif

###############################################################################
Expand All @@ -38,18 +36,12 @@ SUBDIRS=alignment \
system \
utils \
wavefront
ifeq ($(BUILD_MINIMAL),0)
SUBDIRS+=bindings/cpp
ifeq ($(BUILD_TOOLS),1)
APPS+=tools/generate_dataset \
tools/align_benchmark
endif

ifeq ($(BUILD_MINIMAL),0)
ifeq ($(BUILD_TOOLS),1)
APPS+=tools/generate_dataset \
tools/align_benchmark
endif
ifeq ($(BUILD_EXAMPLES),1)
APPS+=examples
endif
ifeq ($(BUILD_EXAMPLES),1)
APPS+=examples
endif

all: CC_FLAGS+=-O3 -march=native #-flto -ffat-lto-objects
Expand All @@ -69,29 +61,26 @@ asan: build
# Build rules
###############################################################################
build: setup
build: $(SUBDIRS)
build: lib_wfa
build: $(SUBDIRS)
build: lib_wfa
build: $(APPS)

setup:
$( if ($(BUILD_MINIMAL),0) $(@mkdir -p $(FOLDER_BUILD_CPP)))
@mkdir -p $(FOLDER_BIN) $(FOLDER_BUILD) $(FOLDER_LIB)

@mkdir -p $(FOLDER_BIN) $(FOLDER_BUILD) $(FOLDER_BUILD_CPP) $(FOLDER_LIB)

lib_wfa: $(SUBDIRS)
$(AR) $(AR_FLAGS) $(LIB_WFA) $(FOLDER_BUILD)/*.o 2> /dev/null
$( if ($(BUILD_MINIMAL),0) $(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)
$(MAKE)

rm -rf $(FOLDER_BIN) $(FOLDER_BUILD) $(FOLDER_LIB) 2> /dev/null

###############################################################################
# Subdir rule
###############################################################################
export
$(SUBDIRS):
$(MAKE) --directory=$@ all

$(APPS):
$(MAKE) --directory=$@ all

Expand Down
Loading

0 comments on commit 734c970

Please sign in to comment.