Initial check in of c++ short read programming library. These classes give functional...
[htsworkflow.git] / htswanalysis / src / SRLib / util.cpp
1 #include <string>
2 #include <vector>
3 #include <math.h>
4
5 #include "util.h"
6
7 using namespace std;
8
9 void split (const string& text, const string& separators, vector<string>& words) {
10     size_t n     = text.length ();
11     size_t start = text.find_first_not_of (separators);
12
13     while (start < n) {
14         size_t stop = text.find_first_of (separators, start);
15         if (stop > n) stop = n;
16         words.push_back (text.substr (start, stop-start));
17         start = text.find_first_not_of (separators, stop+1);
18     }
19 }
20
21 void revcomp(string& output, const string& input)
22 {
23   output = input;
24   unsigned int i;
25
26   for (i = 0; i < output.length(); ++i) { output[i] = input[input.length()-(i+1)]; }
27
28   for (unsigned int p1 = 0; p1 < output.length(); ++p1) {
29     if(output[p1] == 'a' || output[p1] == 'A') { output[p1] = 'T'; } 
30     else if(output[p1] == 'c' || output[p1] == 'C') { output[p1] = 'G'; } 
31     else if(output[p1] == 'g' || output[p1] == 'G') { output[p1] = 'C'; } 
32     else if(output[p1] == 't' || output[p1] == 'T') { output[p1] = 'A'; } 
33   }
34 }
35
36 double norm_prob(double x, double mu, double s) { 
37   return (1.0)/(s*sqrt(2*PI)) * exp(-0.5*(x-mu)*(x-mu)/(s*s)); 
38 }