14 const int STRLEN = 10005 ;
15 const double EPSILON = 1e-300;
16 const double MINEEL = 1.0;
17 const double ORIVALVE = 0.1;
18 const int RANGE = 201;
19 const int OLEN = 25; // overlap length, number of bases must not be in poly(A) tails
20 const int NBITS = 32; // use unsigned int, 32 bits per variable
22 bool verbose = true; // show detail intermediate outputs
24 inline bool isZero(double a) { return fabs(a) < 1e-8; }
25 inline bool isLongZero(double a) { return fabs(a) < 1e-30; }
27 // Assume char's range is -128..127
28 const int CHAR_RANGE = 128;
30 static std::vector<int> init_base2id() {
31 std::vector<int> vec(CHAR_RANGE, -1);
32 vec['a'] = vec['A'] = 0;
33 vec['c'] = vec['C'] = 1;
34 vec['g'] = vec['G'] = 2;
35 vec['t'] = vec['T'] = 3;
36 vec['n'] = vec['N'] = 4;
41 static const std::vector<int> base2id = init_base2id();
43 inline int get_base_id(char c) {
44 if (c < 0 || base2id[c] < 0) {
45 fprintf(stderr, "Found unknown sequence letter %c at function get_base_id!\n", c);
51 static std::vector<int> init_rbase2id() {
52 std::vector<int> vec(CHAR_RANGE, -1);
53 vec['a'] = vec['A'] = 3;
54 vec['c'] = vec['C'] = 2;
55 vec['g'] = vec['G'] = 1;
56 vec['t'] = vec['T'] = 0;
57 vec['n'] = vec['N'] = 4;
62 static const std::vector<int> rbase2id = init_rbase2id();
64 inline int get_rbase_id(char c) {
65 if (c < 0 || rbase2id[c] < 0) {
66 fprintf(stderr, "Found unknown sequence letter %c at function get_rbase_id!\n", c);
72 inline char getOpp(char c) {
74 case 'a' : return 't';
75 case 'c' : return 'g';
76 case 'g' : return 'c';
77 case 't' : return 'a';
78 case 'n' : return 'n';
79 case 'A' : return 'T';
80 case 'C' : return 'G';
81 case 'G' : return 'C';
82 case 'T' : return 'A';
83 case 'N' : return 'N';
85 fprintf(stderr, "Found unknown sequence letter %c!\n", c);
90 inline char getCharacter(int id) {
98 fprintf(stderr, "Found unknown id %d!\n", id);
103 static std::vector<unsigned int> init_mask_code() {
104 std::vector<unsigned int> vec(NBITS);
105 for (int i = 0; i < NBITS; i++) vec[i] = 1 << i;
109 static std::vector<unsigned int> mask_codes = init_mask_code();
111 inline std::string cleanStr(const std::string& str) {
112 int len = str.length();
116 while (fr < len && isspace(str[fr])) ++fr;
118 while (to >= 0 && isspace(str[to])) --to;
120 return (fr <= to ? str.substr(fr, to - fr + 1) : "");
123 void printTimeUsed(const time_t& a, const time_t& b, const char* filename = "") {
124 int hh = (b - a) / 3600;
125 int mm = (b - a) % 3600 / 60;
126 int ss = (b - a) % 60;
128 printf("Time Used : %d h %02d m %02d s\n", hh, mm, ss);
130 if (strcmp(filename, "")) {
131 FILE *fo = fopen(filename, "w");
132 fprintf(fo, "Time Used : %d h %02d m %02d s\n", hh, mm, ss);
137 void genReadFileNames(const char* readFN, int tagType, int read_type, int& s, char readFs[][STRLEN]){
138 const char tags[3][STRLEN] = {"un", "alignable", "max"};
141 if (read_type == 0 || read_type == 2) {
142 strcpy(suffix, "fa");
145 strcpy(suffix, "fq");
148 if (read_type == 0 || read_type == 1) {
150 sprintf(readFs[0], "%s_%s.%s", readFN, tags[tagType], suffix);
154 sprintf(readFs[0], "%s_%s_1.%s", readFN, tags[tagType], suffix);
155 sprintf(readFs[1], "%s_%s_2.%s", readFN, tags[tagType], suffix);