Changeset 3353


Ignore:
Timestamp:
Nov 22, 2014, 11:26:14 AM (8 years ago)
Author:
Peter
Message:

refs #794. First version that compiles against htslib. Alibi implementations in some cases though.

Location:
trunk/yat/omic
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/omic/BamFile.cc

    r3350 r3353  
    5353  InBamFile::~InBamFile(void)
    5454  {
     55#if YAT_HAVE_HTSLIB
     56    hts_idx_destroy(index_);
     57#else
    5558    bam_index_destroy(index_);
     59#endif
    5660  }
    5761
     
    6367
    6468
    65   const bam_index_t* InBamFile::index(void) const
     69  const InBamFile::index_type* InBamFile::index(void) const
    6670  {
    6771    if (!index_) {
     72#if YAT_HAVE_HTSLIB
     73      index_ = hts_idx_load(filename().c_str(), HTS_FMT_BAI);
     74#else
    6875      index_ = bam_index_load(filename().c_str());
     76#endif
    6977      if (!index_) {
    7078        std::ostringstream ss;
     
    7987  void InBamFile::open(const std::string& fn)
    8088  {
     89#if YAT_HAVE_HTSLIB
     90    assert(0 && "FIXME");
     91#else
    8192    open_base(fn, "rb", NULL);
    8293    header_.header_ = sf_->header;
     94#endif
    8395    if (header_.header_ == NULL) {
    8496      std::ostringstream ss;
     
    91103  bool InBamFile::read(BamRead& read)
    92104  {
     105#if YAT_HAVE_HTSLIB
     106    int result_ = sam_read1(sf_, header_.header_, read.bam_);
     107#else
    93108    int result_ = samread(sf_, read.bam_);
     109#endif
    94110    if (result_<-1) {
    95111      std::ostringstream ss;
     
    105121
    106122
     123#if YAT_HAVE_HTSLIB
     124  bool InBamFile::read(BamRead& read, hts_itr_t* iter)
     125  {
     126    assert(0 && "FIXME");
     127    int result_ = -1;
     128#else
    107129  bool InBamFile::read(BamRead& read, bam_iter_t iter)
    108130  {
    109131    assert(sf_->type & 1); // no random access from sam files
    110132    int result_ = bam_iter_read(sf_->x.bam, iter, read.bam_);
     133#endif
    111134    if (result_<-1) {
    112135      std::ostringstream ss;
     
    141164  void OutBamFile::open(const std::string& fn, const BamHeader& h)
    142165  {
     166#if YAT_HAVE_HTSLIB
     167    assert(0 && "FIXME");
     168#else
    143169    open_base(fn, "wb", h.header_);
     170#endif
    144171  }
    145172
     
    155182      throw std::invalid_argument(oss.str());
    156183    }
     184#if YAT_HAVE_HTSLIB
     185    assert(0 && "FIXME");
     186#else
    157187    mode.push_back('0'+compression);
    158188    open_base(fn, mode, h.header_);
     189#endif
    159190  }
    160191
     
    162193  void OutBamFile::write(const BamRead& read)
    163194  {
     195#if YAT_HAVE_HTSLIB
     196    if (bam_write1(sf_->fp.bgzf, read.bam_)) {
     197#else
    164198    if (samwrite(sf_, read.bam_)<=0) {
     199#endif
    165200      throw OutBamFile::error(read);
    166201    }
  • trunk/yat/omic/BamFile.h

    r3166 r3353  
    8080       \see samopen
    8181     */
     82#ifndef YAT_HAVE_HTSLIB
    8283    void open_base(const std::string& fn, const std::string& mode,
    8384                   const void* aux);
     85#endif
     86
     87#ifndef YAT_HAVE_HTSLIB
     88    /// Old samtools 0.1.xx had a struct samfile_t, which in htslib has
     89    /// changed to samFile
     90    typedef samfile_t samFile;
     91#endif
     92
    8493    /**
    8594       bam file handler
    8695     */
    87     samfile_t* sf_;
     96    samFile* sf_;
    8897
    8998    /**
     
    108117  public:
    109118    /**
     119       Struct describing bam index.
     120
     121       If compiled against htslib, \c hts_idx_t. If compiled against
     122       libbam, \c bam_index_t.
     123
     124       \see index(void)
     125     */
     126#if YAT_HAVE_HTSLIB
     127    typedef hts_idx_t index_type;
     128#else
     129    typedef bam_index_t index_type;
     130#endif
     131
     132    /**
    110133       \brief Default constructor
    111134     */
     
    139162       reads from stdin, this function throws.
    140163     */
    141     const bam_index_t* index(void) const;
     164    const index_type* index(void) const;
    142165
    143166    /**
     
    162185       \return true on success
    163186     */
     187#if YAT_HAVE_HTSLIB
     188    bool read(BamRead& read, hts_itr_t* iter);
     189#else
    164190    bool read(BamRead& read, bam_iter_t iter);
     191#endif
    165192  private:
    166193    BamHeader header_;
    167     mutable bam_index_t* index_;
     194    mutable index_type* index_;
    168195  };
    169196
     
    280307  void BamFile<Derived>::close(void)
    281308  {
     309#if YAT_HAVE_HTSLIB
     310    // FIXME, check that sam_close returns 0 (for success)
     311    sam_close(sf_);
     312#else
    282313    samclose(sf_);
     314#endif
    283315    sf_ = NULL;
    284316  }
     
    292324
    293325
     326#ifndef YAT_HAVE_HTSLIB
    294327  template<class Derived>
    295328  void BamFile<Derived>::open_base(const std::string& fn,
     
    306339    }
    307340  }
     341#endif
    308342
    309343}}}
  • trunk/yat/omic/BamReadFilter.h

    r3350 r3353  
    2727
    2828#include <functional>
     29
     30#ifndef BAM_DEF_MASK
     31#define BAM_DEF_MASK (BAM_FUNMAP | BAM_FSECONDARY | BAM_FQCFAIL | BAM_FDUP)
     32#endif
    2933
    3034namespace theplu {
  • trunk/yat/omic/BamReadIterator.cc

    r3056 r3353  
    112112    : Actor(&bf)
    113113  {
     114#if YAT_HAVE_HTSLIB
     115    hts_itr_t* it = hts_itr_query(bf.index(), tid, begin, end, NULL);
     116#else
    114117    bam_iter_t it = bam_iter_query(bf.index(), tid, begin, end);
     118#endif
    115119    if (!it) {
    116120      std::stringstream ss;
     
    120124    }
    121125    // iter_ takes ownership
     126#if YAT_HAVE_HTSLIB
     127    iter_ = boost::shared_ptr<hts_itr_t>(it, IndexDestroyer());
     128#else
    122129    iter_ = boost::shared_ptr<__bam_iter_t>(it, IndexDestroyer());
     130#endif
    123131    assert(iter_.get());
    124132  }
  • trunk/yat/omic/BamReadIterator.h

    r3018 r3353  
    132132      void increment(void);
    133133    private:
     134#if YAT_HAVE_HTSLIB
     135      boost::shared_ptr<hts_itr_t> iter_;
     136#else
    134137      boost::shared_ptr<__bam_iter_t> iter_;
     138#endif
    135139    };
    136140
     
    139143    struct IndexDestroyer
    140144    {
     145#if YAT_HAVE_HTSLIB
     146      void operator()(hts_itr_t* i) const
     147      {
     148        bam_itr_destroy(i);
     149      }
     150#else
    141151      void operator()(bam_iter_t i) const
    142152      {
    143153        bam_iter_destroy(i);
    144154      }
     155#endif
    145156    };
    146157  };
Note: See TracChangeset for help on using the changeset viewer.