forked from k-medai/CASPER
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.h
51 lines (40 loc) · 1.71 KB
/
util.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
#include <fstream>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <sstream>
#define RESET "\e[0m"
#define BOLD "\e[1m"
#define UNDERLINE "\e[4m"
using namespace std;
/*------------------------------------------------
A->T, C->G, G->C, T->A, N->N
------------------------------------------------*/
const unsigned char base_complement[128] = {
'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N',
'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N',
'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N',
'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N',
'N', /*A*/ 'T', 'N', /*C*/ 'G', 'N', 'N', 'N', /*G*/ 'C', 'N', 'N', 'N', 'N', 'N', 'N', /*N*/'N', 'N',
'N', 'N', 'N', 'N', /*T*/ 'A', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N',
'N', /*a*/ 't', 'N', /*c*/ 'g', 'N', 'N', 'N', /*g*/ 'c', 'N', 'N', 'N', 'N', 'N', 'N', /*n*/'n', 'N',
'N', 'N', 'N', 'N', /*t*/ 'a', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N'
};
extern void open_inputfile( ifstream &fp, const char *filename );
extern void open_outputfile( ofstream &fp, const string & filename );
extern void check_firstline( const string &data );
extern string itoa( const int number );
// Reverse a string
static inline string reverse( const string &ori_str ) {
string rev_str="";
for( int i=ori_str.size()-1; i>=0; i-- )
rev_str += ori_str[i];
return rev_str;
}
// Reverse & Complement a string
static inline string reverse_complement(const string &ori_str ) {
string rev_str="";
for( int i=ori_str.size()-1; i>=0; i-- )
rev_str += base_complement[ (unsigned char)ori_str[i] ];
return rev_str;
}