-
Notifications
You must be signed in to change notification settings - Fork 0
/
Helper.cpp
56 lines (44 loc) · 1.45 KB
/
Helper.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
45
46
47
48
49
50
51
52
53
54
55
56
#include "Helper.h"
using namespace std;
// Strip the leading directories and
// the last trailling suffix from a filename
string stripFilename(const string& filename) {
string out = stripDirectories(filename);
return stripExtension(out);
}
// Remove a single file extension from the filename
string stripExtension(const string& filename) {
size_t suffixPos = filename.find_last_of('.');
if(suffixPos == string::npos)
return filename; // no suffix
else
return filename.substr(0, suffixPos);
}
// Strip the leadering directories from a filename
string stripDirectories(const string& filename) {
size_t lastDirPos = filename.find_last_of('/');
if(lastDirPos == string::npos)
return filename; // no directories
else
return filename.substr(lastDirPos + 1);
}
std::string Helper::getReferenceName(BamTools::BamReader &reader, int referenceId) {
assert(referenceId >= 0 && referenceId < reader.GetReferenceCount());
return reader.GetReferenceData()[referenceId].RefName;
}
int numOfTheLongestPrefix(const string &s1, const string &s2)
{
assert(s1.size() == s2.size());
for (int i = 0; i < s1.size(); i++) {
if (s1[i] != s2[i]) return i;
}
return 0;
}
int numOfThelongestSuffix(const string &s1, const string &s2)
{
assert(s1.size() == s2.size());
for (int i = 0; i < s1.size(); i++) {
if (s1[s1.size() - 1 - i] != s2[s1.size() - 1 - i]) return i;
}
return 0;
}