source: trunk/m4/yat_check_htslib.m4

Last change on this file was 4003, checked in by Peter, 8 months ago

Add a constructor Aligner::Cigar(string) (closes #962)

Add a function cigar_table, which is a wrapper around bam_cigar_table
from htslib, translating operation characters in a CIGAR such as 'M'
or 'I' into the value as they are stored in a Cigar object (or a bam
entry). Function, bam_cigar_table, not available in older versions of
htslib or when building --without-htslib, so implement our own version
and decide at configure time whether using homebrew or call htslib.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Date
File size: 7.1 KB
Line 
1## $Id: yat_check_htslib.m4 4003 2020-10-15 02:00:02Z peter $
2#
3# serial 8 (yat 0.19)
4#
5#   Copyright (C) 2016, 2018, 2020 Peter Johansson
6#
7#   This file is part of the yat library, http://dev.thep.lu.se/yat
8#
9#   The yat library is free software; you can redistribute it and/or
10#   modify it under the terms of the GNU General Public License as
11#   published by the Free Software Foundation; either version 3 of the
12#   License, or (at your option) any later version.
13#
14#   The yat library is distributed in the hope that it will be useful,
15#   but WITHOUT ANY WARRANTY; without even the implied warranty of
16#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17#   General Public License for more details.
18#
19#   You should have received a copy of the GNU General Public License
20#   along with yat. If not, see <http://www.gnu.org/licenses/>.
21
22# YAT_CHECK_HTSLIB
23# ===================
24# This is a wrapper macro primarily written for yat. For other
25# packages the sub-macros called within here and defined below are
26# probably more useful.
27#
28# This macro adds a configure option --without-htslib. If option is
29# not provided checks for zlib header and lib are performed, checks
30# for htslib headers and lib are performed.
31
32# In addition, checks if a samtools program is available and whether
33# 'samtools --version' and 'samtools fasta' are available and
34# propagate the results with AM_CONDITIONAL, AC_SUBST and
35# AC_DEFINE. Similarly checks if bcftools program is available.
36AC_DEFUN([YAT_CHECK_HTSLIB],
37[
38# HTSLIB API available from http://www.htslib.org/
39AC_ARG_WITH([htslib],
40            [AS_HELP_STRING([--without-htslib], [disable htslib support])],
41            [],
42            [with_htslib=yes])
43
44AS_IF([test x"$with_htslib" != x"no"], [
45  _YAT_CHECK_ZLIB
46  _YAT_CHECK_HTSLIB
47  YAT_VAR_BAM_CIGAR_TABLE([
48    AC_DEFINE([HAVE_BAM_CIGAR_TABLE], [1],
49              [Define to 1 if bam_cigar_table is available])
50  ])
51])
52_YAT_PROG_SAMTOOLS
53_YAT_PROG_BCFTOOLS
54
55# propagate some results to 'Makefile' and 'config.h'
56AM_CONDITIONAL([HAVE_HTSLIB], [test x"$with_htslib" = x"yes"])
57AC_SUBST([have_htslib], [$with_htslib])
58AM_CONDITIONAL([HAVE_SAMTOOLS_EXECUTABLE], [test x"$SAMTOOLS" != x"false"])
59AC_SUBST([SAMTOOLS])
60AS_IF([test x"$SAMTOOLS" = x"false"], [], [
61  AC_DEFINE([HAVE_SAMTOOLS_EXECUTABLE], [1],
62            [Define if samtools executable is available])
63])
64AM_CONDITIONAL([HAVE_SAMTOOLS_FASTA_EXECUTABLE],
65               [test x"$yat_cv_samtools_fasta" = x"ok"])
66AS_IF([test x"$yat_cv_samtools_fasta" = x"ok"], [
67  AC_DEFINE([HAVE_SAMTOOLS_FASTA_EXECUTABLE], [1],
68            [Define if samtools fasta is available])
69])
70
71AM_CONDITIONAL([HAVE_BCFTOOLS_EXECUTABLE], [test x"$BCFTOOLS" != x"false"])
72AC_SUBST([BCFTOOLS])
73AS_IF([test x"$BCFTOOLS" = x"false"], [], [
74  AC_DEFINE([HAVE_BCFTOOLS_EXECUTABLE], [1],
75            [Define if bcftools executable is available])
76])
77
78]) # YAT_CHECK_HTSLIB
79
80
81# YAT_CHECK_HTS([action-if-found], [action-if-not-found])
82# =====================
83# if header <htslib/hts.h> and libhts exist execute action-if-found,
84# otherwise execute action-if-not-found
85AC_DEFUN([YAT_CHECK_HTS],
86[
87  YAT_HEADER_HTS([YAT_LIB_HTS([$1], [$2])],
88                 [$2])
89])
90
91
92# YAT_HEADER_HTS([action-if-found], [action-if-not-found])
93# =====================
94# Check if header 'htslib/hts.h' is available. If available execute
95# action-if-found; otherwise execute action-if-not-found
96AC_DEFUN([YAT_HEADER_HTS],
97[
98  YAT_CHECK_HEADERS([htslib/hts.h], [$1], [$2])
99]) # YAT_HEADER_HTS
100
101
102# YAT_LIB_HTS([action-if-found], [action-if-not-found])
103# =====================
104# Check if function 'hts_version()' is available. First try linking
105# against LIBS only, if hts_version() not found, try linking against
106# -lhts as well. If hts_version() is found, execute
107# action-if-not-found; otherwise execute action-if-not-found.
108AC_DEFUN([YAT_LIB_HTS],
109[
110HTS_LIBS=no
111YAT_SEARCH_LIBS([hts_version], [hts],
112                [HTS_LIBS=$yat_cv_search_hts_version
113                 $1],
114                [$2])
115]) # YAT_LIB_HTS
116
117
118# YAT_VAR_BAM_CIGAR_TABLE([action-if-found], [action-if-not-found])
119# =====================
120# Check if variable bam_cigar_table is available.
121AC_DEFUN([YAT_VAR_BAM_CIGAR_TABLE],
122[
123  AC_CACHE_CHECK([if bam_cigar_table is available],
124    [yat_cv_var_bam_cigar_table],
125    [AC_COMPILE_IFELSE([
126        AC_LANG_PROGRAM([@%:@include <htslib/sam.h>],
127                        [int8_t x = bam_cigar_table@<:@0@:>@;])
128      ], [
129        yat_cv_var_bam_cigar_table=yes
130      ], [
131        yat_cv_var_bam_cigar_table=no
132      ])
133    ])
134  AS_VAR_IF([yat_cv_var_bam_cigar_table], [yes], [$1], [$2])
135])
136
137
138### Private macros ###
139
140AC_DEFUN([_YAT_CHECK_HTSLIB],
141[
142  # Check if htslib is available.
143  YAT_CHECK_HTS([
144    AC_DEFINE([YAT_HAVE_HTSLIB], [1], [Define to 1 if htslib is available])
145    LIBS="$HTS_LIBS $LIBS"
146    have_hts=yes;
147  ],[
148    AC_MSG_FAILURE([htslib was not found])
149  ])
150
151  YAT_CHECK_LA_LIBS([
152    @%:@ include <htslib/sam.h>
153    void my_func(void) { hts_version(); }
154  ], [$HTS_LIBS $LIBZ $user_LIBS], [$HTS_LIBS], [YAT_STATIC_LIBS])
155])
156
157
158# _YAT_CHECK_ZLIB
159AC_DEFUN([_YAT_CHECK_ZLIB],
160[
161  AC_CHECK_HEADER([zlib.h], [],
162    [AC_MSG_FAILURE([header file 'zlib.h' was not found])])
163  YAT_SEARCH_LIBS([inflateEnd], [z],
164    [LIBZ=$yat_cv_search_inflateEnd
165     LIBS="$LIBZ $LIBS"],
166    [AC_MSG_FAILURE([library 'libz' was not found])])
167
168  YAT_CHECK_LA_LIBS([
169    @%:@include <zlib.h>
170    int my_func(void)
171    { z_streamp zs; inflateEnd(zs); return 0; }
172  ], [$LIBZ $user_LIBS], [$LIBZ], [YAT_STATIC_LIBS])
173]) # _YAT_CHECK_ZLIB
174
175
176# sets shell variables 'SAMTOOLS' and 'have_samtools_fasta'
177AC_DEFUN([_YAT_PROG_SAMTOOLS],
178[
179  have_samtools_fasta=no
180  AC_PATH_PROG([SAMTOOLS], [samtools], [false])
181  # check that found samtools is modern i.e. has --version (introduced in 1.2).
182  AS_IF([test x"$SAMTOOLS" != x"false"], [
183    _YAT_PROG_SAMTOOLS_VERSION([
184       # if samtools --version works, look for samtools fasta
185       _YAT_PROG_SAMTOOLS_FASTA([have_samtools_fasta=yes], [])
186    ], [
187       SAMTOOLS=false
188    ])
189  ])
190  AC_ARG_VAR([SAMTOOLS], [Tools for alignment in the SAM format])
191])
192
193
194# sets shell variables 'BCFTOOLS'
195AC_DEFUN([_YAT_PROG_BCFTOOLS],
196[
197  AC_PATH_PROG([BCFTOOLS], [bcftools], [false])
198  AC_ARG_VAR([BCFTOOLS], [Tools for manipulating VCFs])
199])
200
201
202# _YAT_PROG_SAMTOOLS_VERSION(ACTION-IF-FOUND, ACTION-IF-NOT-FOUND)
203AC_DEFUN([_YAT_PROG_SAMTOOLS_VERSION],
204[
205  AC_CACHE_CHECK([samtools --version],
206                 [yat_cv_samtools_version],
207                 [YAT_RUN_LOG([$SAMTOOLS --version],
208                              [yat_cv_samtools_version=ok],
209                              [yat_cv_samtools_version=no])
210                 ])
211  AS_IF([test x"$yat_cv_samtools_version" = x"ok"], [$1], [$2])
212]) # _YAT_PROG_SAMTOOLS_VERSION
213
214
215# _YAT_PROG_SAMTOOLS_FASTA(ACTION-IF-FOUND, ACTION-IF-NOT-FOUND)
216AC_DEFUN([_YAT_PROG_SAMTOOLS_FASTA],
217[
218  AC_CACHE_CHECK([samtools fasta],
219                 [yat_cv_samtools_fasta],
220                 [YAT_RUN_LOG([$SAMTOOLS fasta -1 conftest_1.fa \
221                               -2 conftest_2.fa $srcdir/test/data/foo.sam],
222                              [yat_cv_samtools_fasta=ok],
223                              [yat_cv_samtools_fasta=no])
224                 ])
225  AS_IF([test x"$yat_cv_samtools_fasta" = x"ok"], [$1], [$2])
226]) # _YAT_PROG_SAMTOOLS_FASTA
Note: See TracBrowser for help on using the repository browser.