-
Notifications
You must be signed in to change notification settings - Fork 4
/
iupac.h
241 lines (222 loc) · 5.92 KB
/
iupac.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
/*
Pheniqs : PHilology ENcoder wIth Quality Statistics
Copyright (C) 2018 Lior Galanti
NYU Center for Genetics and System Biology
Author: Lior Galanti <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PHENIQS_IUPAC_H
#define PHENIQS_IUPAC_H
#include "include.h"
/* BAM Nucleic acid encoding
The BAM encoding fits an ambiguous nucleotide encoding in 4 bits
it is used internally by htslib
most of the pheniqs pipeline uses the same encoding but padded to 8 bits
Name hex char ambiguity
--------------------------------
= 0x0 =
A 0x1 T A
C 0x2 G C
M 0x3 K AC
G 0x4 C G
R 0x5 Y A G
S 0x6 S CG
V 0x7 B ACG
T 0x8 A T
W 0x9 W A T
Y 0xA R C T
H 0xB D AC T
K 0xC M GT
D 0xD H A GT
B 0xE V CGT
N 0xF N ACGT
*/
const uint8_t NO_NUCLEOTIDE = 0x0;
const uint8_t ADENINE = 0x1;
const uint8_t CYTOSINE = 0x2;
const uint8_t GUANINE = 0x4;
const uint8_t THYMINE = 0x8;
const uint8_t ANY_NUCLEOTIDE = 0xf;
const uint8_t IUPAC_CODE_SIZE = 0x10;
/* BAM to ambiguous ASCII
Convert an IUPAC ambiguous nucleic acid 4bit BAM encoding to ASCII
*/
const char BamToAmbiguousAscii[IUPAC_CODE_SIZE] = {
'=',
'A',
'C',
'M',
'G',
'R',
'S',
'V',
'T',
'W',
'Y',
'H',
'K',
'D',
'B',
'N'
};
/* BAM to Unambiguous ASCII
Convert IUPAC ambiguous nucleic acid 4bit BAM encoding to unambiguous ASCII
Ambiguous code is mapped to N
*/
const char BamToUnambiguousAscii[IUPAC_CODE_SIZE] = {
'=', // 0x0
'A', // A 0x1
'C', // C 0x2
'N', // AC 0x3
'G', // G 0x4
'N', // A G 0x5
'N', // CG 0x6
'N', // ACG 0x7
'T', // T 0x8
'N', // A T 0x9
'N', // C T 0xa
'N', // AC T 0xb
'N', // GT 0xc
'N', // A GT 0xd
'N', // CGT 0xe
'N' // ACGT 0xf
};
/* BAM to reverse complement BAM
Convert IUPAC ambiguous nucleic acid 4bit BAM encoding to reverse complement
*/
const char BamToReverseComplementBam[IUPAC_CODE_SIZE] = {
0x0,
0x8,
0x4,
0xc,
0x2,
0xa,
0x6,
0xe,
0x1,
0x9,
0x5,
0xd,
0x3,
0xb,
0x7,
0xf,
};
/* BAM to Unambiguous BAM
Convert IUPAC ambiguous nucleic acid 4bit BAM encoding to unambiguous
*/
const char BamToUnambiguousBam[IUPAC_CODE_SIZE] = {
0x0,
0x1,
0x2,
0xf,
0x4,
0xf,
0xf,
0xf,
0x8,
0xf,
0xf,
0xf,
0xf,
0xf,
0xf,
0xf,
};
/* ASCII to ambiguous BAM
Convert IUPAC ambiguous nucleic acid ASCII to 4bit BAM encoding
character may be either an IUPAC ambiguity code,
either lower or upper case, = for 0, or 0, 1, 2, 3 for 1, 2, 4, 8.
*/
const uint8_t AsciiToAmbiguousBam[256] = {
15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
1, 2, 4, 8, 15,15,15,15, 15,15,15,15, 15, 0,15,15,
15, 1,14, 2, 13,15,15, 4, 11,15,15,12, 15, 3,15,15,
15,15, 5, 6, 8,15, 7, 9, 15,10,15,15, 15,15,15,15,
15, 1,14, 2, 13,15,15, 4, 11,15,15,12, 15, 3,15,15,
15,15, 5, 6, 8,15, 7, 9, 15,10,15,15, 15,15,15,15,
15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15
};
static inline bool is_iupac_ambiguous(const char& c) {
switch(c) {
case 'A':
case 'C':
case 'M':
case 'G':
case 'R':
case 'S':
case 'V':
case 'T':
case 'W':
case 'Y':
case 'H':
case 'K':
case 'D':
case 'B':
case 'N':
return true;
break;
default:
return false;
break;
}
};
static inline bool is_iupac_unambiguous(const char& c) {
switch(c) {
case 'A':
case 'C':
case 'G':
case 'T':
case 'N':
return true;
break;
default:
return false;
break;
}
};
static inline bool is_iupac_strict_nucleotide(const char& c) {
switch(c) {
case 'A':
case 'C':
case 'G':
case 'T':
return true;
break;
default:
return false;
break;
}
};
static inline bool is_iupac_strict_bam_nucleotide(const uint8_t& c) {
switch(c) {
case 0x1:
case 0x2:
case 0x4:
case 0x8:
return true;
break;
default:
return false;
break;
}
};
#endif /* PHENIQS_IUPAC_H */