modified: myjupyterlab.sh
[GalaxyCodeBases.git] / released / pIRS.old / stat_illumina_reads / gcvgstater / self_util.cpp
blob765f74202a2a8e18467d949829d7d6692f0a8a4d
1 #include <string>
2 #include <sstream>
3 #include <iostream>
4 #include "self_util.h"
6 using namespace std;
8 char alphabet[128] =
10 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
11 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
12 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
13 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
14 4, 0, 4, 1, 4, 4, 4, 2, 4, 4, 4, 4, 4, 4, 0, 4,
15 4, 4, 4, 4, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
16 4, 0, 4, 1, 4, 4, 4, 2, 4, 4, 4, 4, 4, 4, 0, 4,
17 4, 4, 4, 4, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4
20 char bases[5] =
22 'A', 'C', 'G', 'T', 'N'
25 char c_bases[5] =
27 'T', 'G', 'C', 'A', 'N'
30 uint64_t seq2bit(string &kseq)
32 uint64_t kbit=0;
34 for(int i=0; i<kseq.size(); i++)
36 kbit=(kbit<<2)|alphabet[kseq[i]];
39 return kbit;
42 string bit2seq(uint64_t kbit, int kmerSize)
44 string kseq;
46 for(int i=0; i<kmerSize; i++)
48 kseq.push_back(bases[(kbit>>(kmerSize-1-i)*2)&0x3]);
51 return kseq;
54 bool check_seq(string &seq)
56 bool is_good = true;
57 for (int i = 0; i < seq.size(); i++)
59 if (alphabet[seq[i]] == 4)
61 is_good = false;
62 break;
66 return is_good;
70 void reverse_complement (string &in_str, string &out_str)
72 for (int64_t i=in_str.size()-1; i>=0; i--)
74 out_str.push_back(c_bases[alphabet[in_str[i]]]);
78 void TrimRight(string& str)
80 int pos = str.length() - 1;
81 if(pos >= 0)
83 char c = str[pos];
84 while((c == '\t') || (c == '\n') || (c == ' '))
86 str = str.substr(0, pos);
87 pos = str.length() - 1;
88 if(pos < 0)
90 break;
92 c = str[pos];
97 void TrimLeft(string& str)
99 if(str.length() > 0)
101 char c = str[0];
102 while((c == '\t') || (c == '\n') || (c == ' '))
104 str = str.substr(1);
105 if(str.length() == 0)
107 break;
109 c = str[0];
114 vector<string> splitString(string str, string delims)
116 vector<string> vec;
117 string temp;
118 //const string delims(" \t\n");
119 string::size_type begIdx, endIdx;
120 begIdx = str.find_first_not_of(delims);
121 while(begIdx != string::npos)
123 endIdx = str.find_first_of(delims, begIdx);
124 if(endIdx == string::npos)
126 endIdx == str.length();
129 vec.push_back(str.substr(begIdx, endIdx-begIdx));
130 begIdx = str.find_first_not_of(delims, endIdx);
132 return vec;
135 vector<int> splitStringToInt(string str, string delims)
137 vector<int> vec;
138 string temp;
139 string::size_type begIdx, endIdx;
140 begIdx = str.find_first_not_of(delims);
141 while(begIdx != string::npos)
143 endIdx = str.find_first_of(delims, begIdx);
144 if(endIdx == string::npos)
146 endIdx == str.length();
148 vec.push_back(toInt(str.substr(begIdx, endIdx-begIdx)));
149 begIdx = str.find_first_not_of(delims, endIdx);
151 return vec;
154 int toInt(string str)
156 int i;
157 stringstream ss;
158 //int prec = numeric_limits<int>::digits10;
159 //ss.precision(prec);
160 ss << str;
161 ss >> i;
162 return i;
165 uint64_t toUint64(string str)
167 int i;
168 stringstream ss;
169 //int prec = numeric_limits<int>::digits10;
170 //ss.precision(prec);
171 ss << str;
172 ss >> i;
173 return i;
176 char toUpper(const char& ch)
178 if(islower(ch))
180 return ch & 0x5F;
184 char toLower(const char& ch)
186 if(isupper(ch))
188 return ch | 0x20;
191 string ToUpper(string str)
193 string temp = "";
194 for(int i=0; i<str.length(); ++i)
196 temp += toUpper(str[i]);
198 return temp;
201 string ToLower(string str)
203 string temp = "";
204 //transform (str.begin(),str.end(), temp.begin(), toLower);
205 for(int i=0; i<str.length(); ++i)
207 temp += toUpper(str[i]);
209 return temp;