Skip to content

Commit

Permalink
Merge pull request #5 from Illumina/RepeatSpecChromCheck
Browse files Browse the repository at this point in the history
Throw exception if can't extract region from ref
  • Loading branch information
egor-dolzhenko authored Mar 22, 2017
2 parents d347b94 + 4b4d0e2 commit 766d6f3
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/ref_genome.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,27 @@
using std::string;
#include <stdexcept>

/*****************************************************************************/

RefGenome::RefGenome(const string& genome_path) : genome_path_(genome_path) {
fai_ptr_ = fai_load(genome_path_.c_str());
}

/*****************************************************************************/

RefGenome::~RefGenome() { fai_destroy(fai_ptr_); }

// Load reference sequence specified by region.
void RefGenome::ExtractSeq(const string& region, string* sequence) const {
int len; // throwaway...
char* ref_tmp(fai_fetch(fai_ptr_, region.c_str(), &len));

if (!ref_tmp) {
std::runtime_error("Can't find sequence region '" + region +
"' in reference file: '" + genome_path_ + "'");
char* ref_tmp = fai_fetch(fai_ptr_, region.c_str(), &len);

if (!ref_tmp || len == -1 || len == -2) {
throw std::runtime_error("ERROR: can't extract " + region + " from "
+ genome_path_ + "; in particular, chromosome names must match "
"exactly (e.g. \"chr1\" and \"1\" are distinct names)");
}

sequence->assign(ref_tmp);
free(ref_tmp);

std::transform(sequence->begin(), sequence->end(), sequence->begin(),
::toupper);
}

/*****************************************************************************/
}

0 comments on commit 766d6f3

Please sign in to comment.