Changeset 3885


Ignore:
Timestamp:
Mar 25, 2020, 4:06:46 AM (2 months ago)
Author:
Peter
Message:

Lift out macro YAT_CHECK_HEADERS to its own file, yat_check_header.m4.

Move htslib-related macros to yat_check_htslib.m4

Deprecate all remaining macros in yat_check_libbam.m4

Location:
trunk/m4
Files:
2 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/m4/yat_check_headers.m4

    r3883 r3885  
    11## $Id$
    22#
    3 # serial 10 (yat 0.18)
     3# serial 11 (yat 0.18)
    44#
    55#
     
    2020#   You should have received a copy of the GNU General Public License
    2121#   along with yat. If not, see <http://www.gnu.org/licenses/>.
    22 
    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
    29 AC_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 htslib/hts.h is available
    39 AC_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 function 'hts_version()' is available
    48 AC_DEFUN([YAT_LIB_HTS],
    49 [
    50 HTS_LIBS=no
    51 YAT_SEARCH_LIBS([hts_version], [hts],
    52                 [HTS_LIBS=$yat_cv_search_hts_version
    53                  $1],
    54                 [$2])
    55 ]) # YAT_LIB_HTS
    56 
    57 
    58 # YAT_CHECK_BAM([action-if-found], [action-if-not-found])
    59 # =======================================================
    60 # Check if header and lib is available for old samtools API 0.1.x
    61 AC_DEFUN([YAT_CHECK_BAM],
    62 [
    63   YAT_HEADER_BAM([YAT_LIB_BAM([$1], [$2])],
    64                  [$2])
    65 ])
    66 
    67 
    68 # YAT_HEADER_BAM([action-if-found], [action-if-not-found])
    69 # ==============================================================
    70 # Check how to include bam.h
    71 AC_DEFUN([YAT_HEADER_BAM],
    72 [
    73   YAT_CHECK_HEADERS([bam.h bam/bam.h samtools/bam.h], [$1], [$2])
    74 ]) # YAT_HEADER_BAM
    7522
    7623
     
    10148  ])
    10249])
    103 ]) # _YAT_CHECK_HEADER_BAM
    104 
    105 
    106 # YAT_LIB_BAM([action-if-found], [action-if-not-found])
    107 # ==========================================================
    108 #
    109 AC_DEFUN([YAT_LIB_BAM],
    110 [
    111 BAM_LIBS=no
    112 AC_MSG_CHECKING([for library containing bam_header_destroy])
    113 for libs in "" "-lbam" "-lbam -lpthread"; do
    114   AS_IF([test x"$BAM_LIBS" = x"no"], [
    115     YAT_LINK_BAM_IFELSE([$libs], [BAM_LIBS=$libs])
    116   ])
    117 done
    118 AS_IF([test x"$BAM_LIBS" = x""], [
    119   AC_MSG_RESULT([none required])
    120 ],[
    121   AC_MSG_RESULT([$BAM_LIBS])
    122 ])
    123 AS_IF([test x"$BAM_LIBS" = xno], [$2], [$1])
    124 ]) # YAT_LIB_BAM
    125 
    126 
    127 
    128 # YAT_LINK_BAM_IFELSE([lib], [action-if-found], [action-if-not-found])
    129 # ====================================================================
    130 # Add lib to LIBS and try to link some code using libbam
    131 AC_DEFUN([YAT_LINK_BAM_IFELSE],
    132 [
    133 save_LIBS=$LIBS
    134 LIBS="$1 $LIBS"
    135 AC_LINK_IFELSE([AC_LANG_PROGRAM([_YAT_BAM_INCLUDES],
    136                                 [
    137                                  bam_header_t* hdr = bam_header_init();
    138                                  bam_header_destroy(hdr);
    139                                 ])],
    140                [$2], [$3])
    141 LIBS=$save_LIBS
    142 ]) # YAT_LINK_BAM_IFELSE
    143 
    144 
    145 # YAT_BAM_NT16_REV_TABLE
    146 # ====================================================================
    147 # Check if global variable bam_nt16_rev_table is available in
    148 # -lbam. If found call AC_DEFINE(HAVE_BAM_NT16_REV_TABLE).
    149 AC_DEFUN([YAT_BAM_NT16_REV_TABLE],
    150 [
    151 AC_MSG_CHECKING([for bam_nt16_rev_table])
    152 AC_LINK_IFELSE([AC_LANG_PROGRAM([_YAT_BAM_INCLUDES],
    153                   [char c = bam_nt16_rev_table@<:@7@:>@;])
    154                ],[
    155                  AC_MSG_RESULT([yes])
    156                  AC_DEFINE([HAVE_BAM_NT16_REV_TABLE], [1],
    157                            [Define to 1 if libbam contains bam_nt16_rev_table])
    158                ],[
    159                  AC_MSG_RESULT([no])
    160                ])
    161 ]) # YAT_BAM_NT16_REV_TABLE
    162 
    163 
    164 # YAT_FUNC_BAM_CALEND(SAM_FILE)
    165 # ===================
    166 # Check if there is a bam_calend that works
    167 AC_DEFUN([YAT_FUNC_BAM_CALEND],
    168 [
    169   AC_CACHE_CHECK([for working bam_calend],
    170     [yat_cv_func_bam_calend],
    171     [AC_RUN_IFELSE(
    172        [AC_LANG_PROGRAM(
    173           [_YAT_BAM_INCLUDES],
    174           [
    175           samfile_t* samfile = samopen("$1", "r", NULL);
    176           if (!samfile)
    177             return 1;
    178           bam1_t* read = bam_init1();
    179           while (samread(samfile, read) >= -1) {
    180             bool have_match = false;
    181             if (read->core.n_cigar < 1)
    182               continue;
    183             uint32_t end = bam_calend(&read->core, bam1_cigar(read));
    184             // replace BAM_CMATCH with BAM_CEQUAL in cigar
    185             for (size_t k=0; k<read->core.n_cigar; ++k) {
    186               uint32_t& element = bam1_cigar(read)@<:@k@:>@;
    187               uint32_t op = element & BAM_CIGAR_MASK;
    188               if (op == BAM_CMATCH) {
    189                 have_match = true;
    190                 uint32_t oplen = element >> BAM_CIGAR_SHIFT;
    191                 element = oplen<<BAM_CIGAR_SHIFT|BAM_CEQUAL;
    192               }
    193             }
    194             // if no match element found, next read please
    195             if (!have_match)
    196               continue;
    197             // bam_calend works on BAM_CEQUAL
    198             if (bam_calend(&read->core, bam1_cigar(read)) == end)
    199               return 0;
    200             // bam_calend is not working as expected
    201             return 2;
    202           }
    203           // end of data, fail
    204           return 3;
    205           ])
    206        ],
    207        [yat_cv_func_bam_calend=yes],
    208        [yat_cv_func_bam_calend=no],
    209        [yat_cv_func_bam_calend="guessing no"])
    210     ])
    211   AS_IF([test x"$yat_cv_func_bam_calend" = x"yes"],[
    212     AC_DEFINE([HAVE_BAM_CALEND], [1], [Define to 1 if bam_calend is working])
    213   ])
    214 ])
    215 
    216 
    217 # _YAT_BAM_INCLUDES
    218 # =================
    219 # Private macro that expand PP magic we see in 'yat/omic/bam_config.h'
    220 AC_DEFUN([_YAT_BAM_INCLUDES],
    221 [
    222 @%:@if YAT_HAVE_HTS_H
    223 @%:@ include <sam.h>
    224 @%:@elif YAT_HAVE_HTSLIB_HTS_H
    225 @%:@ include <htslib/sam.h>
    226 @%:@elif YAT_HAVE_BAM_H
    227 @%:@ include <sam.h>
    228 @%:@ include <bam.h>
    229 @%:@elif YAT_HAVE_BAM_BAM_H
    230 @%:@ include <bam/bam.h>
    231 @%:@ include <bam/sam.h>
    232 @%:@elif YAT_HAVE_SAMTOOLS_BAM_H
    233 @%:@ include <samtools/bam.h>
    234 @%:@ include <samtools/sam.h>
    235 @%:@endif
    236 ]) # _YAT_BAM_HEADER
     50]) # _YAT_CHECK_HEADERS
  • trunk/m4/yat_check_htslib.m4

    r3883 r3885  
    11## $Id$
    22#
    3 # serial 5 (yat 0.18)
     3# serial 6 (yat 0.18)
    44#
    55#   Copyright (C) 2016, 2018, 2020 Peter Johansson
     
    2020#   along with yat. If not, see <http://www.gnu.org/licenses/>.
    2121
    22 #
    23 #
    24 #
     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.
    2536AC_DEFUN([YAT_CHECK_HTSLIB],
    2637[
     
    6374
    6475]) # YAT_CHECK_HTSLIB
     76
     77
     78# YAT_CHECK_HTS([action-if-found], [action-if-not-found])
     79# =====================
     80# if header <htslib/hts.h> and libhts exist execute action-if-found,
     81# otherwise execute action-if-not-found
     82AC_DEFUN([YAT_CHECK_HTS],
     83[
     84  YAT_HEADER_HTS([YAT_LIB_HTS([$1], [$2])],
     85                 [$2])
     86])
     87
     88
     89# YAT_HEADER_HTS([action-if-found], [action-if-not-found])
     90# =====================
     91# Check if header 'htslib/hts.h' is available. If available execute
     92# action-if-found; otherwise execute action-if-not-found
     93AC_DEFUN([YAT_HEADER_HTS],
     94[
     95  YAT_CHECK_HEADERS([htslib/hts.h], [$1], [$2])
     96]) # YAT_HEADER_HTS
     97
     98
     99# YAT_LIB_HTS([action-if-found], [action-if-not-found])
     100# =====================
     101# Check if function 'hts_version()' is available. First try linking
     102# against LIBS only, if hts_version() not found, try linking against
     103# -lhts as well. If hts_version() is found, execute
     104# action-if-not-found; otherwise execute action-if-not-found.
     105AC_DEFUN([YAT_LIB_HTS],
     106[
     107HTS_LIBS=no
     108YAT_SEARCH_LIBS([hts_version], [hts],
     109                [HTS_LIBS=$yat_cv_search_hts_version
     110                 $1],
     111                [$2])
     112]) # YAT_LIB_HTS
    65113
    66114
     
    143191
    144192
    145 # _YAT_PROG_SAMTOOLS_VERSION(ACTION-IF-FOUND, ACTION-IF-NOT-FOUND)
     193# _YAT_PROG_SAMTOOLS_FASTA(ACTION-IF-FOUND, ACTION-IF-NOT-FOUND)
    146194AC_DEFUN([_YAT_PROG_SAMTOOLS_FASTA],
    147195[
  • trunk/m4/yat_check_libbam.m4

    r3883 r3885  
    11## $Id$
    22#
    3 # serial 10 (yat 0.18)
     3# serial 11 (yat 0.18)
    44#
    55#
     
    2222
    2323
    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
    29 AC_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 htslib/hts.h is available
    39 AC_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 function 'hts_version()' is available
    48 AC_DEFUN([YAT_LIB_HTS],
    49 [
    50 HTS_LIBS=no
    51 YAT_SEARCH_LIBS([hts_version], [hts],
    52                 [HTS_LIBS=$yat_cv_search_hts_version
    53                  $1],
    54                 [$2])
    55 ]) # YAT_LIB_HTS
     24## Macros in the file are deprecated
    5625
    5726
     
    7342  YAT_CHECK_HEADERS([bam.h bam/bam.h samtools/bam.h], [$1], [$2])
    7443]) # YAT_HEADER_BAM
    75 
    76 
    77 # YAT_CHECK_HEADERS(headers, [action-if-found], [action-if-not-found])
    78 # ====================================================================
    79 # Loop over headers (space-separated), check if header exist. If
    80 # header exists, AC_DEFINE(YAT_HAVE_header) and execute shell command
    81 # action-if-found. If none of headers is available, execute
    82 # action-if-not-found.
    83 AC_DEFUN([YAT_CHECK_HEADERS],
    84 [
    85 yat_check_headers_result=no
    86 m4_foreach_w([myheader], [$1], [_YAT_CHECK_HEADERS(myheader)])
    87 AS_IF([test x$yat_check_headers_result = xyes], [$2], [$3])
    88 ]) # YAT_CHECK_HEADERS
    89 
    90 
    91 # _YAT_CHECK_HEADERS
    92 # =====================
    93 # Private macro used in YAT_CHECK_HEADERS
    94 AC_DEFUN([_YAT_CHECK_HEADERS],
    95 [
    96 AS_IF([test x$yat_check_headers_result = xno], [dnl
    97   AC_CHECK_HEADER([$1], [
    98     AC_DEFINE_UNQUOTED(AS_TR_CPP([YAT_HAVE_$1]), [1],
    99                        [Define to 1 if you have <$1> header file])
    100     yat_check_headers_result=yes;
    101   ])
    102 ])
    103 ]) # _YAT_CHECK_HEADER_BAM
    10444
    10545
Note: See TracChangeset for help on using the changeset viewer.