Changeset 3883


Ignore:
Timestamp:
Mar 24, 2020, 11:08:54 AM (2 months ago)
Author:
Peter
Message:

remove support for building against libbam (which allows us to remove a lot of specialised code), closes #939.

Location:
trunk
Files:
1 added
34 edited

Legend:

Unmodified
Added
Removed
  • trunk/NEWS

    r3875 r3883  
    44
    55version 0.18 (released NOT YET)
     6  - Building against libbam is no longer supported (ticket #939)
     7  - configure option --withoyr-samtools is no longer supported; use
     8    --without-htslib
     9  - Autoconf macro YAT_CHECK_HTSLIB is no longer looking for libbam or
     10    header files from the samtools API (ticket #939)
     11  - protected function BamFile::open_base(3) is deprecated, ise open_base(2).
    612
    713  A complete list of closed tickets can be found here [[br]]
  • trunk/README

    r3823 r3883  
    126126=== HTSLIB and Samtools ===
    127127
    128 In order to enable functionality related to bam files, either htslib
    129 (http://www.htslib.org) or its predecessor samtools
    130 (http://samtools.sourceforge.net) must be available. Header file
    131 <sam.h> is required as well as either 'libhts' or 'libbam'. The configure
    132 script will try to detect whether <sam.h> is available as 'sam.h',
    133 'htslib/sam.h', 'bam/sam.h', or 'samtools/sam.h'. If you have header
    134 files installed outside compiler's search path, you can help the
    135 compiler with `./configure CPPFLAGS=-I<include dir>` when header files
    136 are found in directory `<include dir>`. Configure detects whether
    137 header files are from htslib or old samtools and looks for either
    138 libhts or libbam accordingly. If library is installed outside linker's
    139 search path, in `<libdir>`, you can run `./configure LDFLAGS=-L<lib
    140 dir>`. You can build yat without bam support by running `./configure
    141 --without-samtools`.
     128In order to enable functionality related to bam files htslib
     129(http://www.htslib.org) must be available. Header file <htslib/sam.h>
     130is required as well as 'libhts'. If you have header files installed
     131outside compiler's search path (in e.g. '/path/to/htslib/sam.h', you
     132can help the compiler with `./configure CPPFLAGS=-I/path/to`. If
     133library is installed outside linker's search path, in e.g. `<libdir>`,
     134you can run `./configure LDFLAGS=-L<lib dir>`. You can build yat
     135without bam support by running `./configure --without-htslib`.
    142136
    143137The samtools program (version 1.2 or newer) is needed for some tests
  • trunk/configure.ac

    r3823 r3883  
    534534  ])
    535535  AS_IF([test x"$suppress_long_long_warnings" = x"no"], [
    536     AC_MSG_CHECKING([whether samtools causes long long warnings])
    537     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([_YAT_BAM_INCLUDES],[])],
     536    AC_MSG_CHECKING([whether <htslib/sam.h> causes long long warnings])
     537    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([@%:@ include <htslib/sam.h>],[])],
    538538                      [AC_MSG_RESULT([no])],
    539539                      [AC_MSG_RESULT([yes])
     
    605605])
    606606
    607 # ignore this whole bam thing if --without-htslib
     607# ignore this whole htslib thing if --without-htslib
    608608AS_IF([test x$with_htslib != x"no"], [
    609609  # htslib comes with a pc file, so we can require htslib in yat.pc
    610   AS_IF([test x$have_hts = x"yes"], [
    611     YAT_VAR_REMOVE([YAT_PC_LIBS_PRIVATE], [$BAM_LIBS -lz])
    612     YAT_SET_CONTAINS([$yat_libyat_la_LIBADD], [-lhts], [
    613       YAT_PC_REQUIRES_PRIVATE="$YAT_PC_REQUIRES_PRIVATE htslib"
    614     ], [
    615       YAT_PC_REQUIRES="$YAT_PC_REQUIRES htslib"
    616     ])
    617   ],[
    618     # libbam has no pc file, so has to remain in LIBS and instead we
    619     # require zlib
    620     YAT_VAR_REMOVE([YAT_PC_LIBS_PRIVATE], [-lz])
    621     YAT_SET_CONTAINS([$yat_libyat_la_LIBADD], [-lz], [
    622       YAT_PC_REQUIRES_PRIVATE="$YAT_PC_REQUIRES_PRIVATE zlib"
    623     ], [
    624       YAT_PC_REQUIRES="$YAT_PC_REQUIRES zlib"
    625     ])
     610  YAT_VAR_REMOVE([YAT_PC_LIBS_PRIVATE], [$HTS_LIBS -lz])
     611  # if libyat is linking in -lhts, linking against libyat is
     612  # sufficient and put htslib in 'requires private:', otherwise put
     613  # them in 'require:'.
     614  YAT_SET_CONTAINS([$yat_libyat_la_LIBADD], [-lhts], [
     615    YAT_PC_REQUIRES_PRIVATE="$YAT_PC_REQUIRES_PRIVATE htslib"
     616  ], [
     617    YAT_PC_REQUIRES="$YAT_PC_REQUIRES htslib"
    626618  ])
    627619])
     
    700692  ATLAS (http://math-atlas.sourceforge.net/) provides an
    701693  optimized BLAS library. It is supported by yat!
    702 '
    703 ])
    704 
    705 yat_libbam_message=
    706 AS_IF([test x$with_htslib = x"yes" && test x"$have_hts" != x"yes"], [
    707 yat_libbam_message='
    708   LIBBAM found. Support for LIBBAM is deprecated and will be
    709   removed in future versions. It is recommended to install HTSLIB
    710   available from http://www.htslib.org
    711694'
    712695])
     
    740723  YAT_LIBS    = $YAT_LIBS
    741724${yat_gslcblas_message}dnl
    742 ${yat_libbam_message}dnl
    743725----------------------------------------------------------------
    744726Now type `make'. dnl
  • trunk/m4/yat_check_htslib.m4

    r3870 r3883  
    11## $Id$
    22#
    3 # serial 4 (yat 0.17)
     3# serial 5 (yat 0.18)
    44#
    55#   Copyright (C) 2016, 2018, 2020 Peter Johansson
     
    2525AC_DEFUN([YAT_CHECK_HTSLIB],
    2626[
    27 # samtools API from http://samtools.sourceforge.net
    28 AC_ARG_WITH([samtools],
    29             [AS_HELP_STRING([--without-samtools],
    30                             [disable samtools support (deprecated)])],
    31             [],
    32             [with_samtools=yes])
    33 
    3427# HTSLIB API available from http://www.htslib.org/
    3528AC_ARG_WITH([htslib],
    3629            [AS_HELP_STRING([--without-htslib], [disable htslib support])],
    3730            [],
    38             [with_htslib=$with_samtools])
     31            [with_htslib=yes])
    3932
    4033AS_IF([test x"$with_htslib" != x"no"], [
     
    7669AC_DEFUN([_YAT_CHECK_HTSLIB],
    7770[
    78   # Check if htslib is available. If not, check if samtools API is available
     71  # Check if htslib is available.
    7972  YAT_CHECK_HTS([
    80     AC_MSG_CHECKING([htslib])
    81     AC_MSG_RESULT([yes])
    82     AC_DEFINE([YAT_HAVE_HTSLIB], [1], [Define to 1 if HTS is available])
    83     LIBS="$BAM_LIBS $LIBS"
     73    AC_DEFINE([YAT_HAVE_HTSLIB], [1], [Define to 1 if htslib is available])
     74    LIBS="$HTS_LIBS $LIBS"
    8475    have_hts=yes;
    8576  ],[
    86     AC_MSG_CHECKING([htslib])
    87     AC_MSG_RESULT([no])
    88     have_hts=no;
    89     YAT_CHECK_BAM([
    90       AC_MSG_CHECKING([samtools API])
    91       AC_MSG_RESULT([yes])
    92       LIBS="$BAM_LIBS $LIBS"
    93       AC_MSG_WARN([support for libbam is deprecated; please use htslib.])
    94       # check if function bam_calend works. Result of this test can be
    95       # overridden by setting variable 'yat_cv_func_bam_calend'
    96       YAT_FUNC_BAM_CALEND([$srcdir/test/data/foo.sam])
    97       # check if global variable bam_nt16_rev_table is available
    98       YAT_BAM_NT16_REV_TABLE
    99     ], [
    100       AC_MSG_CHECKING([samtools API])
    101       AC_MSG_RESULT([no])
    102       AC_MSG_FAILURE([neither htslib or samtools was found])
    103     ])
     77    AC_MSG_FAILURE([htslib was not found])
    10478  ])
    10579  AC_SUBST([HAVE_HTSLIB], [$have_hts])
    10680
    107   AC_DEFINE([YAT_HAVE_LIBBAM], [1],
    108             [Define to 1 if yat is built with bam support])
    109 
    11081  YAT_CHECK_LA_LIBS([
    111     _YAT_BAM_INCLUDES
    112     @%:@if YAT_HAVE_HTSLIB
     82    @%:@ include <htslib/sam.h>
    11383    void my_func(void) { hts_version(); }
    114     @%:@else
    115     void my_func(bam_header_t* hdr) { bam_header_destroy(hdr); }
    116     @%:@endif
    117   ], [$BAM_LIBS $LIBZ $user_LIBS], [$BAM_LIBS], [YAT_STATIC_LIBS])
     84  ], [$HTS_LIBS $LIBZ $user_LIBS], [$HTS_LIBS], [YAT_STATIC_LIBS])
    11885])
    11986
     
    188155  AS_IF([test x"$yat_cv_samtools_fasta" = x"ok"], [$1], [$2])
    189156]) # _YAT_PROG_SAMTOOLS_FASTA
    190 
    191 #../test/data/foo.sam
  • trunk/m4/yat_check_libbam.m4

    r3882 r3883  
    3636# YAT_HEADER_HTS([action-if-found], [action-if-not-found])
    3737# =====================
    38 # Check if header hts.h is available
     38# Check if header htslib/hts.h is available
    3939AC_DEFUN([YAT_HEADER_HTS],
    4040[
     
    4848AC_DEFUN([YAT_LIB_HTS],
    4949[
    50 BAM_LIBS=no
     50HTS_LIBS=no
    5151YAT_SEARCH_LIBS([hts_version], [hts],
    52                [BAM_LIBS=$yat_cv_search_hts_version
    53                 $1],
    54                [$2])
     52                [HTS_LIBS=$yat_cv_search_hts_version
     53                 $1],
     54                [$2])
    5555]) # YAT_LIB_HTS
    5656
  • trunk/test/Makefile.am

    r3878 r3883  
    7878  test/kernel_pca.test test/kernel.test \
    7979  test/knn.test test/kolmogorov_smirnov.test test/large_file.test \
     80  test/libbam.test \
    8081  test/likelihood_ratio_test_binomial.test \
    8182  test/matrix_lookup.test \
  • trunk/test/Suite.cc

    r3855 r3883  
    4747  {
    4848    if (require_bam) {
    49 #ifndef YAT_HAVE_LIBBAM
     49#ifndef YAT_HAVE_HTSLIB
    5050      out() << "no bam support\n";
    5151      exit (EXIT_SKIP);
  • trunk/test/Suite.h

    r3878 r3883  
    3838
    3939// SKIP_BAM_TEST is defined if we should skip bam tests
    40 #if !defined (YAT_HAVE_LIBBAM) || !defined (HAVE_SAMTOOLS_EXECUTABLE)
     40#if !defined (YAT_HAVE_HTSLIB) || !defined (HAVE_SAMTOOLS_EXECUTABLE)
    4141#define SKIP_BAM_TEST
    4242#endif
  • trunk/test/bam.cc

    r3733 r3883  
    2020#include "Suite.h"
    2121
    22 #ifdef YAT_HAVE_LIBBAM
     22#ifdef YAT_HAVE_HTSLIB
    2323#include "yat/omic/BamFile.h"
    2424#include "yat/omic/BamRead.h"
     
    3939{
    4040  test::Suite suite(argc, argv, true);
    41 #ifdef YAT_HAVE_LIBBAM
     41#ifdef YAT_HAVE_HTSLIB
    4242  test1(suite);
    4343#endif
     
    4545}
    4646
    47 #ifdef YAT_HAVE_LIBBAM
     47#ifdef YAT_HAVE_HTSLIB
    4848using namespace omic;
    4949
  • trunk/test/bam_header.cc

    r3661 r3883  
    2020#include "Suite.h"
    2121
    22 #ifdef YAT_HAVE_LIBBAM
     22#ifdef YAT_HAVE_HTSLIB
    2323#include "yat/omic/BamFile.h"
    2424#include "yat/omic/BamHeader.h"
     
    4545void test1(test::Suite& suite)
    4646{
    47 #ifdef YAT_HAVE_LIBBAM
     47#ifdef YAT_HAVE_HTSLIB
    4848  using namespace omic;
    4949  std::string file = "../../data/foo.sorted.bam";
  • trunk/test/bam_header2.cc

    r3210 r3883  
    2020#include "Suite.h"
    2121
    22 #ifdef YAT_HAVE_LIBBAM
     22#ifdef YAT_HAVE_HTSLIB
    2323#include "yat/omic/BamFile.h"
    2424#include "yat/omic/BamHeader.h"
     
    2727using namespace theplu::yat;
    2828
    29 #ifndef YAT_HAVE_LIBBAM
     29#ifndef YAT_HAVE_HTSLIB
    3030void do_main(test::Suite& suite) {}
    3131#else
     
    4747}
    4848
    49 #ifdef YAT_HAVE_LIBBAM
     49#ifdef YAT_HAVE_HTSLIB
    5050void do_main(test::Suite& suite)
    5151{
  • trunk/test/bam_iterator.cc

    r3698 r3883  
    2020#include "Suite.h"
    2121
    22 #ifdef YAT_HAVE_LIBBAM
     22#ifdef YAT_HAVE_HTSLIB
    2323#include "yat/omic/BamFile.h"
    2424#include "yat/omic/BamRead.h"
     
    4949}
    5050
    51 #ifdef YAT_HAVE_LIBBAM
     51#ifdef YAT_HAVE_HTSLIB
    5252using namespace omic;
    5353
  • trunk/test/bam_pair.cc

    r3879 r3883  
    1818#include <config.h>
    1919
    20 #ifdef YAT_HAVE_LIBBAM
     20#ifdef YAT_HAVE_HTSLIB
    2121#include "yat/omic/BamPair.h"
    2222#endif
     
    4444}
    4545
    46 #ifdef YAT_HAVE_LIBBAM
     46#ifdef YAT_HAVE_HTSLIB
    4747
    4848omic::BamPair func_pair(const omic::BamRead& read)
     
    7272    other = func_proxy(read);
    7373  }
    74 
    75 
    7674}
    7775#endif
  • trunk/test/bam_pair_analyse.cc

    r3295 r3883  
    1818#include <config.h>
    1919
    20 #if YAT_HAVE_LIBBAM
     20#if YAT_HAVE_HTSLIB
    2121#include "yat/omic/algorithm.h"
    2222#include "yat/omic/BamRead.h"
     
    3535  test::Suite suite(argc, argv, true);
    3636
    37 #ifdef YAT_HAVE_LIBBAM
     37#ifdef YAT_HAVE_HTSLIB
    3838  test1(suite);
    3939#endif
     
    4242
    4343
    44 #ifdef YAT_HAVE_LIBBAM
     44#ifdef YAT_HAVE_HTSLIB
    4545using namespace omic;
    4646
  • trunk/test/bam_pair_iterator.cc

    r3878 r3883  
    1818#include <config.h>
    1919
    20 #ifdef YAT_HAVE_LIBBAM
     20#ifdef YAT_HAVE_HTSLIB
    2121#include "yat/omic/BamFile.h"
    2222#include "yat/omic/BamPairIterator.h"
     
    3434
    3535using namespace theplu::yat;
    36 #ifdef YAT_HAVE_LIBBAM
     36#ifdef YAT_HAVE_HTSLIB
    3737using namespace omic;
    3838#endif
     
    5656void test1(test::Suite& suite)
    5757{
    58 #ifdef YAT_HAVE_LIBBAM
     58#ifdef YAT_HAVE_HTSLIB
    5959  std::string file = "../../data/foo.sorted.bam";
    6060
  • trunk/test/bam_pair_iterator2.cc

    r3878 r3883  
    1818#include <config.h>
    1919
    20 #ifdef YAT_HAVE_LIBBAM
     20#ifdef YAT_HAVE_HTSLIB
    2121#include "yat/omic/BamFile.h"
    2222#include "yat/omic/BamPairIterator2.h"
     
    3333
    3434using namespace theplu::yat;
    35 #ifdef YAT_HAVE_LIBBAM
     35#ifdef YAT_HAVE_HTSLIB
    3636using namespace omic;
    3737#endif
     
    4444  test::Suite suite(argc, argv, true);
    4545  try {
    46 #ifdef YAT_HAVE_LIBBAM
     46#ifdef YAT_HAVE_HTSLIB
    4747    test1(suite);
    4848    test2(suite);
     
    5656}
    5757
    58 #ifdef YAT_HAVE_LIBBAM
     58#ifdef YAT_HAVE_HTSLIB
    5959
    6060void test1(test::Suite& suite)
  • trunk/test/bam_read_filter.cc

    r3210 r3883  
    2020#include "Suite.h"
    2121
    22 #ifdef YAT_HAVE_LIBBAM
     22#ifdef YAT_HAVE_HTSLIB
    2323#include "yat/omic/BamFile.h"
    2424#include "yat/omic/BamRead.h"
     
    4141{
    4242  test::Suite suite(argc, argv, true);
    43 #ifdef YAT_HAVE_LIBBAM
     43#ifdef YAT_HAVE_HTSLIB
    4444  test1(suite);
    4545#endif
     
    4747}
    4848
    49 #ifdef YAT_HAVE_LIBBAM
     49#ifdef YAT_HAVE_HTSLIB
    5050using namespace omic;
    5151
  • trunk/test/bam_region_iterator.cc

    r3682 r3883  
    2020#include "Suite.h"
    2121
    22 #ifdef YAT_HAVE_LIBBAM
     22#ifdef YAT_HAVE_HTSLIB
    2323#include "yat/omic/BamReadIterator.h"
    2424#include "yat/omic/BamWriteIterator.h"
    2525#include "yat/omic/config_bam.h"
    26 #endif
    27 
    28 #ifdef YAT_BAM_HEADER
    29 #include YAT_BAM_HEADER
    3026#endif
    3127
     
    5854void test1(test::Suite& suite)
    5955{
    60 #ifdef YAT_HAVE_LIBBAM
     56#ifdef YAT_HAVE_HTSLIB
    6157  using namespace omic;
    6258  std::string file = "../../data/foo.sorted.bam";
  • trunk/test/fasta.cc

    r3579 r3883  
    2020#include "Suite.h"
    2121
    22 #ifdef YAT_HAVE_LIBBAM
     22#ifdef YAT_HAVE_HTSLIB
    2323#include "yat/omic/Fasta.h"
    2424#endif
     
    3434{
    3535  test::Suite suite(argc, argv, true);
    36 #ifdef YAT_HAVE_LIBBAM
     36#ifdef YAT_HAVE_HTSLIB
    3737  test1(suite);
    3838#endif
     
    4040}
    4141
    42 #ifdef YAT_HAVE_LIBBAM
     42#ifdef YAT_HAVE_HTSLIB
    4343using namespace omic;
    4444
     
    8989  if (rc.size() != len)
    9090    suite.err() << "error: Sequence::size " << rc.size() << " in rc\n";
    91  
     91
    9292}
    9393#endif
  • trunk/test/pileup.cc

    r3855 r3883  
    2626#include <yat/utility/config_public.h>
    2727
    28 #ifdef YAT_HAVE_LIBBAM
     28#ifdef YAT_HAVE_HTSLIB
    2929#include <yat/omic/BamFile.h>
    3030#include <yat/omic/BamReadIterator.h>
     
    5454char seq_nt16(size_t x)
    5555{
    56 #if YAT_HAVE_HTSLIB
    5756  return seq_nt16_str[x];
    58 #elif HAVE_BAM_NT16_REV_TABLE
    59   return bam_nt16_rev_table[x];
    60 #else
    61   std::string table = "=ACMGRSVTWYHKDBN";
    62   return table[x];
    63 #endif
    64 }
    65 
    66 #ifdef YAT_HAVE_LIBBAM
     57}
     58
     59#ifdef YAT_HAVE_HTSLIB
    6760void test1(test::Suite& suite, const std::string& fn)
    6861{
  • trunk/yat/omic/BamFile.cc

    r3792 r3883  
    2525#include "BamHeader.h"
    2626#include "BamReadIterator.h"
    27 #include "config_bam.h"
    2827
    2928#include "yat/utility/Exception.h"
    3029
    31 #include YAT_SAM_HEADER
     30#include <htslib/sam.h>
    3231
    3332#include <cassert>
     
    3635#include <sstream>
    3736
    38 // This is an ugly hack to allow us access members in private struct
    39 // bam_index_t. This is needed to implement faster than linear
    40 // versions of functions 'get_idx_stat' and
    41 // 'n_no_coordinate'. Stealing declarations like this is obviously
    42 // ugly and usually a no-no as it would break if the declaration
    43 // changes in future versions of libbam. Here, we waive that concern
    44 // as the code is only used against libbam and libbam is a project
    45 // with no momentum and no future versions.
    46 //
    47 // Declarations taken from bam_index.c in samtools-0.1.19
    48 // Copyright (c) 2008-2009 Genome Research Ltd.
    49 #ifndef YAT_HAVE_HTSLIB
    50 #if defined YAT_HAVE_BAM_H
    51 #  include <khash.h>
    52 #  include <ksort.h>
    53 #elif defined YAT_HAVE_BAM_BAM_H
    54 #  include <bam/khash.h>
    55 #  include <bam/ksort.h>
    56 #elif defined YAT_HAVE_SAMTOOLS_BAM_H
    57 #  include <samtools/khash.h>
    58 #  include <samtools/ksort.h>
    59 #endif
    60 
    61 #define BAM_MAX_BIN 37450 // =(8^6-1)/7+1
    62 
    63 typedef struct {
    64   uint64_t u, v;
    65 } pair64_t;
    66 
    67 #define pair64_lt(a,b) ((a).u < (b).u)
    68 KSORT_INIT(off, pair64_t, pair64_lt)
    69 
    70 typedef struct {
    71   uint32_t m, n;
    72   pair64_t *list;
    73 } bam_binlist_t;
    74 
    75 typedef struct {
    76   int32_t n, m;
    77   uint64_t *offset;
    78 } bam_lidx_t;
    79 
    80 KHASH_MAP_INIT_INT(i, bam_binlist_t)
    81 
    82 struct __bam_index_t {
    83   int32_t n;
    84   uint64_t n_no_coor; // unmapped reads without coordinate
    85   khash_t(i) **index;
    86   bam_lidx_t *index2;
    87 };
    88 #endif // end samtools specific declarations
    89 
    90 
    9137namespace theplu {
    9238namespace yat {
     
    10753  InBamFile::~InBamFile(void)
    10854  {
    109 #if YAT_HAVE_HTSLIB
    11055    hts_idx_destroy(index_);
    111 #else
    112     bam_index_destroy(index_);
    113 #endif
    11456  }
    11557
     
    12567    uint64_t mapped;
    12668    uint64_t unmapped;
    127 #if YAT_HAVE_HTSLIB
    12869    if (tid >= header().n_targets())
    12970      throw utility::runtime_error("InBamFile::get_idx_stat");
    13071    hts_idx_get_stat(index(), tid, &mapped, &unmapped);
    131 #else
    132     index(); // ensure index_ is loaded
    133     assert(index_);
    134     khint_t k;
    135     int i = tid;
    136     khash_t(i)* h = index_->index[i];
    137     k = kh_get(i, h, BAM_MAX_BIN);
    138     if (k != kh_end(h)) {
    139       mapped = kh_val(h, k).list[1].u;
    140       unmapped = kh_val(h, k).list[1].v;
    141     }
    142     else {
    143       mapped = 0;
    144       unmapped = 0;
    145     }
    146 #endif
    14772    if (return_mapped)
    14873      return mapped;
     
    16085  {
    16186    if (!index_) {
    162 #if YAT_HAVE_HTSLIB
    16387      index_ = hts_idx_load(filename().c_str(), HTS_FMT_BAI);
    164 #else
    165       index_ = bam_index_load(filename().c_str());
    166 #endif
    16788      if (!index_) {
    16889        std::ostringstream ss;
     
    189110  uint64_t InBamFile::n_no_coordinate(void) const
    190111  {
    191 #if YAT_HAVE_HTSLIB
    192112    return hts_idx_get_n_no_coor(index());
    193 #else
    194     index(); // ensure index_ is loaded
    195     assert(index_);
    196     return index_->n_no_coor;
    197 #endif
    198113  }
    199114
     
    201116  void InBamFile::open(const std::string& fn)
    202117  {
    203 #if YAT_HAVE_HTSLIB
    204     open_base(fn, "rb", NULL);
     118    open_base(fn, "rb");
    205119    header_.header_ = sam_hdr_read(sf_);
    206 #else
    207     open_base(fn, "rb", NULL);
    208     header_.header_ = detail::bam_hdr_dup(sf_->header);
    209 #endif
    210120    if (header_.header_ == NULL) {
    211121      std::ostringstream ss;
     
    218128  bool InBamFile::read(BamRead& read)
    219129  {
    220 #if YAT_HAVE_HTSLIB
    221130    int result_ = sam_read1(sf_, header_.header_, read.bam_);
    222 #else
    223     int result_ = samread(sf_, read.bam_);
    224 #endif
    225131    if (result_<-1) {
    226132      std::ostringstream ss;
     
    236142
    237143
    238 #if YAT_HAVE_HTSLIB
    239144  bool InBamFile::read(BamRead& read, hts_itr_t* iter)
    240145  {
    241146    int result = sam_itr_next(sf_, iter, read.bam_);
    242 #else
    243   bool InBamFile::read(BamRead& read, bam_iter_t iter)
    244   {
    245     assert(sf_->type & 1); // no random access from sam files
    246     int result = bam_iter_read(sf_->x.bam, iter, read.bam_);
    247 #endif
    248147    if (result<-1) {
    249148      std::ostringstream ss;
     
    305204      throw std::invalid_argument(oss.str());
    306205    }
    307 #if YAT_HAVE_HTSLIB
    308206    if (compression)
    309207      mode.push_back('0'+compression);
    310208    else
    311209      mode = "wu";
    312 #else
    313     mode.push_back('0'+compression);
    314 #endif
    315210    open(fn, mode, h);
    316211  }
     
    320215                        const BamHeader& h)
    321216  {
    322 #if YAT_HAVE_HTSLIB
    323     open_base(fn, mode, NULL);
     217    open_base(fn, mode);
    324218    if (sam_hdr_write(sf_, h.header_)) {
    325219      std::ostringstream ss;
     
    327221      throw utility::runtime_error(ss.str());
    328222    }
    329 #else
    330     open_base(fn, mode, h.header_);
    331 #endif
    332223  }
    333224
     
    335226  void OutBamFile::write(const BamRead& read)
    336227  {
    337 #if YAT_HAVE_HTSLIB
    338228    assert(read.bam_);
    339229    if (is_open() && bam_write1(sf_->fp.bgzf, read.bam_)>0)
    340230      return;
    341 #else
    342     if (samwrite(sf_, read.bam_)>0)
    343       return;
    344 #endif
    345231    throw OutBamFile::error(read);
    346232  }
  • trunk/yat/omic/BamFile.h

    r3792 r3883  
    2525#include "BamHeader.h"
    2626#include "BamRead.h"
    27 #include "config_bam.h"
    28 
     27
     28#include "yat/utility/deprecate.h"
    2929#include "yat/utility/Exception.h"
    3030#include "yat/utility/FileUtil.h"
    3131#include "yat/utility/yat_assert.h"
    3232
    33 #include YAT_SAM_HEADER
     33#include <htslib/sam.h>
    3434
    3535#include <boost/utility.hpp>
     
    9191       open a bam file named \a fn with mode \a mode
    9292
    93        \see samopen
     93       \see sam_open in htslib
    9494
    9595       \note \a aux is ignored when compiling against htslib
     96
     97       \deprecated Provided for backward compatibility with the yat
     98       0.17 API. Use open_base(2) instead.
    9699     */
    97100    void open_base(const std::string& fn, const std::string& mode,
    98                    const void* aux);
    99 
    100 #ifndef YAT_HAVE_HTSLIB
    101     /**
    102        \brief only defined when compiling against old bamlib
    103 
    104        Old samtools 0.1.xx had a struct samfile_t, which in htslib has
    105        changed to samFile
     101                   const void* aux) YAT_DEPRECATE;
     102
     103    /**
     104       open a bam file named \a fn with mode \a mode
     105
     106       \see sam_open in htslib
     107
     108       \since New in yat 0.18
    106109    */
    107     typedef samfile_t samFile;
    108 #endif
     110    void open_base(const std::string& fn, const std::string& mode);
    109111
    110112    /**
     
    137139       Struct describing bam index.
    138140
    139        If compiled against htslib, \c hts_idx_t. If compiled against
    140        libbam, \c bam_index_t.
     141       \see hts_idx_t in htslib
    141142
    142143       \since New in yat 0.13
     
    144145       \see function index(void) const
    145146     */
    146 #if YAT_HAVE_HTSLIB
    147147    typedef hts_idx_t index_type;
    148 #else
    149     typedef bam_index_t index_type;
    150 #endif
    151148
    152149    /**
     
    231228       \return true on success
    232229     */
    233 #if YAT_HAVE_HTSLIB
    234230    bool read(BamRead& read, hts_itr_t* iter);
    235 #else
    236     bool read(BamRead& read, bam_iter_t iter);
    237 #endif
    238231  private:
    239232    uint64_t get_idx_stat(int tid, bool return_mapped) const;
     
    366359  void BamFile<Derived>::build_index_base(void) const
    367360  {
    368 #ifdef YAT_HAVE_HTSLIB
    369361    int res = bam_index_build(filename_.c_str(), 0);
    370 #else
    371     int res = bam_index_build(filename_.c_str());
    372 #endif
    373362    if (res) {
    374363      std::ostringstream msg;
     
    388377  void BamFile<Derived>::close(void)
    389378  {
    390 #if YAT_HAVE_HTSLIB
    391379    if (sf_==NULL)
    392380      return;
    393381    if (sam_close(sf_))
    394382      throw utility::IO_error("BamFile::close() failed");
    395 #else
    396     samclose(sf_);
    397 #endif
    398383    sf_ = NULL;
    399384  }
     
    419404                                   const void* aux)
    420405  {
     406    YAT_ASSERT(aux==NULL); // aux is ignored in htslib mode
     407    open_base(fn, mode);
     408  }
     409
     410
     411  template<class Derived>
     412  void BamFile<Derived>::open_base(const std::string& fn,
     413                                   const std::string& mode)
     414  {
    421415    filename_ = fn;
    422416    YAT_ASSERT(!sf_);
    423 #if YAT_HAVE_HTSLIB
    424     YAT_ASSERT(aux==NULL); // aux is ignored in htslib mode
    425417    sf_ = sam_open(fn.c_str(), mode.c_str());
    426 #else
    427     sf_ = samopen(fn.c_str(), mode.c_str(), aux);
    428 #endif
    429418    if (!sf_) {
    430419      std::ostringstream ss;
  • trunk/yat/omic/BamHeader.cc

    r3823 r3883  
    2727#include "yat/utility/split.h"
    2828#include "yat/utility/stl_utility.h"
    29 
    30 // we need to include 'sam_header.h' when compiling against libbam
    31 #ifndef YAT_HAVE_HTSLIB
    32   #if YAT_HAVE_BAM_H
    33   #include <sam_header.h>
    34   #elif YAT_HAVE_BAM_BAM_H
    35   #include <bam/sam_header.h>
    36   #elif YAT_HAVE_SAMTOOLS_BAM_H
    37   #include <samtools/sam_header.h>
    38   #else
    39   #error cannot end up here
    40   #endif
    41 #endif
    4229
    4330#include <cassert>
     
    6047  BamHeader::~BamHeader(void)
    6148  {
    62 #if YAT_HAVE_HTSLIB
    6349    bam_hdr_destroy(header_);
    64 #else
    65     bam_header_destroy(header_);
    66 #endif
    6750  }
    6851
     
    7154    : read_group_(other.read_group_), program_group_(other.program_group_)
    7255  {
    73 #ifndef YAT_HAVE_HTSLIB
    74     using namespace detail; // for bam_hdr_dup in YAT_HAVE_LIBBAM mode
    75 #endif
    7656    header_ = bam_hdr_dup(other.header_);
    7757  }
     
    134114  {
    135115    assert(header_);
    136 #if YAT_HAVE_HTSLIB
    137116    const char* b = reg.c_str();
    138117    const char* e = hts_parse_reg(b, &begin, &end);
     
    150129      }
    151130    }
    152 #else
    153     if (!bam_parse_region(header_, reg.c_str(), &id, &begin, &end))
    154       return;
    155 #endif
    156131    std::ostringstream ss;
    157132    ss << "invalid region: '" << reg << "'";
     
    235210  {
    236211    BamHeader tmp;
    237 #ifdef YAT_HAVE_HTSLIB
    238212    tmp.header_ = sam_hdr_parse(txt.size(), txt.c_str());
    239 #else
    240     tmp.header_ = bam_header_init();
    241 #endif
    242213
    243214    // throw if failed
     
    256227    // copy to temporary
    257228    memcpy(tmp.header_->text, txt.c_str(), txt.size()+1);
    258 #ifndef YAT_HAVE_HTSLIB
    259     sam_header_parse(tmp.header_);
    260 #endif
    261229
    262230    // everything worked; swap data so this get the new stuff and
     
    268236  int32_t BamHeader::tid(const std::string& name) const
    269237  {
    270 #if YAT_HAVE_HTSLIB
    271238    int res = bam_name2id(header_, name.c_str());
    272239    if (res==-1) {
     
    276243    }
    277244    return res;
    278 #else
    279     if (!header_->hash) {
    280       // We would like to call something like bam_init_header_hash,
    281       // but unfortunately that function is not defined in any header
    282       // (only in two source files). Instead we call bam_parse_region
    283       // because a documented side-effect of that function is that
    284       // hash get populated.
    285       int tid, b, e;
    286       bam_parse_region(header_, name.c_str(), &tid, &b, &e);
    287       assert(header_->hash);
    288       assert(tid == bam_get_tid(header_, name.c_str()));
    289       return tid;
    290     }
    291     return bam_get_tid(header_, name.c_str());
    292 #endif
    293245  }
    294246
     
    323275#endif
    324276
    325 
    326 #ifndef YAT_HAVE_HTSLIB
    327   namespace detail {
    328     bam_header_t * bam_hdr_dup(const bam_header_t* other)
    329     {
    330       // taken from htslib 1.2.1 and adjusted to fit old struct bam_header_t
    331       if (!other)
    332         return NULL;
    333       bam_header_t* h = bam_header_init();
    334       if (!h)
    335         return NULL;
    336       // copy stuff
    337       h->n_targets = other->n_targets;
    338       h->l_text = other->l_text;
    339       h->n_text = other->n_text;
    340       h->dict = NULL;
    341       h->hash = NULL;
    342       h->rg2lib = NULL;
    343 
    344       h->text = (char*)calloc(h->l_text + 1, 1);
    345       memcpy(h->text, other->text, h->l_text);
    346       h->target_len = (uint32_t*)calloc(h->n_targets, sizeof(uint32_t));
    347       h->target_name = (char**)calloc(h->n_targets, sizeof(char*));
    348       for (int i = 0; i < h->n_targets; ++i) {
    349         h->target_len[i] = other->target_len[i];
    350         h->target_name[i] = strdup(other->target_name[i]);
    351       }
    352       return h;
    353     }
    354   }
    355 #endif
    356 
    357277}}}
  • trunk/yat/omic/BamHeader.h

    r3792 r3883  
    2323*/
    2424
    25 #include "config_bam.h"
    26 
    2725#include "yat/utility/config_public.h"
    28 
    2926#include "yat/utility/stl_utility.h"
    3027
    31 #include YAT_SAM_HEADER
     28#include <htslib/sam.h>
    3229
    3330#include <boost/iterator/transform_iterator.hpp>
     
    3936namespace yat {
    4037namespace omic {
    41 
    42 #ifndef YAT_HAVE_HTSLIB
    43   namespace detail {
    44     bam_header_t * bam_hdr_dup(const bam_header_t* other);
    45   }
    46 #endif
    4738
    4839  /**
     
    247238
    248239  private:
    249 #ifndef YAT_HAVE_HTSLIB
    250     typedef bam_header_t bam_hdr_t;
    251 #endif
    252240    bam_hdr_t* header_;
    253241    mutable strMap2 read_group_;
  • trunk/yat/omic/BamRead.cc

    r3875 r3883  
    2323
    2424#include "BamRead.h"
    25 #include "config_bam.h"
    26 
    27 #include YAT_SAM_HEADER
    2825
    2926#include "yat/utility/Exception.h"
     
    4138#endif
    4239
    43 // these #defines are no longer available in htslib, define them using
    44 // htslib version
    45 #ifndef bam1_seq
    46 #define bam1_seq(b) (bam_get_seq(b))
    47 #endif
    48 
    49 #ifndef bam1_seqi
    50 #define bam1_seqi(b, i) (bam_seqi(b, i))
    51 #endif
    52 
    53 #ifndef bam1_cigar
    54 #define bam1_cigar(b) (bam_get_cigar(b))
    55 #endif
    56 
    57 #ifndef bam1_qname
    58 #define bam1_qname(b) (bam_get_qname(b))
    59 #endif
    60 
    61 #ifndef bam1_qual
    62 #define bam1_qual(b) (bam_get_qual(b))
    63 #endif
    64 
    6540namespace theplu {
    6641namespace yat {
     
    11489  {
    11590    assert(bam_);
    116 #if YAT_HAVE_HTSLIB
    11791    return bam_get_aux(bam_);
    118 #else
    119     return bam1_aux(bam_);
    120 #endif
    12192  }
    12293
     
    152123  {
    153124    assert(bam_);
    154 #if YAT_HAVE_HTSLIB
    155125    return bam_get_l_aux(bam_);
    156 #else
    157     return bam_->l_aux;
    158 #endif
    159   }
    160 
    161 
    162 #ifndef YAT_HAVE_HTSLIB
    163   uint32_t BamRead::calend(const bam1_core_t *c, const uint32_t *cigar) const
    164   {
    165 #ifdef HAVE_BAM_CALEND
    166     return bam_calend(&core(), bam1_cigar(bam_));
    167 #endif
    168     int k, end = c->pos;
    169     for (k = 0; k < c->n_cigar; ++k) {
    170       int op  = bam_cigar_op(cigar[k]);
    171       int len = bam_cigar_oplen(cigar[k]);
    172       if (op == BAM_CBACK) { // move backward
    173         int l, u, v;
    174         if (k == c->n_cigar - 1) break; // skip trailing 'B'
    175         for (l = k - 1, u = v = 0; l >= 0; --l) {
    176           int op1  = bam_cigar_op(cigar[l]);
    177           int len1 = bam_cigar_oplen(cigar[l]);
    178           if (bam_cigar_type(op1)&1) { // consume query
    179             if (u + len1 >= len) { // stop
    180               if (bam_cigar_type(op1)&2) v += len - u;
    181               break;
    182             } else u += len1;
    183           }
    184           if (bam_cigar_type(op1)&2) v += len1;
    185         }
    186         end = l < 0? c->pos : end - v;
    187       } else if (bam_cigar_type(op)&2) end += bam_cigar_oplen(cigar[k]);
    188     }
    189     return end;
    190   }
    191 #endif
     126  }
    192127
    193128
    194129  const uint32_t* BamRead::cigar(void) const
    195130  {
    196 #if YAT_HAVE_HTSLIB
    197131    return bam_get_cigar(bam_);
    198 #else
    199     return bam1_cigar(bam_);
    200 #endif
    201132  }
    202133
     
    254185    // first move remaining data to new location
    255186    if (offset)
    256       memmove(bam1_seq(bam_)+offset, bam1_seq(bam_),
     187      memmove(bam_get_seq(bam_)+offset, bam_get_seq(bam_),
    257188              data_size() - 4*core().n_cigar - core().l_qname);
    258189
    259190    // copy new cigar
    260191    for (size_t i=0; i<c.size(); ++i)
    261       bam1_cigar(bam_)[i] = c[i];
     192      bam_get_cigar(bam_)[i] = c[i];
    262193
    263194    data_size() += offset;
     
    283214  int& BamRead::data_size(void)
    284215  {
    285 #if YAT_HAVE_HTSLIB
    286216    return bam_->l_data;
    287 #else
    288     return bam_->data_len;
    289 #endif
    290217  }
    291218
     
    293220  const int& BamRead::data_size(void) const
    294221  {
    295 #if YAT_HAVE_HTSLIB
    296222    return bam_->l_data;
    297 #else
    298     return bam_->data_len;
    299 #endif
    300223  }
    301224
     
    304227  {
    305228    assert(bam_);
    306 #if YAT_HAVE_HTSLIB
    307229    return bam_endpos(bam_);
    308 #else
    309     return this->calend(&core(), bam1_cigar(bam_));
    310 #endif
    311230  }
    312231
     
    349268
    350269  const char* BamRead::name(void) const
    351   { return bam1_qname(bam_); }
     270  {
     271    return bam_get_qname(bam_);
     272  }
    352273
    353274
     
    364285    core().l_qname += offset;
    365286    // copy new name
    366     memcpy(bam1_qname(bam_), n.c_str(), n.size()+1);
     287    memcpy(bam_get_qname(bam_), n.c_str(), n.size()+1);
    367288    data_size() += offset;
    368289    assert(static_cast<uint32_t>(data_size()) <= data_capacity());
     
    371292
    372293  uint8_t BamRead::qual(size_t i) const
    373   { return *(bam1_qual(bam_)+i); }
     294  {
     295    return *(bam_get_qual(bam_)+i);
     296  }
    374297
    375298
    376299  void BamRead::qual(size_t i, uint8_t q)
    377   { *(bam1_qual(bam_)+i)=q; }
     300  {
     301    *(bam_get_qual(bam_)+i)=q;
     302  }
    378303
    379304
     
    414339    // |-- qname -->-- cigar -->-- seq -->-- qual -->-- aux -->
    415340
    416     int aux_pos = bam1_seq(bam_) - bam_->data + (seq.size()+1)/2 + qual.size();
     341    int aux_pos =
     342      bam_get_seq(bam_) - bam_->data + (seq.size()+1)/2 + qual.size();
    417343    int len = aux_pos + aux_size();
    418344    reserve(len);
     
    425351    core().l_qseq = seq.size();
    426352    // copy quality
    427     if (qual.size()) // FIXME is this needed or does memcpy work with n=0?
    428       memcpy(static_cast<void*>(bam1_qual(bam_)),
    429              static_cast<const void*>(&qual[0]), qual.size());
     353    memcpy(static_cast<void*>(bam_get_qual(bam_)),
     354           static_cast<const void*>(&qual[0]), qual.size());
    430355    data_size() = len;
    431356    assert(static_cast<uint32_t>(data_size()) <= data_capacity());
     
    437362    assert(bam_);
    438363    assert(seq < 16);
    439     bam1_seq_seti(bam1_seq(bam_), i, seq);
     364    bam1_seq_seti(bam_get_seq(bam_), i, seq);
    440365  }
    441366
     
    444369  {
    445370    assert(bam_);
    446     return bam1_seqi(bam1_seq(bam_),index);
     371    return bam_seqi(bam_get_seq(bam_),index);
    447372  }
    448373
     
    503428  const unsigned char nt16_table(char c)
    504429  {
    505 #if YAT_HAVE_HTSLIB
    506430    return seq_nt16_table[static_cast<uint8_t>(c)];
    507 #else
    508     return bam_nt16_table[static_cast<uint8_t>(c)];
    509 #endif
    510431  }
    511432
     
    514435  {
    515436    assert(x<16);
    516 #if YAT_HAVE_HTSLIB
    517437    return seq_nt16_str[x];
    518 #elif HAVE_BAM_NT16_REV_TABLE
    519     return bam_nt16_rev_table[x];
    520 #else
    521     char table[16] = "=ACMGRSVTWYHKDBN";
    522     return table[x];
    523 #endif
    524438  }
    525439
  • trunk/yat/omic/BamRead.h

    r3855 r3883  
    2323*/
    2424
    25 #include "config_bam.h"
    26 
    2725#include "yat/utility/Aligner.h"
    2826// This file has to be included to keep compatibility with yat 0.11
     
    3028#include "yat/utility/deprecate.h"
    3129
    32 #include YAT_SAM_HEADER
     30#include <htslib/sam.h>
    3331
    3432#include <functional>
     
    393391    friend class OutBamFile;
    394392    friend class BamReadIterator;
    395 #ifndef YAT_HAVE_HTSLIB
    396     uint32_t calend(const bam1_core_t *c, const uint32_t *cigar) const;
    397 #endif
    398393    // access data length, current length of data
    399394    int& data_size(void);
  • trunk/yat/omic/BamReadFilter.h

    r3792 r3883  
    2323*/
    2424
    25 #include "config_bam.h"
    26 #include YAT_SAM_HEADER
     25#include <htslib/sam.h>
    2726
    2827#include <functional>
  • trunk/yat/omic/BamReadIterator.cc

    r3792 r3883  
    123123  {
    124124    using boost::shared_ptr;
    125 #if YAT_HAVE_HTSLIB
    126125    iter_ = shared_ptr<hts_itr_t>(sam_itr_queryi(bf.index(), tid, begin, end),
    127126                                  IndexDestroyer());
    128 #else
    129     iter_ =
    130       shared_ptr<__bam_iter_t>(bam_iter_query(bf.index(), tid, begin, end),
    131                                IndexDestroyer());
    132 #endif
    133127    if (!iter_.get()) {
    134128      std::stringstream ss;
  • trunk/yat/omic/BamReadIterator.h

    r3792 r3883  
    2525#include "BamFile.h"
    2626#include "BamRead.h"
    27 #include "config_bam.h"
    2827
    29 #include YAT_SAM_HEADER
     28#include <htslib/sam.h>
    3029
    3130#include <boost/iterator/iterator_facade.hpp>
     
    150149      void increment(void);
    151150    private:
    152 #if YAT_HAVE_HTSLIB
    153151      boost::shared_ptr<hts_itr_t> iter_;
    154 #else
    155       boost::shared_ptr<__bam_iter_t> iter_;
    156 #endif
    157152    };
    158153
     
    161156    struct IndexDestroyer
    162157    {
    163 #if YAT_HAVE_HTSLIB
    164158      void operator()(hts_itr_t* i) const
    165159      {
    166160        bam_itr_destroy(i);
    167161      }
    168 #else
    169       void operator()(bam_iter_t i) const
    170       {
    171         bam_iter_destroy(i);
    172       }
    173 #endif
    174162    };
    175163  };
  • trunk/yat/omic/BamWriteIterator.cc

    r3792 r3883  
    2525
    2626#include "BamFile.h"
    27 #include "config_bam.h"
    2827
    29 #include YAT_SAM_HEADER
     28#include <htslib/sam.h>
    3029
    3130#include <cassert>
  • trunk/yat/omic/Fasta.cc

    r3792 r3883  
    4848      throw utility::runtime_error(ss.str());
    4949    }
    50 #ifndef YAT_HAVE_HTSLIB
    51     // parse index file
    52     std::string fai = fn + ".fai";
    53     // this will obviously not work if fn is remote
    54     std::ifstream is(fai.c_str());
    55     if (!is) {
    56       std::ostringstream ss;
    57       ss << "cannot open index file '" << fai << "'";
    58       throw utility::runtime_error(ss.str());
    59     }
    60     std::string line;
    61     while (getline(is, line)) {
    62       std::vector<std::string> vec;
    63       utility::split(vec, line, '\t');
    64       name_.push_back(vec[0]);
    65       try {
    66         size_[vec[0]] = utility::convert<int>(vec[1]);
    67       }
    68       catch (utility::runtime_error& e) {
    69         std::ostringstream ss;
    70         ss << "incorrect format in '" << fai << "'\n";
    71         ss << "line: " << line << "\n";
    72         throw utility::runtime_error(ss.str());
    73       }
    74     }
    75     is.close();
    76 #endif
    7750  }
    7851
     
    8154                    int begin,  int end) const
    8255  {
    83     // faidx_fetch_seq takes char* in samtools and const char* in htslib
    84 #if HAVE_HTSLIB
    85     boost::scoped_array<const char> c(chr.c_str());
    86 #else
    87     boost::scoped_array<char> c(new char[chr.size()+1]);
    88     strcpy(c.get(), chr.c_str());
    89 #endif
    9056    // faidx_fetch_seq returns char* allocated the malloc; tell smart
    9157    // pointer to deallocate with free() rather than delete (default).
    92     boost::shared_array<const char>
    93       ptr(faidx_fetch_seq(faidx_.get(), c.get(), begin,end, &res.size_), free);
    94     res.seq_ = ptr;
     58    res.seq_.reset(faidx_fetch_seq(faidx_.get(), chr.c_str(), begin, end,
     59                                   &res.size_), free);
    9560  }
    9661
     
    9964  {
    10065    assert(static_cast<int>(i) < nseq());
    101 #ifdef YAT_HAVE_HTSLIB
    10266    return faidx_iseq(faidx_.get(), i);
    103 #else
    104     assert(i < name_.size());
    105     return name_[i];
    106 #endif
    10767  }
    10868
     
    11070  int Fasta::nseq(void) const
    11171  {
    112 #ifdef YAT_HAVE_HTSLIB
    11372    return faidx_nseq(faidx_.get());
    114 #else
    115     return faidx_fetch_nseq(faidx_.get());
    116 #endif
    11773  }
    11874
     
    12076  bool Fasta::present(const std::string& name) const
    12177  {
    122 #ifdef YAT_HAVE_HTSLIB
    12378    return faidx_has_seq(faidx_.get(), name.c_str());
    124 #else
    125     return size_.count(name);
    126 #endif
    12779  }
    12880
     
    169121  int Fasta::sequence_length(const std::string& name) const
    170122  {
    171 #ifdef YAT_HAVE_HTSLIB
    172123    int res = faidx_seq_len(faidx_.get(), name.c_str());
    173124    if (res == -1)
    174125      throw_unknown_chr(name);
    175126    return res;
    176 #else
    177     std::map<std::string, int>::const_iterator it = size_.find(name);
    178     if (it == size_.end())
    179       throw_unknown_chr(name);
    180     return it->second;
    181 #endif
    182127  }
    183128
  • trunk/yat/omic/Fasta.h

    r3792 r3883  
    1919// along with yat. If not, see <http://www.gnu.org/licenses/>.
    2020
    21 #include "config_bam.h"
    22 
    23 #include YAT_FAIDX_HEADER
     21#include <htslib/faidx.h>
    2422
    2523#include <boost/shared_array.hpp>
     
    143141    // throw exception; called when incorrect chr is passed
    144142    void throw_unknown_chr(const std::string&) const;
    145 #ifndef YAT_HAVE_HTSLIB
    146     std::vector<std::string> name_;
    147     std::map<std::string, int> size_;
    148 #endif
    149143  };
    150144
  • trunk/yat/omic/config_bam.h

    r3792 r3883  
    3434#include "yat/utility/config_public.h"
    3535
     36// These #defines are not needed anymore (since we don't suppoer
     37// building against libbam), but left for backward compatibility with
     38// yat 0.17.
    3639#if defined YAT_HAVE_HTSLIB_HTS_H
    3740#  define YAT_SAM_HEADER "htslib/sam.h"
    3841#  define YAT_FAIDX_HEADER "htslib/faidx.h"
    39 #elif defined YAT_HAVE_BAM_H
    40 #  define YAT_BAM_HEADER "bam.h"
    41 #  define YAT_FAIDX_HEADER "faidx.h"
    42 #  define YAT_SAM_HEADER "sam.h"
    43 #elif defined YAT_HAVE_BAM_BAM_H
    44 #  define YAT_BAM_HEADER "bam/bam.h"
    45 #  define YAT_FAIDX_HEADER "bam/faidx.h"
    46 #  define YAT_SAM_HEADER "bam/sam.h"
    47 #elif defined YAT_HAVE_SAMTOOLS_BAM_H
    48 #  define YAT_BAM_HEADER "samtools/bam.h"
    49 #  define YAT_FAIDX_HEADER "samtools/faidx.h"
    50 #  define YAT_SAM_HEADER "samtools/sam.h"
    5142#endif
    5243
  • trunk/yat/utility/config_public.h.in

    r3855 r3883  
    2929
    3030
    31 /// Define to 1 if you have the <bam/bam.h> header file.
    32 #undef YAT_HAVE_BAM_BAM_H
    33 
    34 /// Define to 1 if you have the <bam.h> header file.
    35 #undef YAT_HAVE_BAM_H
    36 
    37 /// Define to 1 if HTS is available
     31/// Define to 1 if htslib is available
    3832#undef YAT_HAVE_HTSLIB
    3933
     
    4135#undef YAT_HAVE_HTSLIB_HTS_H
    4236
    43 /// Define to 1 if you have the <hts.h> header file.
    44 #undef YAT_HAVE_HTS_H
    45 
    46 /// Define to 1 if yat is built with bam support
    47 #undef YAT_HAVE_LIBBAM
    48 
    49 /// Define to 1 if you have the <samtools/bam.h> header file.
    50 #undef YAT_HAVE_SAMTOOLS_BAM_H
     37/// This macro is deprated, left for backward compatibility with yat 0.17
     38#define YAT_HAVE_LIBBAM YAT_HAVE_HTSLIB
    5139
    5240/// Define if compiler supports deprecated attribute, as in g++ 4.0
Note: See TracChangeset for help on using the changeset viewer.