-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.h
122 lines (104 loc) · 3.16 KB
/
main.h
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#ifndef MAIN_H_
#define MAIN_H_
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <utility>
#include <getopt.h>
#include <algorithm>
#include "option.h"
using namespace std;
typedef unsigned long ulong;
typedef map<char,double> mCharDouble;
typedef map<char, ulong> mCharUlong;
typedef map<string,ulong> mStrUlong;
typedef map<string, vector<string> > mStrStrV;
typedef pair<char,ulong> pCharUlong;
typedef pair<string,ulong> pStrUlong;
typedef pair<double, set<char> > pDoubleCharSet;
typedef pair<char,double> pCharDouble;
typedef vector< set<char> > vCharSet;
typedef vector<string> vString;
// descending sort pair
inline bool _cmpByFirst(const pDoubleCharSet &a, const pDoubleCharSet &b) { return a.first > b.first; }
inline bool _cmpBySecond(const pCharUlong &a, const pCharUlong &b) { return a.second > b.second; }
inline bool _cmpBySecond_StrUlong(const pStrUlong &a, const pStrUlong &b) { return a.second > b.second; }
inline bool _cmpBySecond_CharDouble(const pCharDouble &a, const pCharDouble &b) { return a.second > b.second; }
void replace (string &str, const string &from, const string &to, size_t more=0 );
mStrUlong fetchInDel(string &seq, char type);
vector< pair<string, ulong> > selectInDel( const mStrUlong &m );
string adjust_p(const string &qs, const Option &opt);
inline double errorRate(const char &q, const Option &opt)
{
return pow( 10, (double)(opt.phredOffset-(int)q)/10 );
}
inline vector<double> quaToErrorRate(const string &qs, const Option &opt)
{
vector<double> eV;
for ( size_t i(0); i != qs.size(); i++ ) eV.push_back( errorRate(qs[i], opt) );
return eV;
}
inline string _itoa( size_t &i )
{
ostringstream osm;
osm << i;
return osm.str();
}
inline ulong countN(const string &s)
{
ulong n(0);
for ( size_t i(0); i != s.size(); i++ ) {
if ( s[i] == 'N' ) n++;
}
return n;
}
inline bool lowQuality(const char &q, const Option &opt)
{
return ( int(q) - opt.phredOffset < opt.baseQuaCutoff );
}
inline string reverseComplement(const string &seq)
{
string str("");
for ( string::const_reverse_iterator it = seq.rbegin(); it != seq.rend(); it++) {
switch (*it) {
case 'A': str += "T"; break;
case 'C': str += "G"; break;
case 'G': str += "C"; break;
case 'T': str += "A"; break;
case 'N':
default: str += "N"; break;
}
}
return str;
}
inline void convertBase(string &seq, char &ref)
{
for ( auto &i : seq ) {
switch(i) {
case 'a': i = 'A'; break;
case 'c': i = 'C'; break;
case 'g': i = 'G'; break;
case 't': i = 'T'; break;
case 'n': i = 'N'; break;
case '.':
case ',': i = ref; break;
default: break;
}
}
}
inline mCharUlong countBaseNum(const string &s)
{
mCharUlong m;
for ( auto &i : s ) m[i]++;
return m;
}
inline char errorRateToChar(const double &q, const Option &opt)
{
return char( opt.phredOffset - (int)(-10 * log(q) / log(10.0) ) );
}
#endif // MAIN_H_