-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregion.cpp
44 lines (39 loc) · 1.48 KB
/
region.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "region.hpp"
namespace vg {
void parse_region(
string& region,
string& startSeq,
int& startPos,
int& stopPos) {
size_t foundFirstColon = region.find(":");
// we only have a single string, use the whole sequence as the target
if (foundFirstColon == string::npos) {
startSeq = region;
startPos = 0;
stopPos = -1;
} else {
startSeq = region.substr(0, foundFirstColon);
string sep = "..";
size_t foundRangeSep = region.find(sep, foundFirstColon);
if (foundRangeSep == string::npos) {
sep = "-";
foundRangeSep = region.find("-", foundFirstColon);
}
if (foundRangeSep == string::npos) {
startPos = atoi(region.substr(foundFirstColon + 1).c_str());
// differ from bamtools in this regard, in that we process only
// the specified position if a range isn't given
stopPos = startPos + 1;
} else {
startPos = atoi(region.substr(foundFirstColon + 1, foundRangeSep - foundFirstColon).c_str());
// if we have range sep specified, but no second number, read to the end of sequence
if (foundRangeSep + sep.size() != region.size()) {
stopPos = atoi(region.substr(foundRangeSep + sep.size()).c_str()); // end-exclusive, bed-format
} else {
//stopPos = reference.sequenceLength(startSeq);
stopPos = -1;
}
}
}
}
}