15 const int STRLEN = 10005 ;
16 const double EPSILON = 1e-300;
17 const double MINEEL = 1.0;
18 const double ORIVALVE = 0.1;
19 const int RANGE = 201;
20 const int OLEN = 25; // overlap length, number of bases must not be in poly(A) tails
21 const int NBITS = 32; // use unsigned int, 32 bits per variable
23 bool verbose = true; // show detail intermediate outputs
25 inline bool isZero(double a) { return fabs(a) < 1e-8; }
26 inline bool isLongZero(double a) { return fabs(a) < 1e-30; }
28 // Assume char's range is -128..127
29 const int CHAR_RANGE = 128;
31 static std::vector<int> init_base2id() {
32 std::vector<int> vec(CHAR_RANGE, -1);
33 vec['a'] = vec['A'] = 0;
34 vec['c'] = vec['C'] = 1;
35 vec['g'] = vec['G'] = 2;
36 vec['t'] = vec['T'] = 3;
37 vec['n'] = vec['N'] = 4;
42 static const std::vector<int> base2id = init_base2id();
44 inline int get_base_id(char c) {
45 if (c < 0 || base2id[c] < 0) {
46 fprintf(stderr, "Found unknown sequence letter %c at function get_base_id!\n", c);
52 static std::vector<int> init_rbase2id() {
53 std::vector<int> vec(CHAR_RANGE, -1);
54 vec['a'] = vec['A'] = 3;
55 vec['c'] = vec['C'] = 2;
56 vec['g'] = vec['G'] = 1;
57 vec['t'] = vec['T'] = 0;
58 vec['n'] = vec['N'] = 4;
63 static const std::vector<int> rbase2id = init_rbase2id();
65 inline int get_rbase_id(char c) {
66 if (c < 0 || rbase2id[c] < 0) {
67 fprintf(stderr, "Found unknown sequence letter %c at function get_rbase_id!\n", c);
73 inline char getOpp(char c) {
75 case 'a' : return 't';
76 case 'c' : return 'g';
77 case 'g' : return 'c';
78 case 't' : return 'a';
79 case 'n' : return 'n';
80 case 'A' : return 'T';
81 case 'C' : return 'G';
82 case 'G' : return 'C';
83 case 'T' : return 'A';
84 case 'N' : return 'N';
86 fprintf(stderr, "Found unknown sequence letter %c!\n", c);
91 inline char getCharacter(int id) {
99 fprintf(stderr, "Found unknown id %d!\n", id);
104 static std::vector<unsigned int> init_mask_code() {
105 std::vector<unsigned int> vec(NBITS);
106 for (int i = 0; i < NBITS; i++) vec[i] = 1 << i;
110 static std::vector<unsigned int> mask_codes = init_mask_code();
112 inline std::string cleanStr(const std::string& str) {
113 int len = str.length();
117 while (fr < len && isspace(str[fr])) ++fr;
119 while (to >= 0 && isspace(str[to])) --to;
121 return (fr <= to ? str.substr(fr, to - fr + 1) : "");
124 void printTimeUsed(const time_t& a, const time_t& b, const char* filename = "") {
125 int hh = (b - a) / 3600;
126 int mm = (b - a) % 3600 / 60;
127 int ss = (b - a) % 60;
129 printf("Time Used : %d h %02d m %02d s\n", hh, mm, ss);
131 if (strcmp(filename, "")) {
132 FILE *fo = fopen(filename, "w");
133 fprintf(fo, "Time Used : %d h %02d m %02d s\n", hh, mm, ss);
138 void genReadFileNames(const char* readFN, int tagType, int read_type, int& s, char readFs[][STRLEN]){
139 const char tags[3][STRLEN] = {"un", "alignable", "max"};
142 if (read_type == 0 || read_type == 2) {
143 strcpy(suffix, "fa");
146 strcpy(suffix, "fq");
149 if (read_type == 0 || read_type == 1) {
151 sprintf(readFs[0], "%s_%s.%s", readFN, tags[tagType], suffix);
155 sprintf(readFs[0], "%s_%s_1.%s", readFN, tags[tagType], suffix);
156 sprintf(readFs[1], "%s_%s_2.%s", readFN, tags[tagType], suffix);
160 void exitWithError(const char* errmsg) {
161 fprintf(stderr, "%s\n", errmsg);
165 void pthread_exception(int rc) {
168 fprintf(stderr, "Error code: EAGAIN. Insufficient resources to create another thread, or a system-imposed limit on the number of threads was encountered.\n");
171 fprintf(stderr, "Error code: EINVAL. Invalid settings in attr if pthread_create() is called. Or the implementation has detected that the value specified by thread_id does not refer to a joinable thread if pthread_join() is called.\n");
174 fprintf(stderr, "Error code: EPERM. No permission to set the scheduling policy and parameters specified in attr.\n");
177 fprintf(stderr, "Error code: EDEADLK. A deadlock was detected (e.g., two threads tried to join with each other); or thread_id specifies the calling thread.");
180 fprintf(stderr, "Error code: ESRCH. No thread with thread_id could be found.\n");
182 default: fprintf(stderr, "Unknown error code: %d\n", rc);