Skip to content

Commit 4d34d90

Browse files
committed
Merge branch 'jh_nov2018' into new_hts
2 parents 31f629f + e656a80 commit 4d34d90

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/GenomicRegion.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
#include <cassert>
44
#include <stdexcept>
55
#include <climits>
6+
#ifdef HAVE_C11
7+
#include <regex>
8+
#endif
69

710
// 4 billion
811
#define END_MAX 4000000000
@@ -275,6 +278,16 @@ int32_t GenomicRegion::DistanceBetweenEnds(const GenomicRegion &gr) const {
275278
return;
276279
} else {
277280
chr = hdr.Name2ID(tchr); //bam_name2id(hdr.get(), tchr.c_str());
281+
282+
// if tchr was not found in sequence dictionary, it's possible that we're
283+
// specifying our contigs in b37 style whereas dict is hg** style;
284+
// let's attempt to automatically convert [0-9XY]+ -> chr[0-9XY]+
285+
#ifdef HAVE_C11
286+
static std::regex b37_regex("[0-9XY]+");
287+
if(chr == -1 && std::regex_match(tchr, b37_regex)) {
288+
chr = hdr.Name2ID("chr" + tchr);
289+
}
290+
#endif
278291
}
279292
}
280293
}

0 commit comments

Comments
 (0)