Victor
 All Data Structures Functions Variables Friends Pages
NucleotideCode.h
1 /* This file is part of Victor.
2 
3  Victor is free software: you can redistribute it and/or modify
4  it under the terms of the GNU General Public License as published by
5  the Free Software Foundation, either version 3 of the License, or
6  (at your option) any later version.
7 
8  Victor is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with Victor. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 
18 #ifndef __Nucleotide_CODE_H__
19 #define __Nucleotide_CODE_H__
20 
21 // Includes
22 
23 #include <string>
24 #include <Debug.h>
25 
26 
37 enum NucleotideCode {
38  ADENINE = 0,
39  THYMINE,
40  CYTOSINE,
41  GUANINE,
42  URACIL,
43  XX, // Corresponds to unknown Nucleotide type
44  Nucleotide_CODE_SIZE // number of Nucleotide types
45 };
46 
51 inline
52 bool
53 isKnownNucleotide(NucleotideCode code) {
54  return !(code == XX);
55 }
56 
60 inline
61 NucleotideCode
62 nucleotideOneLetterTranslator(char name) {
63  DUMP(name);
64  if (name == ' ') {
65  return XX;
66  }
67  if (name == 'X') {
68  return XX;
69  }
70  if (name == 'A') {
71  return ADENINE;
72  } else if (name == 'T') {
73  return THYMINE;
74  } else if (name == 'C') {
75  return CYTOSINE;
76  } else if (name == 'G') {
77  return GUANINE;
78  } else if (name == 'U') {
79  return URACIL;
80  }
81 
82  return XX; // Nucleotide type name is unknown
83 }
84 
88 inline
89 NucleotideCode
90 nucleotideThreeLetterTranslator(const string& name) {
91  DUMP(name);
92  if (name == "") {
93  return XX;
94  }
95  if (name == "X") {
96  return XX;
97  }
98  if (name == "A") {
99  return ADENINE;
100  } else if (name == "T") {
101  return THYMINE;
102  } else if (name == "C") {
103  return CYTOSINE;
104  } else if (name == "G") {
105  return GUANINE;
106  } else if (name == "U") {
107  return URACIL;
108  } else if (name == "DA") {
109  return ADENINE;
110  } else if (name == "DT") {
111  return THYMINE;
112  } else if (name == "DC") {
113  return CYTOSINE;
114  } else if (name == "DG") {
115  return GUANINE;
116  } else if (name == "DU") {
117  return URACIL;
118  }
119 
120  return XX; // Nucleotide type name is unknown
121 }
122 
128 inline string nucleotideThreeLetterTranslator(NucleotideCode code) {
129  switch (code) {
130  case XX:
131  return "X";
132  case ADENINE:
133  return "A";
134  case THYMINE:
135  return "T";
136  case CYTOSINE:
137  return "C";
138  case GUANINE:
139  return "G";
140  case URACIL:
141  return "U";
142  case Nucleotide_CODE_SIZE:
143  ERROR("NucleotideTranslator(NucleotideCode code): unknown code", exception);
144  }
145 
146  ERROR("NucleotideTranslator(NucleotideCode code): unknown code", eXXXception);
147 
148  return "X";
149 }
150 
156 inline string nucleotideOneLetter2ThreeLetter(char oneLetter) {
157  NucleotideCode code;
158  code = nucleotideOneLetterTranslator(oneLetter);
159  return nucleotideThreeLetterTranslator(code);
160 }
161 
167 inline char nucleotideThreeLetter2OneLetter(const string& threeLetter) {
168  NucleotideCode code;
169  code = nucleotideThreeLetterTranslator(threeLetter);
170  return nucleotideOneLetterTranslator(code);
171 }
172 
178 inline NucleotideCode& operator++(NucleotideCode& ac, int) {
179  return ac = ((ac == XX) ? ADENINE : NucleotideCode(ac + 1));
180 }
181 
187 inline NucleotideCode& operator--(NucleotideCode& ac, int) {
188  return ac = ((ac == ADENINE) ? XX : NucleotideCode(ac - 1));
189 }
190 
191 #endif /* __Nucleotide_CODE_H__ */
192