-
Notifications
You must be signed in to change notification settings - Fork 0
/
basic-DNA-RNA-AA-routines.h
264 lines (213 loc) · 6.01 KB
/
basic-DNA-RNA-AA-routines.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
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
/* fast_TIGER (version 1.0), a program for computing TIGER rates
* (TIGER: Tree Independent Generation of Evolutionary Rates).
*
* Copyright (C) January 2015 by Paul Frandsen and Christoph Mayer
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, see <http://www.gnu.org/licenses/>.
*
* For any enquiries send an email to
* Paul Frandsen: paulbfrandsen@gmail.com
* or
* Christoph Mayer: c.mayer.zfmk@uni-bonn.de
*
* When publishing work that is based on the results of Fast_Tiger please cite:
*
* Frandsen, P.B., Calcott, B., Mayer, C., Lanfear, R., 2015, Automatic selection of
* partitioning schemes for phylogenetic analyses using iterative k-means clustering
* of site rates, BMC Evolutionary Biology 15:13.
*
*/
#ifndef DNA_ROUTINES_H
#define DNA_ROUTINES_H
/* Todo: count DNA bases, guess data type, is AA, etc. */
#include <cstring>
#include <cctype>
static const char DNARNA_symbols[] = "aAcCgGtTuU";
/////////static const faststring aa_symbols = "aArRnNdDbBcCeEqQzZgGhHiIlLkKmMfFpPsStTwWyYvVxX";
static const char aa_symbols[] = "aArRnNdDcCeEqQzZgGhHiIlLkKmMfFpPsStTwWyYvVxX";
static const char aa_symbols_ext[] = "aArRnNdDcCeEqQzZgGhHiIlLkKmMfFpPsStTwWyYvVxXUuOo*";
static const char non_aa_in_ABC [] = "BJOUZbjouz";
static const char DNARNA_iupac_symbols [] = "aAcCgGtTuURYSWryswKMBDkmbdHVNhvn";
static const char phylip_DNARNA_allowed_symbols [] = "?-nNaAcCgGtTuURYSWryswKMBDkmbdHVhvoOxX";
static const char phylip_neither_aa_dna_symbol [] = "jJzZ";
static const char allowed_non_ABC [] = "-?*";
// O and U are special amino acids that are usually not in the models.
// Chars that are not an aa symbol: B, J, O, U, Z
// X is the amibuity code
inline bool is_DNA_base_upper(char c)
{
if (c == 'A' || c == 'C' || c == 'G' || c == 'T' )
return true;
return false;
}
inline bool is_DNA_base_lower(char c)
{
if (c == 'a' || c == 'c' || c == 'g' || c == 't' )
return true;
return false;
}
inline bool is_DNA_base(char c)
{
if (c == 'A' || c == 'C' || c == 'G' || c == 'T' || c == 'a' || c == 'c' || c == 'g' || c == 't' )
return true;
return false;
}
inline bool is_DNA_or_RNA_base(char c)
{
if (c == 'A' || c == 'C' || c == 'G' || c == 'T' ||
c == 'a' || c == 'c' || c == 'g' || c == 't' || c == 'U' || c == 'u')
return true;
return false;
}
inline bool is_allowed_non_ABC(char c)
{
if (c == '-' || c == '?' || c == '*')
return true;
else
return false;
}
inline bool is_phylip_aa_dna_symbol(char c) // Does not include -? or similar
{
if (c >='a' && c <= 'z')
{
return true;
}
else if (c >='A' && c <= 'Z')
{
return true;
}
return false;
}
inline bool is_DNA_iupac_ambig(char c)
{
if (c == 'R' || c == 'Y' || c == 'S' || c == 'W' ||
c == 'r' || c == 'y' || c == 's' || c == 'w' ||
c == 'K' || c == 'M' || c == 'B' || c == 'D' ||
c == 'k' || c == 'm' || c == 'b' || c == 'd' ||
c == 'H' || c == 'V' || c == 'N' ||
c == 'h' || c == 'v' || c == 'n' || c == '?' )
return true;
else
return false;
}
inline int is_aa_ambig(char c)
{
if (c == 'b' || c == 'B' || c == '?' || c == 'x' || c == 'X' ||
c == 'j' || c == 'J' || c == 'z' || c == 'Z')
return true;
else
return false;
}
inline int is_aa_or_aa_ambig(char c) // includes '?' and B, Z, J, X
{
if (c >='a' && c <= 'z')
{
if (c != 'o' && c != 'u') // ou
return true;
}
else if (c >='A' && c <= 'Z')
{
if (c != 'O' && c != 'U') // OU
return true;
}
if (c == '?' || c == '*')
return true;
return false;
// return (strchr(aa_symbols, c) != NULL);
}
inline int is_aa_or_aa_ambig_extended(char c) // O and U are allowed // includes '?' and B, Z, J, X
{
if (c >='a' && c <= 'z')
{
return true;
}
else if (c >='A' && c <= 'Z')
{
return true;
}
if (c == '?' || c == '*')
return true;
return false;
// return (strchr(aa_symbols, c) != NULL);
}
inline char complementBase_of_upper(char c)
{
switch (c) {
case 'A': c = 'T'; break;
case 'T': c = 'A'; break;
case 'G': c = 'C'; break;
case 'C': c = 'G'; break;
case 'R': c = 'Y'; break;
case 'Y': c = 'R'; break;
case 'M': c = 'K'; break;
case 'K': c = 'M'; break;
case 'B': c = 'V'; break;
case 'V': c = 'B'; break;
case 'D': c = 'H'; break;
case 'H': c = 'D'; break;
case 'N': c = 'N'; break;
case '?': c = '?'; break;
case '-': c = '-'; break;
default:
c = '*';
break;
}
return c;
}
inline char complementBase_of_lower(char c)
{
switch (c) {
case 'a': c = 't'; break;
case 't': c = 'a'; break;
case 'g': c = 'c'; break;
case 'c': c = 'g'; break;
case 'r': c = 'y'; break;
case 'y': c = 'r'; break;
case 'm': c = 'k'; break;
case 'k': c = 'm'; break;
case 'b': c = 'v'; break;
case 'v': c = 'b'; break;
case 'd': c = 'h'; break;
case 'h': c = 'd'; break;
case 'n': c = 'n'; break;
case '?': c = '?'; break;
case '-': c = '-'; break;
default:
c = '*';
break;
}
return c;
}
inline char complementBase(char c)
{
if ( isupper(c) )
return complementBase_of_upper(c);
else
return complementBase_of_lower(c);
}
inline void CG_AT_content_in_region(const char *beg, const char *end, unsigned &AT, unsigned &CG)
{
AT = 0;
CG = 0;
char c;
while (beg != end)
{
c = *beg;
if (c == 'C' || c == 'c' || c == 'G' || c == 'g')
++CG;
else if (c == 'A' || c == 'a' || c == 'T' || c == 't')
++AT;
++beg;
}
}
#endif