Changeset 3306


Ignore:
Timestamp:
Aug 21, 2014, 6:37:21 AM (9 years ago)
Author:
Peter
Message:

merge ptach release 0.12.1 into trunk

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/NEWS

    r3295 r3306  
    1212
    1313yat 0.12.x series from http://dev.thep.lu.se/yat/svn/branches/0.12-stable
     14
     15version 0.12.1 (released 21 August 2014)
     16  - bam_calend is buggy in older versions of samtools; configure
     17    script checks that bam_calend works as expected; if not use its
     18    own implementation (see bug #810)
     19
     20  A complete list of closed tickets can be found here [[br]]
     21  http://dev.thep.lu.se/yat/query?status=closed&milestone=yat+0.12.1
    1422
    1523version 0.12 (released 25 July 2014)
  • trunk/configure.ac

    r3295 r3306  
    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])
  • trunk/m4/version.m4

    r3220 r3306  
    7777# yat-0.11.2 8:2:0
    7878# yat-0.12   9:0:0
     79# yat-0.12.1 9:1:0
    7980#
    8081# *Accidently, the libtool number was not updated for yat 0.5
  • trunk/m4/yat_check_libbam.m4

    r3130 r3306  
    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
  • trunk/test/bam.cc

    r3295 r3306  
    120120
    121121
     122void test_end(test::Suite& suite, BamRead bam)
     123{
     124  suite.out() << "test end:\n";
     125  suite.out() << bam.pos() << "-" << bam.end() << " " << bam.cigar_str()
     126              << "\n";
     127  uint32_t end = bam.end();
     128  if (!suite.add(end==24093)) {
     129    suite.err() << "error: incorrect end: " << end << "\n";
     130  }
     131
     132  // change the cigar to include a DIFF and EQUAL
     133  utility::Aligner::Cigar cig;
     134  cig.push_back(BAM_CEQUAL, 55);
     135  cig.push_back(BAM_CDIFF, 1);
     136  cig.push_back(BAM_CEQUAL, 44);
     137  bam.cigar(cig);
     138  suite.out() << bam.pos() << "-" << bam.end() << " " << bam.cigar_str()
     139              << "\n";
     140  end = bam.end();
     141  if (!suite.add(end==24093)) {
     142    suite.err() << "error: incorrect end: " << end << "\n";
     143  }
     144}
     145
     146
    122147void test_sequence(test::Suite& suite, const BamRead& b)
    123148{
     
    234259  in.read(bam);
    235260  // test that functions are implemented
    236   bam.end();
     261  test_end(suite, bam);
    237262  bam.flag();
    238263  bam.mpos();
  • trunk/yat/omic/BamRead.cc

    r3295 r3306  
    107107    assert(bam_);
    108108    return bam_->l_aux;
     109  }
     110
     111
     112  uint32_t BamRead::calend(const bam1_core_t *c, const uint32_t *cigar) const
     113  {
     114#ifdef HAVE_BAM_CALEND
     115    return bam_calend(&core(), bam1_cigar(bam_));
     116#endif
     117    int k, end = c->pos;
     118    for (k = 0; k < c->n_cigar; ++k) {
     119      int op  = bam_cigar_op(cigar[k]);
     120      int len = bam_cigar_oplen(cigar[k]);
     121      if (op == BAM_CBACK) { // move backward
     122        int l, u, v;
     123        if (k == c->n_cigar - 1) break; // skip trailing 'B'
     124        for (l = k - 1, u = v = 0; l >= 0; --l) {
     125          int op1  = bam_cigar_op(cigar[l]);
     126          int len1 = bam_cigar_oplen(cigar[l]);
     127          if (bam_cigar_type(op1)&1) { // consume query
     128            if (u + len1 >= len) { // stop
     129              if (bam_cigar_type(op1)&2) v += len - u;
     130              break;
     131            } else u += len1;
     132          }
     133          if (bam_cigar_type(op1)&2) v += len1;
     134        }
     135        end = l < 0? c->pos : end - v;
     136      } else if (bam_cigar_type(op)&2) end += bam_cigar_oplen(cigar[k]);
     137    }
     138    return end;
    109139  }
    110140
     
    186216  bam1_core_t& BamRead::core(void)
    187217  { return bam_->core; }
     218
     219
     220  int32_t BamRead::end(void) const
     221  {
     222    assert(bam_);
     223    return this->calend(&core(), bam1_cigar(bam_));
     224  }
    188225
    189226
     
    328365
    329366
    330   int32_t BamRead::end(void) const
    331   {
    332     assert(bam_);
    333     return bam_calend(&core(), bam1_cigar(bam_));
    334   }
    335 
    336 
    337367  void BamRead::swap(BamRead& other)
    338368  {
  • trunk/yat/omic/BamRead.h

    r3295 r3306  
    309309    friend class OutBamFile;
    310310    friend class BamReadIterator;
     311    uint32_t calend(const bam1_core_t *c, const uint32_t *cigar) const;
    311312  };
    312313
  • trunk/yat/utility/Cigar.h

    r3213 r3306  
    5656/// \abstract CIGAR: X = mismatch
    5757#define BAM_CDIFF       8
    58 #define BAM_CBACK       9
    5958#endif // end of YAT_HAVE_LIBBAM
     59
     60// BAM_CBACK is not defined in old versions of bam.h
     61#ifndef BAM_CBACK
     62#define BAM_CBACK 9
     63#endif
    6064
    6165// backport #defines from samtools 0.1.19
Note: See TracChangeset for help on using the changeset viewer.