forked from ekg/smithwaterman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IndelAllele.cpp
62 lines (52 loc) · 1.32 KB
/
IndelAllele.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
57
58
59
60
61
62
#include "IndelAllele.h"
using namespace std;
bool IndelAllele::homopolymer(void) {
string::iterator s = sequence.begin();
char c = *s++;
while (s != sequence.end()) {
if (c != *s++) return false;
}
return true;
}
int IndelAllele::readLength(void) {
if (insertion) {
return length;
} else {
return 0;
}
}
int IndelAllele::referenceLength(void) {
if (insertion) {
return 0;
} else {
return length;
}
}
bool homopolymer(string sequence) {
string::iterator s = sequence.begin();
char c = *s++;
while (s != sequence.end()) {
if (c != *s++) return false;
}
return true;
}
ostream& operator<<(ostream& out, const IndelAllele& indel) {
string t = indel.insertion ? "i" : "d";
out << t << ":" << indel.position << ":" << indel.readPosition << ":" << indel.length << ":" << indel.sequence;
return out;
}
bool operator==(const IndelAllele& a, const IndelAllele& b) {
return (a.insertion == b.insertion
&& a.length == b.length
&& a.position == b.position
&& a.sequence == b.sequence);
}
bool operator!=(const IndelAllele& a, const IndelAllele& b) {
return !(a==b);
}
bool operator<(const IndelAllele& a, const IndelAllele& b) {
ostringstream as, bs;
as << a;
bs << b;
return as.str() < bs.str();
}