-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.h
More file actions
executable file
·229 lines (196 loc) · 6.69 KB
/
Copy pathcommon.h
File metadata and controls
executable file
·229 lines (196 loc) · 6.69 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#ifndef TYPES_H_
#define TYPES_H_
#include <string>
#include <vector>
#include <cstring>
#include <cmath>
#include <climits>
#include <cstdlib>
#ifdef INLINE_DISABLED
#define INLINE
#else
#define INLINE inline
#endif
#define VERBOSE_CHANNEL std::cerr
#define DEBUG_CHANNEL std::cerr
#define DEFAULT_CHANNEL std::cout
/*
static inline std::string fast_description() {
std::string line(PACKAGE_NAME);
line.append(" version ");
line.append(PACKAGE_VERSION);
return line;
}
*/
#define text_delimitator '$'
#define masked_base 'N'
#define match_character '.'
#define removed_character '-'
typedef std::size_t t_size; ///< Type for Vectors or similar classes
//#define LONG_LENGTH
#ifdef LONG_LENGTH
typedef long int t_length; ///< Type for TEXT
#define MAX_T_LENGTH LONG_MAX ///< Max value for TEXT
#define SA_NOT_FOUND -1
#else
typedef int t_length; ///< Type for TEXT
#define MAX_T_LENGTH INT_MAX ///< Max value for TEXT
#define SA_NOT_FOUND -1
#endif
typedef unsigned short int t_char; ///< Type for char conversion
typedef unsigned short int t_errors; ///< Type for ERRORS
typedef t_errors t_errors_delta ;
typedef unsigned int t_pattern_length; ///< Type for PATTERN
typedef double t_quality; ///< Type for QUALITY VALUES
typedef std::vector<short unsigned int> t_quality_vector; ///< Vector with quality values
typedef std::string t_edit_string; ///< For future expansion
enum t_strand { forward_strand, reverse_strand, unknown_strand }; ///< Just an enumeration of possible strands
enum t_alignment { unique_alignment, multiple_alignments, alignments_not_found, quality_discarded, low_complexity, contamination, unknown_alignment };
enum t_masked { masked, not_masked };
/**
* Conversion from strand type to char type
*/
static inline char strand_to_char(const t_strand s) {
if (s == unknown_strand)
return '.';
else
return (s == forward_strand) ? '+' : '-';
}
/**
* Conversion from char type to strand type
*/
static inline t_strand char_to_strand(const char c) {
if (c == '+' or c == 'F')
return forward_strand;
else if (c == '-' or c == 'R')
return reverse_strand;
else
return unknown_strand;
}
#define unique_alignment_char 'U'
#define multiple_alignments_char 'M'
#define alignments_not_found_char 'N'
#define quality_discarded_char 'Q'
#define low_complexity_char 'L'
#define contamination_char 'C'
#define unknown_alignment_to_char '?'
#define unique_alignment_string "U"
#define multiple_alignments_string "M"
#define alignments_not_found_string "NF"
#define quality_discarded_string "QD"
#define low_complexity_string "LC"
#define contamination_string "C"
#define unknown_alignment_to_string "?"
/**
* Conversion from alignment type to char type
*/
static inline char alignment_to_char(const t_alignment a) {
switch (a) {
case unique_alignment : return unique_alignment_char;
case multiple_alignments : return multiple_alignments_char;
case alignments_not_found : return alignments_not_found_char;
case quality_discarded : return quality_discarded_char;
case low_complexity : return low_complexity_char;
case contamination : return contamination_char;
case unknown_alignment : return unknown_alignment_to_char;
}
return unknown_alignment_to_char;
}
/**
* Conversion from char type to alignment type
*/
static inline t_alignment char_to_alignment(char c) {
switch (c) {
case unique_alignment_char : return unique_alignment;
case 'R': // backward compatibility
case multiple_alignments_char : return multiple_alignments;
case alignments_not_found_char : return alignments_not_found;
case quality_discarded_char : return quality_discarded;
case low_complexity_char : return low_complexity;
case contamination_char : return contamination;
default : return unknown_alignment;
}
}
/**
* Conversion from alignment type to string type
*/
static inline std::string alignment_to_string(const t_alignment a) {
switch (a) {
case unique_alignment : return std::string(unique_alignment_string);
case multiple_alignments : return std::string(multiple_alignments_string);
case alignments_not_found : return std::string(alignments_not_found_string);
case quality_discarded : return std::string(quality_discarded_string);
case low_complexity : return std::string(low_complexity_string);
case contamination : return std::string(contamination_string);
case unknown_alignment : return std::string(unknown_alignment_to_string);
}
return std::string(unknown_alignment_to_string);
}
static inline char reverse_complement_standalone_char(const char c) {
switch (c) {
case 'A' : return 'T';
case 'T' : return 'A';
case 'C' : return 'G';
case 'G' : return 'C';
case 'U' : return 'A';
case 'R' : return 'Y';
case 'Y' : return 'R';
case 'M' : return 'K';
case 'K' : return 'M';
case 'W' : return 'S';
case 'S' : return 'W';
case 'B' : return 'V';
case 'V' : return 'B';
case 'D' : return 'H';
case 'H' : return 'D';
//case 'N' : return 'N';
//case 'X' : return 'X';
default : return c;
}
}
static inline std::string reverse_complement_standalone_str_length(const char *str, size_t length) {
std::string reverse;
t_size i = length;
while (i > 0)
reverse.push_back(reverse_complement_standalone_char(str[--i]));
return reverse;
}
static inline std::string reverse_complement_standalone_str(const char *str) {
return reverse_complement_standalone_str_length(str,strlen(str));
}
static inline std::string reverse_complement_standalone_str(const std::string & str) {
return reverse_complement_standalone_str_length(str.c_str(),str.length());
}
static inline std::string reverse_standalone_str_length(const char *str, size_t length) {
std::string reverse;
t_size i = length;
while (i > 0)
reverse.push_back(str[--i]);
return reverse;
}
static inline std::string reverse_standalone_str(const char *str) {
return reverse_standalone_str_length(str,strlen(str));
}
static inline std::string tolower(const std::string & old_string) {
std::string lower_string(old_string);
for (std::string::iterator iter = lower_string.begin(); iter != lower_string.end(); iter++) {
*iter = tolower(*iter);
}
return lower_string;
}
static inline std::string toupper(const std::string & old_string){
std::string upper_string(old_string);
for (std::string::iterator iter = upper_string.begin(); iter != upper_string.end(); iter++) {
*iter = toupper(*iter);
}
return upper_string;
}
#define CCT_LETTERS 4
static const char colorspace_conversion_table[CCT_LETTERS][CCT_LETTERS] = {
// A C G T
/* A */ { '0', '1', '2', '3' }, // 'AA' => 0, 'AC' => 1, 'AG' => 2, 'AT' => 3
/* C */ { '1', '0', '3', '2' }, // 'CA' => 1, 'CC' => 0, 'CG' => 3, 'CT' => 2
/* G */ { '2', '3', '0', '1' }, // 'GA' => 2, 'GC' => 3, 'GG' => 0, 'GT' => 1
/* T */ { '3', '2', '1', '0' } // 'TA' => 3, 'TC' => 2, 'TG' => 1, 'TT' => 0
};
#endif /*TYPES_H_*/