-
Notifications
You must be signed in to change notification settings - Fork 3
/
basic-DNA-RNA-AA-routines.h
831 lines (705 loc) · 23 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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
#ifndef DNA_ROUTINES_H
#define DNA_ROUTINES_H
/* Todo: count DNA bases, guess data type, is AA, etc. */
// Changes 10/11.11.2016:
// * Removed a bug: (c == 'O' && c == 'U') should read (c == 'O' || c == 'U').
// The impact of this error is low. Basically, we overlook O or U as not allowed amino acids.
// Since they should not occur in normal amino acid sequences, it does not make much of a difference.
// * added the blosum symbols, lists and functions
// * added some upper lists and functions.
// * added a look-up table for the blosum symbols. This is much more efficient.
// * removed z from aa_symbols, aa_symbols_ext and _upper, since it as an ambiguity character.
#include <cstring>
#include <cctype>
static const char DNARNA_symbols[] = "aAcCgGtTuU";
static const char DNARNA_symbols_upper[] = "ACGTU";
static const char aa_symbols[] = "aArRnNdDcCeEqQgGhHiIlLkKmMfFpPsStTwWyYvVxX";
static const char aa_symbols_upper[] = "ARNDCEQGHILKMFPSTWYVX";
// Extended also includes: O and U:
static const char aa_symbols_ext[] = "aArRnNdDcCeEqQgGhHiIlLkKmMfFpPsStTwWyYvVxXuUoO*";
static const char aa_symbols_ext_upper [] = "ARNDCEQGHILKMFPSTWYVXUO*";
static const char non_aa_in_ABC [] = "BJOUZbjouz";
// AA ambiguity characters: J is a very rare ambiguity character also included in this set.
// J is not allowed in many programs.
static const char aa_ambig [] = "bBzZjJxX";
// Usually a safe list of allowed characters are those in the blosum matrix:
// Lists the symbols that are allowed in the blosum matrix: Contains B,Z but not J as ambiguity character.
// See also the look up tables: is_aa_blosum_code[] and is_aa_blosum_code_or_gap[]
static const char aa_symbols_blosum[] = "aArRnNdDcCeEqQzZgGhHiIlLkKmMfFpPsStTwWyYvVbBxX*";
static const char aa_symbols_blosum_upper [] = "ARNDCEQZGHILKMFPSTWYVBX*";
static const char non_aa_symbols_blosum[] = "jJoOuU";
static const char non_aa_symbols_blosum_upper [] = "JOU";
static const char DNARNA_iupac_symbols [] = "aAcCgGtTuURYSWryswKMBDkmbdHVNhvn";
static const char DNARNA_iupac_symbols_upper [] = "ACGTURYSWKMBDHVN";
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
// Includes the symbols which occur in the blosum matrices:
const int is_aa_blosum_code_lookup[] = {
0,0,0,0,0,0,0,0,0,0, // 0- 9
0,0,0,0,0,0,0,0,0,0, // 10-19
0,0,0,0,0,0,0,0,0,0, // 20-29
0,0,0,0,0,0,0,0,0,0, // 30-39
0,0,1,0,0,0,0,0,0,0, // 40-49 45: - is not included, 42: * included
0,0,0,0,0,0,0,0,0,0, // 50-59
0,0,0,0,0,1,1,1,1,1, // 60-69 63: ? is not included
1,1,1,1,0,1,1,1,1,0, // 70-79
1,1,1,1,1,0,1,1,1,1, // 80-89
1,0,0,0,0,0,0,1,1,1, // 90-99
1,1,1,1,1,1,0,1,1,1, //100-109
1,0,1,1,1,1,1,0,1,1, //110-119
1,1,1,0,0,0,0,0 //120-127
};
// Includes the symbols which occur in the blosum matrices and the gap character:
const int is_aa_blosum_code_or_gap_lookup[] = {
0,0,0,0,0,0,0,0,0,0, // 0- 9
0,0,0,0,0,0,0,0,0,0, // 10-19
0,0,0,0,0,0,0,0,0,0, // 20-29
0,0,0,0,0,0,0,0,0,0, // 30-39
0,0,1,0,0,1,0,0,0,0, // 40-49 45: - is included, 42: * included
0,0,0,0,0,0,0,0,0,0, // 50-59
0,0,0,0,0,1,1,1,1,1, // 60-69 63: ? is not included
1,1,1,1,0,1,1,1,1,0, // 70-79
1,1,1,1,1,0,1,1,1,1, // 80-89
1,0,0,0,0,0,0,1,1,1, // 90-99
1,1,1,1,1,1,0,1,1,1, //100-109
1,0,1,1,1,1,1,0,1,1, //110-119
1,1,1,0,0,0,0,0 //120-127
};
// Inlcudes all DNA symbols, no ambiguity characters
const char is_DNA_lookup[128] = {
0,0,0,0,0,0,0,0,0,0, // 0- 9
0,0,0,0,0,0,0,0,0,0, // 10-19
0,0,0,0,0,0,0,0,0,0, // 20-29
0,0,0,0,0,0,0,0,0,0, // 30-39
0,0,0,0,0,0,0,0,0,0, // 40-49
0,0,0,0,0,0,0,0,0,0, // 50-59
0,0,0,0,0,1,0,1,0,0, // 60-69 63:'?', 65:'A' to 69:'E'
0,1,0,0,0,0,0,0,0,0, // 70-79
0,0,0,0,1,0,0,0,0,0, // 80-89
0,0,0,0,0,0,0,1,0,1, // 90-99
0,0,0,1,0,0,0,0,0,0, //100-109
0,0,0,0,0,0,1,0,0,0, //110-119
0,0,0,0,0,0,0,0 //120-127
};
// Inlcudes all DNA symbols and gap '-', no ambiguity characters
const char is_DNA_or_GAP_lookup[128] = {
0,0,0,0,0,0,0,0,0,0, // 0- 9
0,0,0,0,0,0,0,0,0,0, // 10-19
0,0,0,0,0,0,0,0,0,0, // 20-29
0,0,0,0,0,0,0,0,0,0, // 30-39
0,0,0,0,0,1,0,0,0,0, // 40-49
0,0,0,0,0,0,0,0,0,0, // 50-59
0,0,0,0,0,1,0,1,0,0, // 60-69 63:'?', 65:'A' to 69:'E'
0,1,0,0,0,0,0,0,0,0, // 70-79
0,0,0,0,1,0,0,0,0,0, // 80-89
0,0,0,0,0,0,0,1,0,1, // 90-99
0,0,0,1,0,0,0,0,0,0, //100-109
0,0,0,0,0,0,1,0,0,0, //110-119
0,0,0,0,0,0,0,0 //120-127
};
// Includes all ambiguity characters as well as ?
const char is_DNA_or_AMBIG_lookup[128] = {
0,0,0,0,0,0,0,0,0,0, // 0- 9
0,0,0,0,0,0,0,0,0,0, // 10-19
0,0,0,0,0,0,0,0,0,0, // 20-29
0,0,0,0,0,0,0,0,0,0, // 30-39
0,0,0,0,0,0,0,0,0,0, // 40-49
0,0,0,0,0,0,0,0,0,0, // 50-59
0,0,0,1,0,1,1,1,1,0, // 60-69 63:'?', 65:'A' to 69:'E' .,.,.,?,.,A,B,C,D,E,
0,1,1,0,0,1,0,1,1,0, // 70-79 F,G,H,I,J,K,L,M,N,O,
0,0,1,1,1,0,1,1,0,1, // 80-89 U is not included P,Q,R,S,T,U,V,W,X,Y,
0,0,0,0,0,0,0,1,1,1, // 90-99 Z,.,.,.,.,.,.,a,b,c,
1,0,0,1,1,0,0,1,0,1, //100-109 d,e,f,g,h,i,j,k,l,m,
1,0,0,0,1,1,1,0,1,1, //110-119 n,o,p,q,r,s,t,u,b,w,
0,1,0,0,0,0,0,0 //120-127 x,y,z,
};
// Inlcudes all ambiguity characters as well as ? and -
const char is_DNA_or_AMBIG_or_GAP_lookup[128] = {
0,0,0,0,0,0,0,0,0,0, // 0- 9
0,0,0,0,0,0,0,0,0,0, // 10-19
0,0,0,0,0,0,0,0,0,0, // 20-29
0,0,0,0,0,0,0,0,0,0, // 30-39
0,0,0,0,0,1,0,0,0,0, // 40-49 45: - is included
0,0,0,0,0,0,0,0,0,0, // 50-59
0,0,0,1,0,1,1,1,1,0, // 60-69 63:'?', 65:'A' to 69:'E' .,.,.,?,.,A,B,C,D,E,
0,1,1,0,0,1,0,1,1,0, // 70-79 F,G,H,I,J,K,L,M,N,O,
0,0,1,1,1,0,1,1,0,1, // 80-89 U is not included P,Q,R,S,T,U,V,W,X,Y,
0,0,0,0,0,0,0,1,1,1, // 90-99 Z,.,.,.,.,.,.,a,b,c,
1,0,0,1,1,0,0,1,0,1, //100-109 d,e,f,g,h,i,j,k,l,m,
1,0,0,0,1,1,1,0,1,1, //110-119 n,o,p,q,r,s,t,u,b,w,
0,1,0,0,0,0,0,0 //120-127 x,y,z,
};
// Inlcudes all ambiguity characters as well as ?. Does not include DNA/RNA characters.
const char is_DNA_AMBIG_lookup[128] = {
0,0,0,0,0,0,0,0,0,0, // 0- 9
0,0,0,0,0,0,0,0,0,0, // 10-19
0,0,0,0,0,0,0,0,0,0, // 20-29
0,0,0,0,0,0,0,0,0,0, // 30-39
0,0,0,0,0,0,0,0,0,0, // 40-49 45: - is not included
0,0,0,0,0,0,0,0,0,0, // 50-59
0,0,0,1,0,0,1,0,1,0, // 60-69 63:'?', 65:'A' to 69:'E' .,.,.,?,.,A,B,C,D,E,
0,0,1,0,0,1,0,1,1,0, // 70-79 F,G,H,I,J,K,L,M,N,O,
0,0,1,1,0,0,1,1,0,1, // 80-89 U is not included P,Q,R,S,T,U,V,W,X,Y,
0,0,0,0,0,0,0,0,1,0, // 90-99 Z,.,.,.,.,.,.,a,b,c,
1,0,0,0,1,0,0,1,0,1, //100-109 d,e,f,g,h,i,j,k,l,m,
1,0,0,0,1,1,0,0,1,1, //110-119 n,o,p,q,r,s,t,u,v,w,
0,1,0,0,0,0,0,0 //120-127 x,y,z,
};
// Inlcudes all non R/Y ambiguity characters as well as ?. Does not include DNA/RNA characters.
const char is_DNA_AMBIG_non_R_Y_lookup[128] = {
0,0,0,0,0,0,0,0,0,0, // 0- 9
0,0,0,0,0,0,0,0,0,0, // 10-19
0,0,0,0,0,0,0,0,0,0, // 20-29
0,0,0,0,0,0,0,0,0,0, // 30-39
0,0,0,0,0,0,0,0,0,0, // 40-49 45: - is not included
0,0,0,0,0,0,0,0,0,0, // 50-59
0,0,0,1,0,0,1,0,1,0, // 60-69 63:'?', 65:'A' to 69:'E' .,.,.,?,.,A,B,C,D,E,
0,0,1,0,0,1,0,1,1,0, // 70-79 F,G,H,I,J,K,L,M,N,O,
0,0,0,1,0,0,1,1,0,0, // 80-89 U is not included P,Q,R,S,T,U,V,W,X,Y,
0,0,0,0,0,0,0,0,1,0, // 90-99 Z,.,.,.,.,.,.,a,b,c,
1,0,0,0,1,0,0,1,0,1, //100-109 d,e,f,g,h,i,j,k,l,m,
1,0,0,0,0,1,0,0,1,1, //110-119 n,o,p,q,r,s,t,u,v,w,
0,0,0,0,0,0,0,0 //120-127 x,y,z,
};
/* 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; */
/* } */
// Only defined if c <= 127
inline bool is_DNA_base(char c)
{
return is_DNA_lookup[(int)c];
}
inline bool is_DNA_base_or_GAP(char c)
{
return is_DNA_or_GAP_lookup[(int)c];
}
inline bool is_DNA_or_DNA_ambig(char c)
{
return is_DNA_or_AMBIG_lookup[(int)c];
}
inline bool is_DNA_or_DNA_ambig_or_GAP(char c)
{
return is_DNA_or_AMBIG_or_GAP_lookup[(int)c];
}
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
{
// Only one character is not allowed:
if (c=='o' || c == 'O')
return false;
if (c >='a' && c <= 'z')
{
return true;
}
else if (c >='A' && c <= 'Z')
{
return true;
}
return false;
}
inline bool is_gap(char c)
{
return c == '-';
}
// Only defined if c <= 127
// Includes only DNA ambig symbols. Does not include DNA symbols. See also is_DNA_or_AMBIG below.
inline bool is_DNA_ambig(char c)
{
return is_DNA_AMBIG_lookup[(int)c];
// return is_DNA_or_AMBIG_lookup[(int)c] && !is_DNA_lookup[(int)c];
/* if (c == 'N' || c == '?' || c == 'n' || */
/* 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 == 'h' || c == 'v') */
/* return true; */
/* else */
/* return false; */
}
/* inline bool is_DNA_iupac_ambig_upper(char c) */
/* { */
/* if (c == 'N' || c == '?' || */
/* c == 'R' || c == 'Y' || c == 'S' || c == 'W' || */
/* c == 'K' || c == 'M' || c == 'B' || c == 'D' || */
/* c == 'H' || c == 'V') */
/* return true; */
/* else */
/* return false; */
/* } */
inline bool is_DNA_ambig_non_RY(char c)
{
return is_DNA_AMBIG_non_R_Y_lookup[(int)c];
}
// A list can be found here: https://en.wikipedia.org/wiki/Amino_acid
// The acceptance of J as an ambiguous amino acid symbol is low.
// J does not occur in the blosm matrix and is not allowed in some programs.
inline bool 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 bool is_aa_blosum_code(unsigned char c)
{
return (is_aa_blosum_code_lookup[c] != 0);
}
inline bool is_aa_blosum_code_or_gap(unsigned char c)
{
return (is_aa_blosum_code_or_gap_lookup[c] != 0);
}
inline int is_aa_upper(char c)
{
if (c >='A' && c <= 'Z')
{
// AA ambigs:
if (c == 'B' || c == 'X' || c == 'J' || c == 'Z')
return false;
// The few symbols that represent nothing.
// Indeed they are listed as the 21st and 22nd amino acid in https://en.wikipedia.org/wiki/Amino_acid
// But they are usually not handled by programs, so we return false.
if (c == 'O' || c == 'U') // OU
return false;
return true;
}
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') // Only not allowed characters in a..z are: ou
return true;
}
else if (c >='A' && c <= 'Z')
{
if (c != 'O' && c != 'U') // Only not allowed characters in a..z are: 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;
case 'S': /*c = 'S';*/ break;
case 'W': /*c = 'W';*/ 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;
case 's': /*c = 's';*/ break;
case 'w': /*c = 'w';*/ 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;
}
}
inline void content_in_region_DNA(const char *beg, const char *end, unsigned &AT, unsigned &CG, unsigned &gap, unsigned &ambig, unsigned &unknown)
{
AT = 0;
CG = 0;
gap = 0;
ambig = 0;
unknown = 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;
else if (c == '-')
++gap;
else if (is_DNA_ambig(c) )
++ambig;
else
++unknown;
++beg;
}
}
inline bool is_aa_blosum_code_or_gap_sequence(const char *p1, const char *p2, unsigned *offending_pos)
{
const char *startp = p1;
while (p1 != p2)
{
if (!is_aa_blosum_code_or_gap(*p1) )
{
*offending_pos = p1 - startp;
return false;
}
++p1;
}
return true;
}
// Recoding symbols:
// A char can hold 8 bits, enough for 8 characters to be "in or out",
// to be switched on or off. Thus a char can be used to hold
// all bases including ambiguities as follows:
// Say A, C, G, T are the bits 1,2,3,4,
// the ambiguity {A,C} is 1+2 = 3
// A: 65, 97 -> 1
// C: 67, 99 -> 2
// G: 71,103 -> 4
// T: 84,116 -> 8
// R(AG): 82,114 -> 5
// Y(CT): 89,121 -> 10
// S(CG): 83,115 -> 6
// W(TA): 87,119 -> 9
// K(TG): 75,107 -> 12
// M(CA): 77,109 -> 3
// B(CTG): 66,98 -> 14
// D(ATG): 68,100 -> 13
// H(ATC): 72,104 -> 11
// V(ACG): 86,118 -> 7
// N(ACGT): 78,110 -> 15
// - 45 -> 127 !!!!
// ? 63 -> 15
const char ascii2recode_DNA[128] = {
0,0,0,0,0,0,0,0,0,0, // 0- 9
0,0,0,0,0,0,0,0,0,0, // 10-19
0,0,0,0,0,0,0,0,0,0, // 20-29
0,0,0,0,0,0,0,0,0,0, // 30-39
0,0,0,0,0,127,0,0,0,0, // 40-49
0,0,0,0,0,0,0,0,0,0, // 50-59
0,0,0,15,0,1,14,2,13,0, // 60-69
0,4,11,0,0,12,0,3,15,0, // 70-79
0,0,5,6,8,0,7,9,0,10, // 80-89
0,0,0,0,0,0,0,1,14,2, // 90-99
13,0,0,4,11,0,0,0,0,0, //100-109
0,0,0,0,5,0,8,0,7,9, //110-119
0,10,0,0,0,0,0,0 //120-127
};
const char recode2ascii_DNA[128] = {
0,65,67,77,71,82,83,86,84,87, // 0- 9
89,72,75,68,66,78,0,0,0,0, // 10-19
0,0,0,0,0,0,0,0,0,0, // 20-29
0,0,0,0,0,0,0,0,0,0, // 30-39
0,0,0,0,0,0,0,0,0,0, // 40-49
0,0,0,0,0,0,0,0,0,0, // 50-59
0,0,0,0,0,0,0,0,0,0, // 60-69
0,0,0,0,0,0,0,0,0,0, // 70-79
0,0,0,0,0,0,0,0,0,0, // 80-89
0,0,0,0,0,0,0,0,0,0, // 90-99
0,0,0,0,0,0,0,0,0,0, //100-109
0,0,0,0,0,0,0,0,0,0, //110-119
0,0,0,0,0,0,0,45 //120-127
};
const char recodeISDNAambig[128] = {
0,0,0,1,0,1,1,1,0,1, // 0- 9
1,1,1,1,1,1,0,0,0,0, // 10-19
0,0,0,0,0,0,0,0,0,0, // 20-29
0,0,0,0,0,0,0,0,0,0, // 30-39
0,0,0,0,0,0,0,0,0,0, // 40-49
0,0,0,0,0,0,0,0,0,0, // 50-59
0,0,0,0,0,0,0,0,0,0, // 60-69
0,0,0,0,0,0,0,0,0,0, // 70-79
0,0,0,0,0,0,0,0,0,0, // 80-89
0,0,0,0,0,0,0,0,0,0, // 90-99
0,0,0,0,0,0,0,0,0,0, //100-109
0,0,0,0,0,0,0,0,0,0, //110-119
0,0,0,0,0,0,0,0 //120-127
};
const char recodeISDNA[128] = {
0,1,1,0,1,0,0,0,1,0, // 0- 9
0,0,0,0,0,0,0,0,0,0, // 10-19
0,0,0,0,0,0,0,0,0,0, // 20-29
0,0,0,0,0,0,0,0,0,0, // 30-39
0,0,0,0,0,0,0,0,0,0, // 40-49
0,0,0,0,0,0,0,0,0,0, // 50-59
0,0,0,0,0,0,0,0,0,0, // 60-69
0,0,0,0,0,0,0,0,0,0, // 70-79
0,0,0,0,0,0,0,0,0,0, // 80-89
0,0,0,0,0,0,0,0,0,0, // 90-99
0,0,0,0,0,0,0,0,0,0, //100-109
0,0,0,0,0,0,0,0,0,0, //110-119
0,0,0,0,0,0,0,0 //120-127
};
// all but below: 0
// A: 1
// C: 2
// G: 3
// T: 4
// -: 127
const char ascii2simpleIndex_DNA[128] = {
0,0,0,0,0,0,0,0,0,0, // 0- 9
0,0,0,0,0,0,0,0,0,0, // 10-19
0,0,0,0,0,0,0,0,0,0, // 20-29
0,0,0,0,0,0,0,0,0,0, // 30-39
0,0,0,0,0,127,0,0,0,0, // 40-49
0,0,0,0,0,0,0,0,0,0, // 50-59
0,0,0,0,0,1,0,2,0,0, // 60-69
0,3,0,0,0,0,0,0,0,0, // 70-79
0,0,0,0,4,0,0,0,0,0, // 80-89
0,0,0,0,0,0,0,1,0,2, // 90-99
0,0,0,3,0,0,0,0,0,0, //100-109
0,0,0,0,0,0,4,0,0,0, //110-119
0,0,0,0,0,0,0,0 //120-127
};
const char simpleIndex2ascii_DNA[128] = {
0,65,67,71,84,0,0,0,0,0, // 0- 9
0,0,0,0,0,0,0,0,0,0, // 10-19
0,0,0,0,0,0,0,0,0,0, // 20-29
0,0,0,0,0,0,0,0,0,0, // 30-39
0,0,0,0,0,0,0,0,0,0, // 40-49
0,0,0,0,0,0,0,0,0,0, // 50-59
0,0,0,0,0,0,0,0,0,0, // 60-69
0,0,0,0,0,0,0,0,0,0, // 70-79
0,0,0,0,0,0,0,0,0,0, // 80-89
0,0,0,0,0,0,0,0,0,0, // 90-99
0,0,0,0,0,0,0,0,0,0, //100-109
0,0,0,0,0,0,0,0,0,0, //110-119
0,0,0,0,0,0,0,45 //120-127
};
inline unsigned char recode_DNA(unsigned char c)
{
return ascii2recode_DNA[c];
}
inline unsigned char backrecode_DNA(unsigned char c)
{
return recode2ascii_DNA[c];
}
// Only true of character is an ambiguity character for DNA in the iupaccode
inline unsigned char recode_is_DNA_ambig(unsigned char c)
{
return recodeISDNAambig[c];
}
inline unsigned char recode_is_DNA(unsigned char c)
{
return recodeISDNA[c];
}
// Recodes can store multiple DNA bases in one char. This function determines whether the base is present in the reode.
inline bool is_base_in_recode(unsigned char recode, unsigned char base)
{
return recode & recode_DNA(base);
}
inline bool is_valid_recode_DNA(unsigned char c)
{
return recodeISDNA[c];
}
inline bool is_valid_recode_DNA_or_DNAambig(unsigned char c)
{
return recodeISDNA[c] || recodeISDNAambig[c];
}
inline bool is_recode_gap(unsigned char c)
{
return (c == 127);
}
inline unsigned char simpleIndex2DNA(unsigned char c)
{
return simpleIndex2ascii_DNA[c];
}
inline unsigned char DNA2simpleIndex(unsigned char c)
{
return ascii2simpleIndex_DNA[c];
}
inline bool is_valid_simple_Index_DNA(unsigned char c)
{
return simpleIndex2ascii_DNA[c]!=0;
}
// A Ala Alanine 01 65
// R Arg Arginine 02 82
// N Asn Asparagine 04 78
// D Asp Aspartic acid 08 68
// C Cys Cysteine 16 67
// Q Gln Glutamine 32 81
// E Glu Glutamic acid 64 69
// G Gly Glycine 128 71
// H His Histidine 256 72
// I Ile Isoleucine 512 73
// L Leu Leucine 1024 76
// K Lys Lysine 2048 75
// M Met Methionine 4096 77
// F Phe Phenylalanine 8192 70
// P Pro Proline 16384 80
// S Ser Serine 32768 83
// T Thr Threonine 65536 84
// W Trp Tryptophan 131072 87
// Y Tyr Tyrosine 262144 89
// V Val Valine 524288 86
// - 45 -> 0
// ? 63 -> 1048575
// X 88 -> 1048575
/* const int ascii2recode_aa[128] = { */
/* 0,0,0,0,0,0,0,0,0,0, // 0- 9 */
/* 0,0,0,0,0,0,0,0,0,0, // 10-19 */
/* 0,0,0,0,0,0,0,0,0,0, // 20-29 */
/* 0,0,0,0,0,0,0,0,0,0, // 30-39 */
/* 0,0,0,0,0,64,0,0,0,0, // 40-49 */
/* 0,0,0,0,0,0,0,0,0,0, // 50-59 */
/* 0,0,0,15,0,1,14,2,13,0, // 60-69 */
/* 0,4,11,0,0,12,0,3,15,0, // 70-79 */
/* 0,0,5,6,8,0,7,9,0,10, // 80-89 */
/* 0,0,0,0,0,0,0,1,14,2, // 90-99 */
/* 13,0,0,4,11,0,0,0,0,0, //100-109 */
/* 0,0,0,0,5,0,8,0,7,9, //110-119 */
/* 0,10,0,0,0,0,0,0 //120-127 */
/*}; */
/* Not yet implemented:
const int32_t ascii2recode_AA[128] = {
0,0,0,0,0,0,0,0,0,0, // 0- 9
0,0,0,0,0,0,0,0,0,0, // 10-19
0,0,0,0,0,0,0,0,0,0, // 20-29
0,0,0,0,0,0,0,0,0,0, // 30-39
0,0,0,0,0,127,0,0,0,0, // 40-49
0,0,0,0,0,0,0,0,0,0, // 50-59
0,0,0,15,0,1,14,2,13,0, // 60-69
0,4,11,0,0,12,0,3,15,0, // 70-79
0,0,5,6,8,0,7,9,0,10, // 80-89
0,0,0,0,0,0,0,1,14,2, // 90-99
13,0,0,4,11,0,0,0,0,0, //100-109
0,0,0,0,5,0,8,0,7,9, //110-119
0,10,0,0,0,0,0,0 //120-127
};
const char recode2ascii_AA[128] = {
0,65,67,77,71,82,83,86,84,87, // 0- 9
89,72,75,68,66,78,0,0,0,0, // 10-19
0,0,0,0,0,0,0,0,0,0, // 20-29
0,0,0,0,0,0,0,0,0,0, // 30-39
0,0,0,0,0,0,0,0,0,0, // 40-49
0,0,0,0,0,0,0,0,0,0, // 50-59
0,0,0,0,0,0,0,0,0,0, // 60-69
0,0,0,0,0,0,0,0,0,0, // 70-79
0,0,0,0,0,0,0,0,0,0, // 80-89
0,0,0,0,0,0,0,0,0,0, // 90-99
0,0,0,0,0,0,0,0,0,0, //100-109
0,0,0,0,0,0,0,0,0,0, //110-119
0,0,0,0,0,0,0,45 //120-127
};
const char recodeISAAambig[128] = {
0,0,0,1,0,1,1,1,0,1, // 0- 9
1,1,1,1,1,1,0,0,0,0, // 10-19
0,0,0,0,0,0,0,0,0,0, // 20-29
0,0,0,0,0,0,0,0,0,0, // 30-39
0,0,0,0,0,0,0,0,0,0, // 40-49
0,0,0,0,0,0,0,0,0,0, // 50-59
0,0,0,0,0,0,0,0,0,0, // 60-69
0,0,0,0,0,0,0,0,0,0, // 70-79
0,0,0,0,0,0,0,0,0,0, // 80-89
0,0,0,0,0,0,0,0,0,0, // 90-99
0,0,0,0,0,0,0,0,0,0, //100-109
0,0,0,0,0,0,0,0,0,0, //110-119
0,0,0,0,0,0,0,0 //120-127
};
const char recodeISAA[128] = {
0,1,1,0,1,0,0,0,1,0, // 0- 9
0,0,0,0,0,0,0,0,0,0, // 10-19
0,0,0,0,0,0,0,0,0,0, // 20-29
0,0,0,0,0,0,0,0,0,0, // 30-39
0,0,0,0,0,0,0,0,0,0, // 40-49
0,0,0,0,0,0,0,0,0,0, // 50-59
0,0,0,0,0,0,0,0,0,0, // 60-69
0,0,0,0,0,0,0,0,0,0, // 70-79
0,0,0,0,0,0,0,0,0,0, // 80-89
0,0,0,0,0,0,0,0,0,0, // 90-99
0,0,0,0,0,0,0,0,0,0, //100-109
0,0,0,0,0,0,0,0,0,0, //110-119
0,0,0,0,0,0,0,0 //120-127
};
*/
#endif