Changeset 3358


Ignore:
Timestamp:
Nov 23, 2014, 8:02:26 AM (8 years ago)
Author:
Peter
Message:

fix how to read from a hts_itr_t. refs #794

Location:
trunk/yat/omic
Files:
3 edited

Legend:

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

    r3357 r3358  
    125125  bool InBamFile::read(BamRead& read, hts_itr_t* iter)
    126126  {
    127     assert(0 && "FIXME");
    128     int result_ = -1;
     127    int result = sam_itr_next(sf_, iter, read.bam_);
    129128#else
    130129  bool InBamFile::read(BamRead& read, bam_iter_t iter)
    131130  {
    132131    assert(sf_->type & 1); // no random access from sam files
    133     int result_ = bam_iter_read(sf_->x.bam, iter, read.bam_);
    134 #endif
    135     if (result_<-1) {
     132    int result = bam_iter_read(sf_->x.bam, iter, read.bam_);
     133#endif
     134    if (result<-1) {
    136135      std::ostringstream ss;
    137136      ss << "read(2): invalid bam file '" << filename() << "'";
    138       if (result_ == -2)
     137      if (result == -2)
    139138        ss << " truncated file";
    140139      else
    141         ss << " error: " << result_;
     140        ss << " error: " << result;
    142141      throw utility::runtime_error(ss.str());
    143142    }
    144     return result_>=0;
     143    return result>=0;
    145144  }
    146145
  • trunk/yat/omic/BamHeader.cc

    r3352 r3358  
    4040
    4141
    42   void BamHeader::parse_region(const std::string& reg, int& tid, int& begin,
     42  void BamHeader::parse_region(const std::string& reg, int& id, int& begin,
    4343                               int& end) const
    4444  {
    4545    assert(header_);
    4646#if YAT_HAVE_HTSLIB
    47     assert(0 && "FIXME: parse_region not implement against htslib");
     47    const char* b = reg.c_str();
     48    const char* e = hts_parse_reg(b, &begin, &end);
     49    // If begin > end suggests something is wrong and that is also how
     50    // bam_parse_region (below in samtools impl) used to detect error
     51    // and return non-zero.
     52    if (begin<=end) {
     53      std::string chr = reg.substr(0, e-b);
     54      try {
     55        id = tid(chr);
     56        return;
     57      }
     58      catch (utility::runtime_error& e) {
     59        ; // throw below instead
     60      }
     61    }
    4862#else
    49     if (!bam_parse_region(header_, reg.c_str(), &tid, &begin, &end))
     63    if (!bam_parse_region(header_, reg.c_str(), &id, &begin, &end))
    5064      return;
    5165#endif
     
    7387  {
    7488#if YAT_HAVE_HTSLIB
    75     return bam_name2id(header_, name.c_str());
     89    int res = bam_name2id(header_, name.c_str());
     90    if (res==-1) {
     91      std::string msg("invalid segment name:");
     92      msg += name;
     93      throw utility::runtime_error(msg);
     94    }
     95    return res;
    7696#else
    7797    if (!header_->hash) {
  • trunk/yat/omic/BamReadIterator.cc

    r3353 r3358  
    113113  {
    114114#if YAT_HAVE_HTSLIB
    115     hts_itr_t* it = hts_itr_query(bf.index(), tid, begin, end, NULL);
     115    hts_itr_t* it = sam_itr_queryi(bf.index(), tid, begin, end);
    116116#else
    117117    bam_iter_t it = bam_iter_query(bf.index(), tid, begin, end);
Note: See TracChangeset for help on using the changeset viewer.