Skip to content

Commit

Permalink
Merge pull request #304 from pjotrp/main
Browse files Browse the repository at this point in the history
wfmash now builds with clang
  • Loading branch information
AndreaGuarracino authored Dec 15, 2024
2 parents 606f55c + af58c5e commit 164433d
Show file tree
Hide file tree
Showing 15 changed files with 3,502 additions and 250 deletions.
12 changes: 4 additions & 8 deletions .github/workflows/test_on_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,12 @@ jobs:
run: git submodule update --init --recursive
- name: Build wfmash
run: cmake -H. -Bbuild -D CMAKE_BUILD_TYPE=Debug -DWFA_PNG_AND_TSV=ON && cmake --build build -- -j 2
- name: Test mapping coverage with 8 yeast genomes (PAF output)
run: ASAN_OPTIONS=detect_leaks=1:symbolize=1 LSAN_OPTIONS=verbosity=0:log_threads=1 build/bin/wfmash data/scerevisiae8.fa.gz -p 95 -n 7 -m -L -Y '#' > scerevisiae8.paf; scripts/test.sh data/scerevisiae8.fa.gz.fai scerevisiae8.paf 0.92
- name: Run cmake tests
run: |
cd build
ctest --verbose
- name: Test mapping+alignment with a subset of the LPA dataset (PAF output)
run: ASAN_OPTIONS=detect_leaks=1:symbolize=1 LSAN_OPTIONS=verbosity=0:log_threads=1 build/bin/wfmash data/LPA.subset.fa.gz -n 10 -L > LPA.subset.paf && head LPA.subset.paf
- name: Test mapping+alignment with a subset of the LPA dataset (SAM output)
run: ASAN_OPTIONS=detect_leaks=1:symbolize=1 LSAN_OPTIONS=verbosity=0:log_threads=1 build/bin/wfmash data/LPA.subset.fa.gz -N -a -L > LPA.subset.sam && samtools view LPA.subset.sam -bS | samtools sort > LPA.subset.bam && samtools index LPA.subset.bam && samtools view LPA.subset.bam | head | cut -f 1-9
- name: Test mapping+alignment with short reads (500 bps) to a reference (SAM output)
run: ASAN_OPTIONS=detect_leaks=1:symbolize=1 LSAN_OPTIONS=verbosity=0:log_threads=1 build/bin/wfmash data/reference.fa.gz data/reads.500bps.fa.gz -s 0.5k -N -a > reads.500bps.sam && samtools view reads.500bps.sam -bS | samtools sort > reads.500bps.bam && samtools index reads.500bps.bam && samtools view reads.500bps.bam | head
- name: Test mapping+alignment with short reads (255bps) (PAF output)
run: ASAN_OPTIONS=detect_leaks=1:symbolize=1 LSAN_OPTIONS=verbosity=0:log_threads=1 build/bin/wfmash data/reads.255bps.fa.gz -w 16 -s 100 -L > reads.255bps.paf && head reads.255bps.paf
- name: Test input mapping functionality
run: |
# First generate mappings
Expand Down
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ wfmash
#build directories
src/common/wflign/build
build
pgo

#Others
*.bam
*.bai
*.sam
*.bed
wfmash-*
*.cache
*~
\#*
Expand All @@ -32,9 +38,11 @@ src/common/WFA2-lib/bin/
src/wfmash_git_version.hpp
src/common/wflign/src/wflign_git_version.hpp

test/
.idea/
cmake-build-debug/
result
tmp/
.aider*
.env
scerevisiae8*
reads.255bps.paf
157 changes: 122 additions & 35 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,27 +1,49 @@
# Usage:
#
# mkdir build ; cd build
# cmake -DCMAKE_BUILD_TYPE=Debug ..
# make -j 8 VERBOSE=1
#
# Build types are Release (default), Debug, Generic, RelWithDebInfo

cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
project(wfmash)

enable_testing()

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

include(GNUInstallDirs)
include(CheckCXXCompilerFlag)

set(CMAKE_CXX_STANDARD 17)
# set(CMAKE_CXX_STANDARD 20) # because of sequenceIds.hpp:101:23: warning: captured structured bindings are a C++20 extension [-Wc++20-extensions]
set(CMAKE_CXX_STANDARD_REQUIRED ON) # Falling back to different standard is not allowed.
set(CMAKE_CXX_EXTENSIONS OFF) # Make sure no compiler-specific features are used.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)


option(BUILD_STATIC "Build static binary" OFF)
option(BUILD_DEPS "Build external dependencies" OFF)
option(BUILD_RETARGETABLE "Build retargetable binary" OFF)
option(BUILD_OPTIMIZED "Build optimized binary" OFF)
option(GPROF "Enable gprof profiling" OFF)
option(DISABLE_LTO "Disable IPO/LTO" OFF)
option(STOP_ON_ERROR "Stop compiling on first error" OFF)

if (NOT DISABLE_LTO)
include(CheckIPOSupported) # adds lto
check_ipo_supported(RESULT ipo_supported OUTPUT output) # lto
endif()

if (STOP_ON_ERROR)
add_definitions( -Wfatal-errors )
endif()

if (BUILD_STATIC)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
set(BUILD_SHARED_LIBS OFF)
set(CMAKE_EXE_LINKER_FLAGS "-static")
set(CMAKE_POSITION_INDEPENDENT_CODE OFF)
else ()
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif ()

find_package(PkgConfig REQUIRED)
Expand All @@ -34,43 +56,53 @@ find_package(OpenMP REQUIRED)

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

message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")

if (${CMAKE_BUILD_TYPE} MATCHES Release)
set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG")
set(CMAKE_C_FLAGS_RELEASE "-DNDEBUG")
if (NOT EXTRA_FLAGS)
if (BUILD_RETARGETABLE)
set(EXTRA_FLAGS "-Ofast -march=x86-64-v3 -flto")
else()
set(EXTRA_FLAGS "-Ofast -march=native -flto")
endif()
if (BUILD_OPTIMIZED)
# set(EXTRA_FLAGS "-Ofast -march=native -pipe -msse4.2 -funroll-all-loops") # -fprofile-generate=../pgo")
# set(EXTRA_FLAGS "-Ofast -march=x86-64-v3 -funroll-all-loops")
set(EXTRA_FLAGS "-O3 -march=native -funroll-all-loops")
# set(EXTRA_FLAGS "-O3 -march=native -funroll-all-loops -fprofile-generate=${CMAKE_BINARY_DIR}/../pgo")
# set(EXTRA_FLAGS "-O3 -march=native -funroll-all-loops -fprofile-use=${CMAKE_BINARY_DIR}/../pgo")

else()
set(EXTRA_FLAGS "-Ofast -march=native")
endif()
set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG ${EXTRA_FLAGS}")
set(CMAKE_C_FLAGS_RELEASE "-DNDEBUG ${EXTRA_FLAGS}")
endif ()

if (${CMAKE_BUILD_TYPE} MATCHES Generic)
set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG")
set(CMAKE_C_FLAGS_RELEASE "-DNDEBUG")
if (NOT EXTRA_FLAGS)
set(EXTRA_FLAGS "-Ofast -flto")
endif()
endif ()

if (${CMAKE_BUILD_TYPE} MATCHES Debug)
# Enable debug symbols and ASan with no optimizations
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -g -fsanitize=address -fno-omit-frame-pointer")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g -fsanitize=address -fno-omit-frame-pointer")
# Ensure that ASan is linked explicitly
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
else()
set (CMAKE_C_FLAGS "${OpenMP_C_FLAGS} ${PIC_FLAG} ${EXTRA_FLAGS}")
set (CMAKE_CXX_FLAGS "${OpenMP_CXX_FLAGS} ${PIC_FLAG} ${EXTRA_FLAGS}")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
else ()
set (CMAKE_C_FLAGS "${OpenMP_C_FLAGS}")
set (CMAKE_CXX_FLAGS "${OpenMP_CXX_FLAGS}")
endif ()

if(WFA_PNG_AND_TSV)
if( NOT DISABLE_LTO AND ipo_supported )
message(STATUS "IPO / LTO enabled")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ${ipo_supported})
endif()

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

if (WFA_PNG_AND_TSV)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWFA_PNG_TSV_TIMING")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DWFA_PNG_TSV_TIMING")
endif ()
Expand Down Expand Up @@ -145,13 +177,15 @@ else()
#)

target_link_libraries(wfmash
gsl
gslcblas
hts
deflate
gsl
gslcblas
hts
deflate
)
endif()



target_include_directories(wfmash PRIVATE
src
src/common
Expand All @@ -162,32 +196,85 @@ target_include_directories(wfmash PRIVATE
target_link_libraries(wfmash
m
pthread
libwflign_static
rt
wfa2cpp_static
lzma
bz2
z
Threads::Threads
)

if (BUILD_STATIC)
target_link_libraries(wfmash
wflign_static
wfa2cpp_static
)
else()
target_link_libraries(wfmash
wflign
wfa2cpp
)
endif()

# This is to disable tests defined in CTestCustom.cmake:
configure_file(${CMAKE_SOURCE_DIR}/CTestCustom.cmake ${CMAKE_BINARY_DIR})

set(INVOKE "ASAN_OPTIONS=detect_leaks=1:symbolize=1 LSAN_OPTIONS=verbosity=0:log_threads=1 ${CMAKE_BINARY_DIR}/bin/wfmash")
set(REGRESSION_TEST_DIR "test/data/regression")

add_test(
NAME wfmash-time-LPA
COMMAND bash -c "${INVOKE} data/LPA.subset.fa.gz -p 80 -n 5 -t 8 > wfmash-time-LPA.output"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})

add_test(
NAME wfmash-subset-LPA-to-SAM
COMMAND bash -c "${INVOKE} data/LPA.subset.fa.gz -N -a -L > LPA.subset.sam && samtools view LPA.subset.sam -bS | samtools sort > LPA.subset.bam && samtools index LPA.subset.bam && samtools view LPA.subset.bam | head | cut -f 1-9"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})

add_test(
NAME wfmash-mapping-coverage-with-8-yeast-genomes-to-PAF
COMMAND bash -c "${INVOKE} data/scerevisiae8.fa.gz -p 95 -n 7 -m -L -Y \\# > scerevisiae8.paf && ./scripts/test.sh data/scerevisiae8.fa.gz.fai scerevisiae8.paf 0.92 && head -3000 scerevisiae8.paf > scerevisiae8.paf.output && ${CMAKE_COMMAND} -E compare_files ${REGRESSION_TEST_DIR}/scerevisiae8.paf.output scerevisiae8.paf.output"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})

add_test(
NAME wfmash-test
COMMAND wfmash data/LPA.subset.fa.gz -p 80 -n 5 -t 8
NAME wfmash-short-reads-500bps-to-SAM
COMMAND bash -c "${INVOKE} data/reference.fa.gz data/reads.500bps.fa.gz -s 0.5k -N -a > reads.500bps.sam && samtools view reads.500bps.sam -bS | samtools sort > reads.500bps.bam && samtools index reads.500bps.bam && samtools view reads.500bps.bam | head > wfmash-short-reads-500bps-to-SAM.output && ${CMAKE_COMMAND} -E compare_files ${REGRESSION_TEST_DIR}/wfmash-short-reads-500bps-to-SAM.output wfmash-short-reads-500bps-to-SAM.output"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})

add_test(
NAME wfmash-short-reads-255bps-to-PAF
COMMAND bash -c "${INVOKE} data/reads.255bps.fa.gz -w 16 -s 100 -L > reads.255bps.paf && head reads.255bps.paf && ${CMAKE_COMMAND} -E compare_files ${REGRESSION_TEST_DIR}/reads.255bps.paf reads.255bps.paf"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})

install(TARGETS wfmash DESTINATION bin)

install(TARGETS wfa2cpp_static
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
if (BUILD_STATIC)

install(TARGETS wfa2cpp_static
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

install(TARGETS wflign_static
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

install(TARGETS wfa2_static
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(TARGETS wfa2_static
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
else()

install(TARGETS wfa2cpp
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

install(TARGETS wflign
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

install(TARGETS wfa2
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
endif()

file(MAKE_DIRECTORY ${CMAKE_SOURCE_DIR}/include)
execute_process(COMMAND bash ${CMAKE_SOURCE_DIR}/scripts/generate_git_version.sh ${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/src/common/wflign/src)
Loading

0 comments on commit 164433d

Please sign in to comment.