Changeset 3887


Ignore:
Timestamp:
Mar 25, 2020, 5:41:25 AM (2 months ago)
Author:
Peter
Message:

detect error from faidx_fetch_seq in ::fetch rather thasn in function calling ::fetch. closes #940

File:
1 edited

Legend:

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

    r3883 r3887  
    5858    res.seq_.reset(faidx_fetch_seq(faidx_.get(), chr.c_str(), begin, end,
    5959                                   &res.size_), free);
     60    // fetch failed
     61    if (!res.seq_) {
     62      // htslib documents that they communicate type of error with
     63      // setting size_ to either -1 or -2 (unknown chromosome).
     64      if (res.size_ == -2)
     65        throw_unknown_chr(chr); // throw
     66      std::ostringstream msg;
     67      msg << "failed fetching sequence for '" << chr << ":" << begin << "-"
     68          << end << "'";
     69      throw utility::runtime_error(msg.str());
     70    }
    6071  }
    61 
     72 
    6273
    6374  std::string Fasta::name(size_t i) const
     
    8394  {
    8495    Fasta::Sequence res;
    85     fetch(res, chr, 0, std::numeric_limits<int>::max());
    86     if (!res.seq_.get()) {
    87       // htslib documents that they communicate type of error with
    88       // setting size_ to either -1 or -2.
    89       if (res.size_ == -2)
    90         throw_unknown_chr(chr); // throw
    91       std::ostringstream msg;
    92       msg << "failed fetching sequence for '" << chr << "'";
    93       throw utility::runtime_error(msg.str());
     96    try {
     97      fetch(res, chr, 0, std::numeric_limits<int>::max());
     98    }
     99    catch (utility::runtime_error& e) {
     100      if (!res.seq_.get() && res.size_==-2) {
     101        std::ostringstream msg;
     102        msg << "failed fetching sequence for '" << chr << "'";
     103        throw utility::runtime_error(msg.str());
     104      }
     105      throw; // retrow e
    94106    }
    95107    return res;
     
    102114    Fasta::Sequence res;
    103115    fetch(res, chr, begin, end);
    104     if (!res.seq_.get()) {
    105       // FIXME, perhaps throw different classes to allow catcher to
    106       // easily distinguish the two cases below.
    107 
    108       // htslib documents that they communicate type of error with
    109       // setting size_ to either -1 or -2.
    110       if (res.size_ == -2)
    111         throw_unknown_chr(chr); // throw
    112       std::ostringstream msg;
    113       msg << "failed fetching sequence for '" << chr << ":" << begin << "-"
    114           << end << "'";
    115       throw utility::runtime_error(msg.str());
    116     }
     116    assert(res.seq_);
    117117    return res;
    118118  }
Note: See TracChangeset for help on using the changeset viewer.