Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 11 additions & 18 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
# MIT License
# Copyright (C) 2025 Andrew D Smith
#
# Copyright (c) 2024 Andrew Smith
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <https://www.gnu.org/licenses/>.

BasedOnStyle: LLVM
ColumnLimit: 80
Expand Down
171 changes: 171 additions & 0 deletions cmake/FindHTSLIB.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
# SPDX-License-Identifier: GPL-3.0-or-later; (c) 2025 Andrew D Smith (author)
#[=======================================================================[.rst:
FindHTSLIB
--------

Find the native HTSLib includes and library. Based on the ZLIB module.

#]=======================================================================]

cmake_policy(PUSH)
cmake_policy(SET CMP0159 NEW) # file(STRINGS) with REGEX updates CMAKE_MATCH_<n>

if(HTSLIB_FIND_COMPONENTS AND NOT HTSLIB_FIND_QUIETLY)
message(AUTHOR_WARNING
"HTSLib does not provide any COMPONENTS. Calling\n"
" find_package(HTSLIB COMPONENTS ...)\n"
"will always fail."
)
endif()

set(_HTSLIB_SEARCHES)

# Search HTSLIB_ROOT first if it is set.
if(HTSLIB_ROOT)
set(_HTSLIB_SEARCH_ROOT PATHS ${HTSLIB_ROOT} NO_DEFAULT_PATH)
list(APPEND _HTSLIB_SEARCHES _HTSLIB_SEARCH_ROOT)
endif()

# Normal search.
# Windows stuff
set(_HTSLIB_x86 "(x86)")
set(_HTSLIB_SEARCH_NORMAL
PATHS "$ENV{ProgramFiles}/htslib"
"$ENV{ProgramFiles${_HTSLIB_x86}}/htslib")
unset(_HTSLIB_x86)
list(APPEND _HTSLIB_SEARCHES _HTSLIB_SEARCH_NORMAL)

if(HTSLIB_USE_STATIC_LIBS)
set(HTSLIB_NAMES hts)
set(HTSLIB_NAMES_DEBUG hts)
else()
set(HTSLIB_NAMES hts)
set(HTSLIB_NAMES_DEBUG hts)
endif()

# Try each search configuration.
foreach(search ${_HTSLIB_SEARCHES})
find_path(HTSLIB_INCLUDE_DIR NAMES htslib ${${search}} PATH_SUFFIXES include)
endforeach()

# Allow HTSLIB_LIBRARY to be set manually, as the location of the htslib library
if(NOT HTSLIB_LIBRARY)
if(DEFINED CMAKE_FIND_LIBRARY_PREFIXES)
set(_htslib_ORIG_CMAKE_FIND_LIBRARY_PREFIXES "${CMAKE_FIND_LIBRARY_PREFIXES}")
else()
set(_htslib_ORIG_CMAKE_FIND_LIBRARY_PREFIXES)
endif()
if(DEFINED CMAKE_FIND_LIBRARY_SUFFIXES)
set(_htslib_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES "${CMAKE_FIND_LIBRARY_SUFFIXES}")
else()
set(_htslib_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES)
endif()
# Prefix/suffix of the win32/Makefile.gcc build
if(WIN32)
list(APPEND CMAKE_FIND_LIBRARY_PREFIXES "" "lib")
list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES ".dll.a")
endif()
# Support preference of static libs by adjusting CMAKE_FIND_LIBRARY_SUFFIXES
if(HTSLIB_USE_STATIC_LIBS)
if(WIN32)
set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
else()
set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
endif()
endif()

foreach(search ${_HTSLIB_SEARCHES})
find_library(HTSLIB_LIBRARY_RELEASE NAMES ${HTSLIB_NAMES} NAMES_PER_DIR ${${search}} PATH_SUFFIXES lib)
find_library(HTSLIB_LIBRARY_DEBUG NAMES ${HTSLIB_NAMES_DEBUG} NAMES_PER_DIR ${${search}} PATH_SUFFIXES lib)
endforeach()

# Restore the original find library ordering
if(DEFINED _htslib_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES)
set(CMAKE_FIND_LIBRARY_SUFFIXES "${_htslib_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES}")
else()
set(CMAKE_FIND_LIBRARY_SUFFIXES)
endif()
if(DEFINED _htslib_ORIG_CMAKE_FIND_LIBRARY_PREFIXES)
set(CMAKE_FIND_LIBRARY_PREFIXES "${_htslib_ORIG_CMAKE_FIND_LIBRARY_PREFIXES}")
else()
set(CMAKE_FIND_LIBRARY_PREFIXES)
endif()

include(SelectLibraryConfigurations)
select_library_configurations(HTSLIB)
endif()

unset(HTSLIB_NAMES)
unset(HTSLIB_NAMES_DEBUG)

mark_as_advanced(HTSLIB_INCLUDE_DIR)

if(HTSLIB_INCLUDE_DIR AND EXISTS "${HTSLIB_INCLUDE_DIR}/htslib/hts.h")
# Example: #define HTS_VERSION 101300
file(STRINGS "${HTSLIB_INCLUDE_DIR}/htslib/hts.h" HTSLIB_H_LIST REGEX "^#define HTS_VERSION")
list(GET HTSLIB_H_LIST 0 HTSLIB_H) # Take the first matching line
if (HTSLIB_H MATCHES "#define[ \t]+HTS_VERSION[ \t]+\([0-9]+\)")
set(NUMERIC_VERSION "${CMAKE_MATCH_1}")
# Extract digits by position in string
# XYYYZZ => X = major, YYY = minor, ZZ = patch
string(SUBSTRING "${NUMERIC_VERSION}" 0 1 HTSLIB_VERSION_MAJOR)
string(SUBSTRING "${NUMERIC_VERSION}" 1 3 HTSLIB_VERSION_MINOR)
string(SUBSTRING "${NUMERIC_VERSION}" 4 2 HTSLIB_VERSION_PATCH)
else()
set(HTSLIB_VERSION_STRING "")
set(HTSLIB_VERSION_MAJOR "")
set(HTSLIB_VERSION_MINOR "")
set(HTSLIB_VERSION_PATCH "")
endif()
# Set canonical variables
set(HTSLIB_MAJOR_VERSION "${HTSLIB_VERSION_MAJOR}")
set(HTSLIB_MINOR_VERSION "${HTSLIB_VERSION_MINOR}")
set(HTSLIB_PATCH_VERSION "${HTSLIB_VERSION_PATCH}")
# Build the standard version string
set(HTSLIB_VERSION "${HTSLIB_VERSION_MAJOR}.${HTSLIB_VERSION_MINOR}")
# Only append patch if it's not "00"
if(NOT HTSLIB_VERSION_PATCH STREQUAL "00")
set(HTSLIB_VERSION "${HTSLIB_VERSION}.${HTSLIB_VERSION_PATCH}")
endif()
endif()

include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(
HTSLIB
REQUIRED_VARS
HTSLIB_LIBRARY
HTSLIB_INCLUDE_DIR
VERSION_VAR
HTSLIB_VERSION
HANDLE_COMPONENTS
)

if(HTSLIB_FOUND)
set(HTSLIB_INCLUDE_DIRS ${HTSLIB_INCLUDE_DIR})
if(NOT HTSLIB_LIBRARIES)
set(HTSLIB_LIBRARIES ${HTSLIB_LIBRARY})
endif()
if(NOT TARGET HTSLIB::HTSLIB)
add_library(HTSLIB::HTSLIB UNKNOWN IMPORTED)
set_target_properties(HTSLIB::HTSLIB PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${HTSLIB_INCLUDE_DIRS}")
if(HTSLIB_LIBRARY_RELEASE)
set_property(TARGET HTSLIB::HTSLIB APPEND PROPERTY
IMPORTED_CONFIGURATIONS RELEASE)
set_target_properties(HTSLIB::HTSLIB PROPERTIES
IMPORTED_LOCATION_RELEASE "${HTSLIB_LIBRARY_RELEASE}")
endif()
if(HTSLIB_LIBRARY_DEBUG)
set_property(TARGET HTSLIB::HTSLIB APPEND PROPERTY
IMPORTED_CONFIGURATIONS DEBUG)
set_target_properties(HTSLIB::HTSLIB PROPERTIES
IMPORTED_LOCATION_DEBUG "${HTSLIB_LIBRARY_DEBUG}")
endif()
if(NOT HTSLIB_LIBRARY_RELEASE AND NOT HTSLIB_LIBRARY_DEBUG)
set_property(TARGET HTSLIB::HTSLIB APPEND PROPERTY
IMPORTED_LOCATION "${HTSLIB_LIBRARY}")
endif()
endif()
endif()

cmake_policy(POP)
4 changes: 4 additions & 0 deletions src/AbismalAlign.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,22 @@ typedef std::vector<std::uint32_t> bam_cigar_t;
static inline score_t
count_deletions(const bam_cigar_t &cigar) {
score_t ans = 0;
// cppcheck-suppress-begin useStlAlgorithm
for (const auto &x : cigar)
if (abismal_bam_cigar_op(x) == ABISMAL_BAM_CDEL)
ans += abismal_bam_cigar_oplen(x);
// cppcheck-suppress-end useStlAlgorithm
return ans;
}

static inline score_t
count_insertions(const bam_cigar_t &cigar) {
score_t ans = 0;
// cppcheck-suppress-begin useStlAlgorithm
for (const auto &x : cigar)
if (abismal_bam_cigar_op(x) == ABISMAL_BAM_CINS)
ans += abismal_bam_cigar_oplen(x);
// cppcheck-suppress-end useStlAlgorithm
return ans;
}

Expand Down
Loading
Loading