Changeset 3303


Ignore:
Timestamp:
Aug 21, 2014, 5:55:50 AM (9 years ago)
Author:
Peter
Message:

New macro YAT_FUNC_BAM_CALEND, which checks if function bam_calend is
buggy. If the function works as expected, HAVE_BAM_CALEND is
AC_DEFINEd so bam_calend is used. Closes #810.

Location:
branches/0.12-stable
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/0.12-stable/configure.ac

    r3293 r3303  
    383383  # check if global variable bam_nt16_rev_table is available
    384384  YAT_BAM_NT16_REV_TABLE
     385  # check if function bam_calend works. Result of this test can be
     386  # overridden by setting variable 'yat_cv_func_bam_calend'
     387  YAT_FUNC_BAM_CALEND([$srcdir/test/data/foo.sam])
    385388  AC_PATH_PROG([SAMTOOLS], [samtools], [false])
    386389  AC_ARG_VAR([SAMTOOLS], [Tools for alignment in the SAM format])
  • branches/0.12-stable/m4/yat_check_libbam.m4

    r3130 r3303  
    11## $Id$
    22#
    3 # serial 4 (yat 0.11)
     3# serial 5 (yat 0.12.1)
    44#
    55#
    6 #   Copyright (C) 2012, 2013 Peter Johansson
     6#   Copyright (C) 2012, 2013, 2014 Peter Johansson
    77#
    88#   This file is part of the yat library, http://dev.thep.lu.se/yat
     
    107107
    108108
     109# YAT_FUNC_BAM_CALEND(SAM_FILE)
     110# ===================
     111# Check if there is a bam_calend that works
     112AC_DEFUN([YAT_FUNC_BAM_CALEND],
     113[
     114  AC_CACHE_CHECK([for working bam_calend],
     115    [yat_cv_func_bam_calend],
     116    [AC_RUN_IFELSE(
     117       [AC_LANG_PROGRAM(
     118          [_YAT_BAM_INCLUDES],
     119          [
     120          samfile_t* samfile = samopen("$1", "r", NULL);
     121          if (!samfile)
     122            return 1;
     123          bam1_t* read = bam_init1();
     124          while (samread(samfile, read) >= -1) {
     125            bool have_match = false;
     126            if (read->core.n_cigar < 1)
     127              continue;
     128            uint32_t end = bam_calend(&read->core, bam1_cigar(read));
     129            // replace BAM_CMATCH with BAM_CEQUAL in cigar
     130            for (size_t k=0; k<read->core.n_cigar; ++k) {
     131              uint32_t& element = bam1_cigar(read)@<:@k@:>@;
     132              uint32_t op = element & BAM_CIGAR_MASK;
     133              if (op == BAM_CMATCH) {
     134                have_match = true;
     135                uint32_t oplen = element >> BAM_CIGAR_SHIFT;
     136                element = oplen<<BAM_CIGAR_SHIFT|BAM_CEQUAL;
     137              }
     138            }
     139            // if no match element found, next read please
     140            if (!have_match)
     141              continue;
     142            // bam_calend works on BAM_CEQUAL
     143            if (bam_calend(&read->core, bam1_cigar(read)) == end)
     144              return 0;
     145            // bam_calend is not working as expected
     146            return 2;
     147          }
     148          // end of data, fail
     149          return 3;
     150          ])
     151       ],
     152       [yat_cv_func_bam_calend=yes],
     153       [yat_cv_func_bam_calend=no],
     154       [yat_cv_func_bam_calend="guessing no"])
     155    ])
     156  AS_IF([test x"$yat_cv_func_bam_calend" = x"yes"],[
     157    AC_DEFINE([HAVE_BAM_CALEND], [1], [Define to 1 if bam_calend is working])
     158  ])
     159])
     160
     161
    109162# _YAT_BAM_INCLUDES
    110163# =================
     
    114167@%:@if YAT_HAVE_BAM_H
    115168@%:@ include <bam.h>
     169@%:@ include <sam.h>
    116170@%:@elif YAT_HAVE_BAM_BAM_H
    117171@%:@ include <bam/bam.h>
     172@%:@ include <bam/sam.h>
    118173@%:@elif YAT_HAVE_SAMTOOLS_BAM_H
    119174@%:@ include <samtools/bam.h>
     175@%:@ include <samtools/sam.h>
    120176@%:@endif
    121177]) # _YAT_BAM_HEADER
Note: See TracChangeset for help on using the changeset viewer.