ARB
adRevCompl.cxx
Go to the documentation of this file.
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  case 'A': n = T_or_U; break; // A <-> TU
20  case 'a': n = tolower(T_or_U); break;
21  case 'U':
22  case 'T': n = 'A'; break;
23  case 'u':
24  case 't': n = 'a'; break;
25 
26  case 'C': n = 'G'; break; // C <-> G
27  case 'c': n = 'g'; break;
28  case 'G': n = 'C'; break;
29  case 'g': n = 'c'; break;
30 
31  case 'M': n = 'K'; break; // M=A/C <-> TU/G=K
32  case 'm': n = 'k'; break;
33  case 'K': n = 'M'; break;
34  case 'k': n = 'm'; break;
35 
36  case 'R': n = 'Y'; break; // R=A/G <-> TU/C=Y
37  case 'r': n = 'y'; break;
38  case 'Y': n = 'R'; break;
39  case 'y': n = 'r'; break;
40 
41  case 'V': n = 'B'; break; // V=A/C/G <-> TU/G/C=B
42  case 'v': n = 'b'; break;
43  case 'B': n = 'V'; break;
44  case 'b': n = 'v'; break;
45 
46  case 'H': n = 'D'; break; // H=A/C/TU <-> TU/G/A=D
47  case 'h': n = 'd'; break;
48  case 'D': n = 'H'; break;
49  case 'd': n = 'h'; break;
50 
51  case 'S': // S = C/G <-> G/C=S
52  case 's':
53  case 'W': // W = A/TU <-> TU/A=W
54  case 'w':
55  case 'N': // N = A/C/G/TU
56  case 'n':
57  case '.':
58  case '-': break;
59 
60  default: break;
61  }
62 
63  return n;
64 }
65 
66 char *GBT_reverseNucSequence(const char *s, int len) {
67  char *n = ARB_alloc<char>(len+1);
68  len--;
69 
70  int p;
71  for (p=0; len>=0; p++, len--) {
72  n[p] = s[len];
73  }
74  n[p] = 0;
75 
76  return n;
77 }
78 char *GBT_complementNucSequence(const char *s, int len, char T_or_U) {
79  char *n = ARB_alloc<char>(len+1);
80  int p;
81 
82  for (p=0; p<len; p++) {
83  n[p] = GBT_complementNucleotide(s[p], T_or_U);
84  }
85  n[p] = 0;
86 
87  return n;
88 }
89 
90 NOT4PERL GB_ERROR GBT_determine_T_or_U(GB_alignment_type alignment_type, char *T_or_U, const char *supposed_target) {
91  switch (alignment_type) {
92  case GB_AT_RNA: *T_or_U = 'U'; break;
93  case GB_AT_DNA: *T_or_U = 'T'; break;
94  default: {
95  *T_or_U = 0;
96  return GBS_global_string("%s not available for alignment-type", supposed_target);
97  }
98  }
99  return NULp;
100 }
101 
102 NOT4PERL void GBT_reverseComplementNucSequence(char *seq, long length, char T_or_U) {
103  long i, l;
104  for (i=0, l=length-1; i <= l; i++, l--) {
105  char c = seq[i];
106 
107  seq[i] = GBT_complementNucleotide(seq[l], T_or_U);
108  seq[l] = GBT_complementNucleotide(c, T_or_U);
109  }
110 }
char * GBT_complementNucSequence(const char *s, int len, char T_or_U)
Definition: adRevCompl.cxx:78
const char * GB_ERROR
Definition: arb_core.h:25
NOT4PERL void GBT_reverseComplementNucSequence(char *seq, long length, char T_or_U)
Definition: adRevCompl.cxx:102
const char * GBS_global_string(const char *templat,...)
Definition: arb_msg.cxx:203
static char GBT_complementNucleotide(char c, char T_or_U)
Definition: adRevCompl.cxx:15
FILE * seq
Definition: rns.c:46
#define NOT4PERL
Definition: arbdb_base.h:23
NOT4PERL GB_ERROR GBT_determine_T_or_U(GB_alignment_type alignment_type, char *T_or_U, const char *supposed_target)
Definition: adRevCompl.cxx:90
char * GBT_reverseNucSequence(const char *s, int len)
Definition: adRevCompl.cxx:66
GB_alignment_type
Definition: arbdb_base.h:61
#define NULp
Definition: cxxforward.h:116
size_t length
GB_write_int const char s
Definition: AW_awar.cxx:154