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 = (char*)malloc(len+1); |
---|
69 | int p; |
---|
70 | |
---|
71 | if (!n) { |
---|
72 | GB_memerr(); |
---|
73 | return 0; |
---|
74 | } |
---|
75 | |
---|
76 | len--; |
---|
77 | for (p=0; len>=0; p++, len--) { |
---|
78 | n[p] = s[len]; |
---|
79 | } |
---|
80 | n[p] = 0; |
---|
81 | |
---|
82 | return n; |
---|
83 | } |
---|
84 | char *GBT_complementNucSequence(const char *s, int len, char T_or_U) { |
---|
85 | char *n = (char*)malloc(len+1); |
---|
86 | int p; |
---|
87 | |
---|
88 | for (p=0; p<len; p++) { |
---|
89 | n[p] = GBT_complementNucleotide(s[p], T_or_U); |
---|
90 | } |
---|
91 | n[p] = 0; |
---|
92 | |
---|
93 | return n; |
---|
94 | } |
---|
95 | |
---|
96 | NOT4PERL GB_ERROR GBT_determine_T_or_U(GB_alignment_type alignment_type, char *T_or_U, const char *supposed_target) { |
---|
97 | switch (alignment_type) |
---|
98 | { |
---|
99 | case GB_AT_RNA: *T_or_U = 'U'; break; |
---|
100 | case GB_AT_DNA: *T_or_U = 'T'; break; |
---|
101 | default: { |
---|
102 | *T_or_U = 0; |
---|
103 | return GBS_global_string("%s not available for alignment-type", supposed_target); |
---|
104 | } |
---|
105 | } |
---|
106 | return 0; |
---|
107 | } |
---|
108 | |
---|
109 | NOT4PERL void GBT_reverseComplementNucSequence(char *seq, long length, char T_or_U) { |
---|
110 | long i, l; |
---|
111 | for (i=0, l=length-1; i <= l; i++, l--) { |
---|
112 | char c = seq[i]; |
---|
113 | |
---|
114 | seq[i] = GBT_complementNucleotide(seq[l], T_or_U); |
---|
115 | seq[l] = GBT_complementNucleotide(c, T_or_U); |
---|
116 | } |
---|
117 | } |
---|