1 | // =============================================================== // |
---|
2 | // // |
---|
3 | // File : adRevCompl.cxx // |
---|
4 | // Purpose : reverse / complement nucleotide sequences // |
---|
5 | // // |
---|
6 | // Coded by Ralf Westram (coder@reallysoft.de) in January 2001 // |
---|
7 | // Institute of Microbiology (Technical University Munich) // |
---|
8 | // http://www.arb-home.de/ // |
---|
9 | // // |
---|
10 | // =============================================================== // |
---|
11 | |
---|
12 | #include "arbdbt.h" |
---|
13 | #include <cctype> |
---|
14 | |
---|
15 | static char GBT_complementNucleotide(char c, char T_or_U) { |
---|
16 | char n = c; |
---|
17 | |
---|
18 | switch (c) |
---|
19 | { |
---|
20 | case 'A': n = T_or_U; break; // A <-> TU |
---|
21 | case 'a': n = tolower(T_or_U); break; |
---|
22 | case 'U': |
---|
23 | case 'T': n = 'A'; break; |
---|
24 | case 'u': |
---|
25 | case 't': n = 'a'; break; |
---|
26 | |
---|
27 | case 'C': n = 'G'; break; // C <-> G |
---|
28 | case 'c': n = 'g'; break; |
---|
29 | case 'G': n = 'C'; break; |
---|
30 | case 'g': n = 'c'; break; |
---|
31 | |
---|
32 | case 'M': n = 'K'; break; // M=A/C <-> TU/G=K |
---|
33 | case 'm': n = 'k'; break; |
---|
34 | case 'K': n = 'M'; break; |
---|
35 | case 'k': n = 'm'; break; |
---|
36 | |
---|
37 | case 'R': n = 'Y'; break; // R=A/G <-> TU/C=Y |
---|
38 | case 'r': n = 'y'; break; |
---|
39 | case 'Y': n = 'R'; break; |
---|
40 | case 'y': n = 'r'; break; |
---|
41 | |
---|
42 | case 'V': n = 'B'; break; // V=A/C/G <-> TU/G/C=B |
---|
43 | case 'v': n = 'b'; break; |
---|
44 | case 'B': n = 'V'; break; |
---|
45 | case 'b': n = 'v'; break; |
---|
46 | |
---|
47 | case 'H': n = 'D'; break; // H=A/C/TU <-> TU/G/A=D |
---|
48 | case 'h': n = 'd'; break; |
---|
49 | case 'D': n = 'H'; break; |
---|
50 | case 'd': n = 'h'; break; |
---|
51 | |
---|
52 | case 'S': // S = C/G <-> G/C=S |
---|
53 | case 's': |
---|
54 | case 'W': // W = A/TU <-> TU/A=W |
---|
55 | case 'w': |
---|
56 | case 'N': // N = A/C/G/TU |
---|
57 | case 'n': |
---|
58 | case '.': |
---|
59 | case '-': break; |
---|
60 | |
---|
61 | default: break; |
---|
62 | } |
---|
63 | |
---|
64 | return n; |
---|
65 | } |
---|
66 | |
---|
67 | char *GBT_reverseNucSequence(const char *s, int len) { |
---|
68 | char *n = ARB_alloc<char>(len+1); |
---|
69 | len--; |
---|
70 | |
---|
71 | int p; |
---|
72 | for (p=0; len>=0; p++, len--) { |
---|
73 | n[p] = s[len]; |
---|
74 | } |
---|
75 | n[p] = 0; |
---|
76 | |
---|
77 | return n; |
---|
78 | } |
---|
79 | char *GBT_complementNucSequence(const char *s, int len, char T_or_U) { |
---|
80 | char *n = ARB_alloc<char>(len+1); |
---|
81 | int p; |
---|
82 | |
---|
83 | for (p=0; p<len; p++) { |
---|
84 | n[p] = GBT_complementNucleotide(s[p], T_or_U); |
---|
85 | } |
---|
86 | n[p] = 0; |
---|
87 | |
---|
88 | return n; |
---|
89 | } |
---|
90 | |
---|
91 | NOT4PERL GB_ERROR GBT_determine_T_or_U(GB_alignment_type alignment_type, char *T_or_U, const char *supposed_target) { |
---|
92 | switch (alignment_type) |
---|
93 | { |
---|
94 | case GB_AT_RNA: *T_or_U = 'U'; break; |
---|
95 | case GB_AT_DNA: *T_or_U = 'T'; break; |
---|
96 | default: { |
---|
97 | *T_or_U = 0; |
---|
98 | return GBS_global_string("%s not available for alignment-type", supposed_target); |
---|
99 | } |
---|
100 | } |
---|
101 | return 0; |
---|
102 | } |
---|
103 | |
---|
104 | NOT4PERL void GBT_reverseComplementNucSequence(char *seq, long length, char T_or_U) { |
---|
105 | long i, l; |
---|
106 | for (i=0, l=length-1; i <= l; i++, l--) { |
---|
107 | char c = seq[i]; |
---|
108 | |
---|
109 | seq[i] = GBT_complementNucleotide(seq[l], T_or_U); |
---|
110 | seq[l] = GBT_complementNucleotide(c, T_or_U); |
---|
111 | } |
---|
112 | } |
---|