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