Changeset 3357


Ignore:
Timestamp:
Nov 23, 2014, 2:54:44 AM (8 years ago)
Author:
Peter
Message:

refs #794. implement open and close functions

Location:
trunk/yat/omic
Files:
2 edited

Legend:

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

    r3353 r3357  
    8888  {
    8989#if YAT_HAVE_HTSLIB
    90     assert(0 && "FIXME");
     90    open_base(fn, "rb", NULL);
     91    header_.header_ = sam_hdr_read(sf_);
    9192#else
    9293    open_base(fn, "rb", NULL);
     
    165166  {
    166167#if YAT_HAVE_HTSLIB
    167     assert(0 && "FIXME");
     168    open_base(fn, "wb", NULL);
     169    sam_hdr_write(sf_, h.header_);
    168170#else
    169171    open_base(fn, "wb", h.header_);
     
    183185    }
    184186#if YAT_HAVE_HTSLIB
    185     assert(0 && "FIXME");
     187    if (compression)
     188      mode.push_back('0'+compression);
     189    else
     190      mode = "wu";
     191    open_base(fn, mode, NULL);
     192    sam_hdr_write(sf_, h.header_);
    186193#else
    187194    mode.push_back('0'+compression);
     
    194201  {
    195202#if YAT_HAVE_HTSLIB
    196     if (bam_write1(sf_->fp.bgzf, read.bam_)) {
     203    if (bam_write1(sf_->fp.bgzf, read.bam_)<=0) {
    197204#else
    198205    if (samwrite(sf_, read.bam_)<=0) {
  • trunk/yat/omic/BamFile.h

    r3353 r3357  
    7979
    8080       \see samopen
    81      */
    82 #ifndef YAT_HAVE_HTSLIB
     81
     82       \note \a aux is ignored when compiling against htslib
     83     */
    8384    void open_base(const std::string& fn, const std::string& mode,
    8485                   const void* aux);
    85 #endif
    8686
    8787#ifndef YAT_HAVE_HTSLIB
     
    308308  {
    309309#if YAT_HAVE_HTSLIB
    310     // FIXME, check that sam_close returns 0 (for success)
    311     sam_close(sf_);
     310    if (sf_==NULL)
     311      return;
     312    if (sam_close(sf_))
     313      throw utility::IO_error("BamFile::close() failed");
    312314#else
    313315    samclose(sf_);
     
    324326
    325327
    326 #ifndef YAT_HAVE_HTSLIB
    327328  template<class Derived>
    328329  void BamFile<Derived>::open_base(const std::string& fn,
     
    332333    filename_ = fn;
    333334    YAT_ASSERT(!sf_);
     335#if YAT_HAVE_HTSLIB
     336    YAT_ASSERT(aux==NULL); // aux is ignored in htslib mode
     337    sf_ = sam_open(fn.c_str(), mode.c_str());
     338#else
    334339    sf_ = samopen(fn.c_str(), mode.c_str(), aux);
     340#endif
    335341    if (!sf_) {
    336342      std::ostringstream ss;
     
    339345    }
    340346  }
    341 #endif
    342347
    343348}}}
Note: See TracChangeset for help on using the changeset viewer.