source: trunk/m4/yat_check_libbam.m4

Last change on this file was 3885, checked in by Peter, 15 months ago

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

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Date
File size: 5.4 KB
Line 
1## $Id: yat_check_libbam.m4 3885 2020-03-25 03:06:46Z peter $
2#
3# serial 11 (yat 0.18)
4#
5#
6#   Copyright (C) 2012, 2013, 2014, 2015, 2018, 2020 Peter Johansson
7#
8#   This file is part of the yat library, http://dev.thep.lu.se/yat
9#
10#   The yat library is free software; you can redistribute it and/or
11#   modify it under the terms of the GNU General Public License as
12#   published by the Free Software Foundation; either version 3 of the
13#   License, or (at your option) any later version.
14#
15#   The yat library is distributed in the hope that it will be useful,
16#   but WITHOUT ANY WARRANTY; without even the implied warranty of
17#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18#   General Public License for more details.
19#
20#   You should have received a copy of the GNU General Public License
21#   along with yat. If not, see <http://www.gnu.org/licenses/>.
22
23
24## Macros in the file are deprecated
25
26
27# YAT_CHECK_BAM([action-if-found], [action-if-not-found])
28# =======================================================
29# Check if header and lib is available for old samtools API 0.1.x
30AC_DEFUN([YAT_CHECK_BAM],
31[
32  YAT_HEADER_BAM([YAT_LIB_BAM([$1], [$2])],
33                 [$2])
34])
35
36
37# YAT_HEADER_BAM([action-if-found], [action-if-not-found])
38# ==============================================================
39# Check how to include bam.h
40AC_DEFUN([YAT_HEADER_BAM],
41[
42  YAT_CHECK_HEADERS([bam.h bam/bam.h samtools/bam.h], [$1], [$2])
43]) # YAT_HEADER_BAM
44
45
46# YAT_LIB_BAM([action-if-found], [action-if-not-found])
47# ==========================================================
48#
49AC_DEFUN([YAT_LIB_BAM],
50[
51BAM_LIBS=no
52AC_MSG_CHECKING([for library containing bam_header_destroy])
53for libs in "" "-lbam" "-lbam -lpthread"; do
54  AS_IF([test x"$BAM_LIBS" = x"no"], [
55    YAT_LINK_BAM_IFELSE([$libs], [BAM_LIBS=$libs])
56  ])
57done
58AS_IF([test x"$BAM_LIBS" = x""], [
59  AC_MSG_RESULT([none required])
60],[
61  AC_MSG_RESULT([$BAM_LIBS])
62])
63AS_IF([test x"$BAM_LIBS" = xno], [$2], [$1])
64]) # YAT_LIB_BAM
65
66
67
68# YAT_LINK_BAM_IFELSE([lib], [action-if-found], [action-if-not-found])
69# ====================================================================
70# Add lib to LIBS and try to link some code using libbam
71AC_DEFUN([YAT_LINK_BAM_IFELSE],
72[
73save_LIBS=$LIBS
74LIBS="$1 $LIBS"
75AC_LINK_IFELSE([AC_LANG_PROGRAM([_YAT_BAM_INCLUDES],
76                                [
77                                 bam_header_t* hdr = bam_header_init();
78                                 bam_header_destroy(hdr);
79                                ])],
80               [$2], [$3])
81LIBS=$save_LIBS
82]) # YAT_LINK_BAM_IFELSE
83
84
85# YAT_BAM_NT16_REV_TABLE
86# ====================================================================
87# Check if global variable bam_nt16_rev_table is available in
88# -lbam. If found call AC_DEFINE(HAVE_BAM_NT16_REV_TABLE).
89AC_DEFUN([YAT_BAM_NT16_REV_TABLE],
90[
91AC_MSG_CHECKING([for bam_nt16_rev_table])
92AC_LINK_IFELSE([AC_LANG_PROGRAM([_YAT_BAM_INCLUDES],
93                  [char c = bam_nt16_rev_table@<:@7@:>@;])
94               ],[
95                 AC_MSG_RESULT([yes])
96                 AC_DEFINE([HAVE_BAM_NT16_REV_TABLE], [1],
97                           [Define to 1 if libbam contains bam_nt16_rev_table])
98               ],[
99                 AC_MSG_RESULT([no])
100               ])
101]) # YAT_BAM_NT16_REV_TABLE
102
103
104# YAT_FUNC_BAM_CALEND(SAM_FILE)
105# ===================
106# Check if there is a bam_calend that works
107AC_DEFUN([YAT_FUNC_BAM_CALEND],
108[
109  AC_CACHE_CHECK([for working bam_calend],
110    [yat_cv_func_bam_calend],
111    [AC_RUN_IFELSE(
112       [AC_LANG_PROGRAM(
113          [_YAT_BAM_INCLUDES],
114          [
115          samfile_t* samfile = samopen("$1", "r", NULL);
116          if (!samfile)
117            return 1;
118          bam1_t* read = bam_init1();
119          while (samread(samfile, read) >= -1) {
120            bool have_match = false;
121            if (read->core.n_cigar < 1)
122              continue;
123            uint32_t end = bam_calend(&read->core, bam1_cigar(read));
124            // replace BAM_CMATCH with BAM_CEQUAL in cigar
125            for (size_t k=0; k<read->core.n_cigar; ++k) {
126              uint32_t& element = bam1_cigar(read)@<:@k@:>@;
127              uint32_t op = element & BAM_CIGAR_MASK;
128              if (op == BAM_CMATCH) {
129                have_match = true;
130                uint32_t oplen = element >> BAM_CIGAR_SHIFT;
131                element = oplen<<BAM_CIGAR_SHIFT|BAM_CEQUAL;
132              }
133            }
134            // if no match element found, next read please
135            if (!have_match)
136              continue;
137            // bam_calend works on BAM_CEQUAL
138            if (bam_calend(&read->core, bam1_cigar(read)) == end)
139              return 0;
140            // bam_calend is not working as expected
141            return 2;
142          }
143          // end of data, fail
144          return 3;
145          ])
146       ],
147       [yat_cv_func_bam_calend=yes],
148       [yat_cv_func_bam_calend=no],
149       [yat_cv_func_bam_calend="guessing no"])
150    ])
151  AS_IF([test x"$yat_cv_func_bam_calend" = x"yes"],[
152    AC_DEFINE([HAVE_BAM_CALEND], [1], [Define to 1 if bam_calend is working])
153  ])
154])
155
156
157# _YAT_BAM_INCLUDES
158# =================
159# Private macro that expand PP magic we see in 'yat/omic/bam_config.h'
160AC_DEFUN([_YAT_BAM_INCLUDES],
161[
162@%:@if YAT_HAVE_HTS_H
163@%:@ include <sam.h>
164@%:@elif YAT_HAVE_HTSLIB_HTS_H
165@%:@ include <htslib/sam.h>
166@%:@elif YAT_HAVE_BAM_H
167@%:@ include <sam.h>
168@%:@ include <bam.h>
169@%:@elif YAT_HAVE_BAM_BAM_H
170@%:@ include <bam/bam.h>
171@%:@ include <bam/sam.h>
172@%:@elif YAT_HAVE_SAMTOOLS_BAM_H
173@%:@ include <samtools/bam.h>
174@%:@ include <samtools/sam.h>
175@%:@endif
176]) # _YAT_BAM_HEADER
Note: See TracBrowser for help on using the repository browser.