-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathutility.cpp
60 lines (53 loc) · 1.52 KB
/
utility.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
#include "utility.h"
short qualityChar2ShortInt(char c) {
return static_cast<short>(c) - 33;
}
char shortInt2QualityChar(short i) {
return static_cast<char>(i + 33);
}
long double qualityChar2LongDouble(char c) {
return static_cast<long double>(c) - 33;
}
long double averageQuality(const string& qualstr) {
long double qual = 0; //(long double) *max_element(quals.begin(), quals.end());
for (string::const_iterator q = qualstr.begin(); q != qualstr.end(); ++q)
qual += qualityChar2LongDouble(*q);
return qual / qualstr.size();
}
bool allATGC(string& s) {
for (string::iterator c = s.begin(); c != s.end(); ++c) {
char b = *c;
if (b != 'A' && b != 'T' && b != 'G' && b != 'C') {
return false;
}
}
return true;
}
bool allN(string& s) {
for (string::iterator c = s.begin(); c != s.end(); ++c) {
if (*c != 'N') {
return false;
}
}
return true;
}
string graph_mapping_to_string(gssw_graph_mapping* gm) {
gssw_graph_cigar* g = &gm->cigar;
int32_t i;
int32_t c = 0;
gssw_node_cigar* nc = g->elements;
stringstream gmss;
gmss << gm->score << "@" << gm->position << ":";
for (i = 0; i < g->length; ++i, ++nc) {
gmss << nc->node->id << "[";
gssw_cigar* c = nc->cigar;
int j;
int l = c->length;
gssw_cigar_element* e = c->elements;
for (j=0; j < l; ++j, ++e) {
gmss << e->length << e->type;
}
gmss << "]";
}
return gmss.str();
}