Changeset 3415


Ignore:
Timestamp:
Apr 30, 2015, 9:36:46 AM (4 years ago)
Author:
Peter
Message:

refs #794

Change logic in configure test looking for libhts/samtools headers and
libraries. Instead of looking whether both headers and libraries are
available, first look for both and <htslib/hts.h> and libhts. If found
use that. If not found, look if both <bam.h> and libbam are
available. If yes, use them. If not abort.

Only test for function bam_calend and global variable
bam_nt16_rev_table when building against libbam as they are irrelevant
in htslib mode.

yat/utility/config_public.h.in: change back to macros
YAT_HAVE_BAM_H
YAT_HAVE_BAM_BAM_H
YAT_HAVE_SAMTOOLS_BAM_H
as they were called in 0.12. Add a new macro YAT_HAVE_HTSLIB_SAM_H,
which is defined when builiding against htslib (just like
YAT_HAVE_HTSLIB).

yat/omic/config_bam.h: use new macro names in
'yat/utility/config_public.h' and avoid having nested if statements
and instead use style:

#if defined YAT_HAVE_HTSLIB_HTS_H
# define YAT_SAM_HEADER "htslib/sam.h"
#elif defined YAT_HAVE_BAM_H
# define YAT_BAM_HEADER "bam.h"
# define YAT_SAM_HEADER "sam.h"
#elif defined YAT_HAVE_BAM_BAM_H
# define YAT_BAM_HEADER "bam/bam.h"
# define YAT_SAM_HEADER "bam/sam.h"
#endif

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/configure.ac

    r3413 r3415  
    371371  ], [$LIBZ $user_LIBS], [$LIBZ], [YAT_STATIC_LIBS])
    372372
    373   YAT_CHECK_HEADER_SAM([],[AC_MSG_FAILURE([header file 'sam.h' was not found])])
    374   # check if we have hts
    375   YAT_CHECK_HEADER_HTS([with_hts=yes;
    376                         AC_DEFINE([YAT_HAVE_HTSLIB],
    377                                   [1], [Define to 1 if HTS is available])],
    378                        [with_hts=no])
    379   AC_SUBST([HAVE_HTSLIB], [$with_hts])
    380   # try link against libhts or libbam
    381   YAT_CHECK_LIBBAM([LIBS="$BAM_LIBS $LIBS"
    382                     AC_DEFINE([YAT_HAVE_LIBBAM], [1],
    383                               [Define to 1 if libbam is available])],
    384     [AC_MSG_FAILURE([library 'libbam' was not found])])
     373  # Check if htslib is available. If no check if samtools API is available
     374  YAT_CHECK_HTS([
     375    AC_MSG_CHECKING([htslib])
     376    AC_MSG_RESULT([yes])
     377    AC_DEFINE([YAT_HAVE_HTSLIB], [1], [Define to 1 if HTS is available])
     378    LIBS="$BAM_LIBS $LIBS"
     379    have_hts=yes;
     380  ],[
     381    AC_MSG_CHECKING([htslib])
     382    AC_MSG_RESULT([no])
     383    have_hts=no;
     384    YAT_CHECK_BAM([
     385      AC_MSG_CHECKING([samtools API])
     386      AC_MSG_RESULT([yes])
     387      LIBS="$BAM_LIBS $LIBS"
     388      # check if function bam_calend works. Result of this test can be
     389      # overridden by setting variable 'yat_cv_func_bam_calend'
     390      YAT_FUNC_BAM_CALEND([$srcdir/test/data/foo.sam])
     391      # check if global variable bam_nt16_rev_table is available
     392      YAT_BAM_NT16_REV_TABLE
     393    ], [
     394      AC_MSG_CHECKING([samtools API])
     395      AC_MSG_RESULT([no])
     396      AC_MSG_FAILURE([neither htslib or samtools was found])
     397    ])
     398  ])
     399  AC_SUBST([HAVE_HTSLIB], [$have_hts])
     400
     401  AC_DEFINE([YAT_HAVE_LIBBAM], [1],
     402            [Define to 1 if yat is built with bam support])
     403
    385404  YAT_CHECK_LA_LIBS([
    386405    _YAT_BAM_INCLUDES
     
    391410    @%:@endif
    392411  ], [$BAM_LIBS $LIBZ $user_LIBS], [$BAM_LIBS], [YAT_STATIC_LIBS])
    393   # check if global variable bam_nt16_rev_table is available
    394   YAT_BAM_NT16_REV_TABLE
    395   # check if function bam_calend works. Result of this test can be
    396   # overridden by setting variable 'yat_cv_func_bam_calend'
    397   YAT_FUNC_BAM_CALEND([$srcdir/test/data/foo.sam])
     412
    398413  AC_PATH_PROG([SAMTOOLS], [samtools], [false])
    399414  AC_ARG_VAR([SAMTOOLS], [Tools for alignment in the SAM format])
     415
    400416], [
    401417  SAMTOOLS=false
  • trunk/m4/yat_check_libbam.m4

    r3350 r3415  
    11## $Id$
    22#
    3 # serial 6 (yat 0.13)
     3# serial 7 (yat 0.13)
    44#
    55#
     
    2121#   along with yat. If not, see <http://www.gnu.org/licenses/>.
    2222
    23 # YAT_CHECK_HEADER_SAM([action-if-found], [action-if-not-found])
     23
     24
     25# YAT_CHECK_HTS([action-if-found], [action-if-not-found])
     26# =====================
     27# if header and lib exist execute action-if-found, otherwise execute
     28# action-if-not-found
     29AC_DEFUN([YAT_CHECK_HTS],
     30[
     31  YAT_HEADER_HTS([YAT_LIB_HTS([$1], [$2])],
     32                 [$2])
     33])
     34
     35
     36# YAT_HEADER_HTS([action-if-found], [action-if-not-found])
     37# =====================
     38# Check if header hts.h is available
     39AC_DEFUN([YAT_HEADER_HTS],
     40[
     41  YAT_CHECK_HEADERS([htslib/hts.h], [$1], [$2])
     42]) # YAT_HEADER_HTS
     43
     44
     45# YAT_LIB_HTS([action-if-found], [action-if-not-found])
     46# =====================
     47# Check if bam_hdr_destroy is available
     48AC_DEFUN([YAT_LIB_HTS],
     49[
     50BAM_LIBS=no
     51AC_SEARCH_LIBS([bam_hdr_destroy], [hts],
     52               [AS_IF([test "$ac_cv_search_bam_hdr_destroy" != "none required"],
     53                      [BAM_LIBS=$ac_cv_search_bam_hdr_destroy])
     54                $1],
     55               [$2])
     56]) # YAT_LIB_HTS
     57
     58
     59# YAT_CHECK_BAM([action-if-found], [action-if-not-found])
     60# =======================================================
     61# Check if header and lib is available for old samtools API 0.1.x
     62AC_DEFUN([YAT_CHECK_BAM],
     63[
     64  YAT_HEADER_BAM([YAT_LIB_BAM([$1], [$2])],
     65                 [$2])
     66])
     67
     68
     69# YAT_HEADER_BAM([action-if-found], [action-if-not-found])
    2470# ==============================================================
    25 #
    26 AC_DEFUN([YAT_CHECK_HEADER_SAM],
    27 [
    28 yat_sam_header=no
    29 # check how to #include <sam.h>
    30 m4_foreach_w([myheader], [sam.h htslib/sam.h bam/sam.h samtools/sam.h],
    31              [_YAT_CHECK_HEADER_SAM(myheader)
    32 ])
    33 AS_IF([test x$yat_sam_header = xyes], [$1], [$2])
    34 ]) # YAT_CHECK_HEADER_SAM
    35 
    36 
    37 # _YAT_CHECK_HEADER_SAM
    38 # =====================
    39 # Private macro used in YAT_CHECK_HEADER_SAM
    40 AC_DEFUN([_YAT_CHECK_HEADER_SAM],
    41 [
    42 AS_IF([test x$yat_sam_header = xno], [dnl
     71# Check how to include bam.h
     72AC_DEFUN([YAT_HEADER_BAM],
     73[
     74  YAT_CHECK_HEADERS([bam.h bam/bam.h samtools/bam.h], [$1], [$2])
     75]) # YAT_HEADER_BAM
     76
     77
     78# YAT_CHECK_HEADERS(headers, [action-if-found], [action-if-not-found])
     79# ====================================================================
     80# Loop over headers (space-separated), check if header exist. If
     81# header exists, AC_DEFINE(YAT_HAVE_header) and execute shell command
     82# action-if-found. If none of headers is available, execute
     83# action-if-not-found.
     84AC_DEFUN([YAT_CHECK_HEADERS],
     85[
     86yat_check_headers_result=no
     87m4_foreach_w([myheader], [$1], [_YAT_CHECK_HEADERS(myheader)])
     88AS_IF([test x$yat_check_headers_result = xyes], [$2], [$3])
     89]) # YAT_CHECK_HEADERS
     90
     91
     92# _YAT_CHECK_HEADERS
     93# =====================
     94# Private macro used in YAT_CHECK_HEADERS
     95AC_DEFUN([_YAT_CHECK_HEADERS],
     96[
     97AS_IF([test x$yat_check_headers_result = xno], [dnl
    4398  AC_CHECK_HEADER([$1], [
    4499    AC_DEFINE_UNQUOTED(AS_TR_CPP([YAT_HAVE_$1]), [1],
    45100                       [Define to 1 if you have <$1> header file])
    46     yat_sam_header=yes;
     101    yat_check_headers_result=yes;
    47102  ])
    48103])
    49 ]) # _YAT_CHECK_HEADER_SAM
    50 
    51 
    52 # YAT_CHECK_HEADER_HTS([action-if-found], [action-if-not-found])
    53 # =====================
    54 # Check if header hts.h is available
    55 AC_DEFUN([YAT_CHECK_HEADER_HTS],
    56 [
    57 AC_CHECK_HEADER([hts.h], [$1],
    58   [AC_CHECK_HEADER([htslib/hts.h], [$1], [$2])])
    59 ]) # YAT_CHECK_HEADER_HTS
    60 
    61 
    62 # YAT_CHECK_LIBBAM([action-if-found], [action-if-not-found])
     104]) # _YAT_CHECK_HEADER_BAM
     105
     106
     107# YAT_LIB_BAM([action-if-found], [action-if-not-found])
    63108# ==========================================================
    64109#
    65 AC_DEFUN([YAT_CHECK_LIBBAM],
     110AC_DEFUN([YAT_LIB_BAM],
    66111[
    67112BAM_LIBS=no
    68 AC_MSG_CHECKING([for library containing bam_hdr_destroy])
    69 for libs in "" "-lhts" "-lbam" "-lbam -lpthread"; do
     113AC_MSG_CHECKING([for library containing bam_header_destroy])
     114for libs in "" "-lbam" "-lbam -lpthread"; do
    70115  AS_IF([test x"$BAM_LIBS" = x"no"], [
    71116    YAT_LINK_BAM_IFELSE([$libs], [BAM_LIBS=$libs])
     
    78123])
    79124AS_IF([test x"$BAM_LIBS" = xno], [$2], [$1])
    80 ]) # YAT_CHECK_LIBBAM
     125]) # YAT_LIB_BAM
    81126
    82127
     
    91136AC_LINK_IFELSE([AC_LANG_PROGRAM([_YAT_BAM_INCLUDES],
    92137                                [
    93                                  #if YAT_HAVE_HTSLIB
    94                                  bam_hdr_t* hdr = bam_hdr_init();
    95                                  bam_hdr_destroy(hdr);
    96                                  #else
    97138                                 bam_header_t* hdr = bam_header_init();
    98139                                 bam_header_destroy(hdr);
    99                                  #endif
    100140                                ])],
    101141               [$2], [$3])
    102142LIBS=$save_LIBS
    103143]) # YAT_LINK_BAM_IFELSE
     144
    104145
    105146# YAT_BAM_NT16_REV_TABLE
     
    179220# Private macro that expand PP magic we see in 'yat/omic/bam_config.h'
    180221AC_DEFUN([_YAT_BAM_INCLUDES],
    181 [AC_REQUIRE([YAT_CHECK_HEADER_SAM])
    182 @%:@if YAT_HAVE_SAM_H
     222[
     223@%:@if YAT_HAVE_HTS_H
    183224@%:@ include <sam.h>
    184 @%:@elif YAT_HAVE_HTSLIB_SAM_H
     225@%:@elif YAT_HAVE_HTSLIB_HTS_H
    185226@%:@ include <htslib/sam.h>
    186 @%:@elif YAT_HAVE_BAM_SAM_H
     227@%:@elif YAT_HAVE_BAM_H
     228@%:@ include <sam.h>
     229@%:@ include <bam.h>
     230@%:@elif YAT_HAVE_BAM_BAM_H
    187231@%:@ include <bam/bam.h>
    188232@%:@ include <bam/sam.h>
    189 @%:@elif YAT_HAVE_SAMTOOLS_SAM_H
     233@%:@elif YAT_HAVE_SAMTOOLS_BAM_H
    190234@%:@ include <samtools/bam.h>
    191235@%:@ include <samtools/sam.h>
  • trunk/yat/omic/config_bam.h

    r3360 r3415  
    3434#include "yat/utility/config_public.h"
    3535
    36 #ifdef YAT_HAVE_SAM_H
    37 # define YAT_BAM_HEADER "bam.h"
    38 # define YAT_SAM_HEADER "sam.h"
    39 #else
    40 # ifdef YAT_HAVE_HTSLIB_SAM_H
     36#if defined YAT_HAVE_HTSLIB_HTS_H
    4137#  define YAT_SAM_HEADER "htslib/sam.h"
    42 # else
    43 #  ifdef YAT_HAVE_BAM_SAM_H
    44 #   define YAT_BAM_HEADER "bam/bam.h"
    45 #   define YAT_SAM_HEADER "bam/sam.h"
    46 #  else
    47 #   ifdef YAT_HAVE_SAMTOOLS_SAM_H
    48 #    define YAT_BAM_HEADER "samtools/bam.h"
    49 #    define YAT_SAM_HEADER "samtools/sam.h"
    50 #   endif
    51 #  endif
    52 # endif
     38#elif defined YAT_HAVE_BAM_H
     39#  define YAT_BAM_HEADER "bam.h"
     40#  define YAT_SAM_HEADER "sam.h"
     41#elif defined YAT_HAVE_BAM_BAM_H
     42#  define YAT_BAM_HEADER "bam/bam.h"
     43#  define YAT_SAM_HEADER "bam/sam.h"
     44#elif defined YAT_HAVE_SAMTOOLS_BAM_H
     45#  define YAT_BAM_HEADER "samtools/bam.h"
     46#  define YAT_SAM_HEADER "samtools/sam.h"
    5347#endif
    5448
  • trunk/yat/utility/config_public.h.in

    r3350 r3415  
    2929
    3030
    31 /// Define to 1 if you have the <bam/sam.h> header file.
    32 #undef YAT_HAVE_BAM_SAM_H
     31/// Define to 1 if you have the <bam/bam.h> header file.
     32#undef YAT_HAVE_BAM_BAM_H
    3333
    34 /// Define to 1 if you have the <htslib/sam.h> header file.
    35 #undef YAT_HAVE_HTSLIB_SAM_H
    36 
    37 /// Define to 1 if you have the <sam.h> header file.
    38 #undef YAT_HAVE_SAM_H
    39 
    40 /// Define to 1 if you have the <samtools/sam.h> header file.
    41 #undef YAT_HAVE_SAMTOOLS_SAM_H
     34/// Define to 1 if you have the <bam.h> header file.
     35#undef YAT_HAVE_BAM_H
    4236
    4337/// Define to 1 if HTS is available
    4438#undef YAT_HAVE_HTSLIB
    4539
    46 /// Define to 1 if you have 'bam_header_t'
    47 #undef YAT_HAVE_BAM_HEADER_T
     40/// Define to 1 if you have the <htslib/hts.h> header file.
     41#undef YAT_HAVE_HTSLIB_HTS_H
    4842
    49 /// Define to 1 if libbam is available
     43/// Define to 1 if you have the <hts.h> header file.
     44#undef YAT_HAVE_HTS_H
     45
     46/// Define to 1 if yat is build with bam support
    5047#undef YAT_HAVE_LIBBAM
     48
     49/// Define to 1 if you have the <samtools/bam.h> header file.
     50#undef YAT_HAVE_SAMTOOLS_BAM_H
    5151
    5252/// Define if compiler supports deprecated attribute, as in g++ 4.0
     
    7373#undef YAT_DEV_BUILD
    7474
    75 // for backward compatibility
    76 
    77 #ifdef YAT_HAVE_SAM_H
    78 /// \deprecated defined for backward compatibility with 0.12 API
    79 #define YAT_HAVE_BAM_H YAT_HAVE_SAM_H
    8075#endif
    81 
    82 #ifdef YAT_HAVE_BAM_SAM_H
    83 /// \deprecated defined for backward compatibility with 0.12 API
    84 #define YAT_HAVE_BAM_BAM_H YAT_HAVE_BAM_SAM_H
    85 #endif
    86 
    87 #ifdef YAT_HAVE_SAMTOOLS_SAM_H
    88 /// \deprecated defined for backward compatibility with 0.12 API
    89 #define YAT_HAVE_SAMTOOLS_BAM_H YAT_HAVE_SAMTOOLS_SAM_H
    90 #endif
    91 
    92 #endif
Note: See TracChangeset for help on using the changeset viewer.