1 | #ifndef theplu_yat_omic_dna |
---|
2 | #define theplu_yat_omic_dna |
---|
3 | |
---|
4 | /* |
---|
5 | $Id: DNA.h 2377 2010-12-20 20:49:34Z peter $ |
---|
6 | |
---|
7 | Copyright (C) 2010 Peter Johansson |
---|
8 | |
---|
9 | This file is part of the yat library, http://dev.thep.lu.se/yat |
---|
10 | |
---|
11 | The yat library is free software; you can redistribute it and/or |
---|
12 | modify it under the terms of the GNU General Public License as |
---|
13 | published by the Free Software Foundation; either version 3 of the |
---|
14 | License, or (at your option) any later version. |
---|
15 | |
---|
16 | The yat library is distributed in the hope that it will be useful, |
---|
17 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
19 | General Public License for more details. |
---|
20 | |
---|
21 | You should have received a copy of the GNU General Public License |
---|
22 | along with yat. If not, see <http://www.gnu.org/licenses/>. |
---|
23 | */ |
---|
24 | |
---|
25 | #include <boost/operators.hpp> |
---|
26 | |
---|
27 | #include <iosfwd> |
---|
28 | #include <map> |
---|
29 | #include <string> |
---|
30 | #include <vector> |
---|
31 | |
---|
32 | namespace theplu { |
---|
33 | namespace yat { |
---|
34 | namespace omic { |
---|
35 | |
---|
36 | /** |
---|
37 | Class for DNA e.g. A, C, G, or T. Nucleotides can be overloaded |
---|
38 | e.g. 'A' | 'G' == 'R'. Null object (opposite to 'N') is denoted |
---|
39 | by space, ' '. |
---|
40 | |
---|
41 | <table> |
---|
42 | <tr><td>A</td><td>A</td></tr> |
---|
43 | <tr><td>T</td><td>T</td></tr> |
---|
44 | <tr><td>G</td><td>G</td></tr> |
---|
45 | <tr><td>C</td><td>C</td></tr> |
---|
46 | <tr><td>R</td><td>G or A</td></tr> |
---|
47 | <tr><td>Y</td><td>T or C</td></tr> |
---|
48 | <tr><td>M</td><td>A or C</td></tr> |
---|
49 | <tr><td>K</td><td>G or T</td></tr> |
---|
50 | <tr><td>S</td><td>G or C</td></tr> |
---|
51 | <tr><td>W</td><td>A or T</td></tr> |
---|
52 | <tr><td>H</td><td>A or C or T</td></tr> |
---|
53 | <tr><td>B</td><td>G or T or C</td></tr> |
---|
54 | <tr><td>V</td><td>G or C or A</td></tr> |
---|
55 | <tr><td>D</td><td>G or T or A</td></tr> |
---|
56 | <tr><td>N</td><td>A or C or T or G</td></tr> |
---|
57 | <tr><td>' '</td><td>none</td></tr> |
---|
58 | </table> |
---|
59 | |
---|
60 | \since New in yat 0.7 |
---|
61 | */ |
---|
62 | class DNA : boost::operators<DNA> |
---|
63 | { |
---|
64 | public: |
---|
65 | /** |
---|
66 | \brief Default Constructor |
---|
67 | |
---|
68 | Equivalent to DNA(' '). |
---|
69 | */ |
---|
70 | DNA(void); |
---|
71 | |
---|
72 | /** |
---|
73 | \brief Copy Constructor |
---|
74 | */ |
---|
75 | DNA(const DNA&); |
---|
76 | |
---|
77 | /** |
---|
78 | \param c must be one of the following 16 characters, A, C, G, |
---|
79 | T, M, R, W, S, Y, K, B, D, H, V, N, or ' '. |
---|
80 | |
---|
81 | \throw std::invalid_argument if \a c is not one of 16 allowed |
---|
82 | characters |
---|
83 | */ |
---|
84 | explicit DNA(char c); |
---|
85 | |
---|
86 | /** |
---|
87 | Calculates complement, i.e., 'A' becomes 'T' and 'G' becomes |
---|
88 | 'C' etc. In case of combination the returned DNA will be the |
---|
89 | combination of all complements, i.e., 'R' becomes 'Y. |
---|
90 | |
---|
91 | \return Complementary base |
---|
92 | */ |
---|
93 | DNA complement(void) const; |
---|
94 | |
---|
95 | /** |
---|
96 | \return DNA as a character |
---|
97 | */ |
---|
98 | char get(void) const; |
---|
99 | |
---|
100 | /** |
---|
101 | Modifies lhs and keeps those bases present on both sides, i.e., |
---|
102 | if lhs, for example, is 'R' and rhs is 'M' the overlap is 'A' |
---|
103 | so resulting lhs will be an 'A'. |
---|
104 | |
---|
105 | As DNA is inherits boost::operators<DNA> corresponding |
---|
106 | operator&(const DNA&, const DNA&) is also available. |
---|
107 | */ |
---|
108 | DNA& operator&=(const DNA& rhs); |
---|
109 | |
---|
110 | /** |
---|
111 | Modifies lhs to a combination of bases present on either side. |
---|
112 | If, for example, lhs is 'A' and rhs is 'C', resuting lhs will |
---|
113 | be 'M'. |
---|
114 | |
---|
115 | As DNA is inherits boost::operators<DNA> corresponding |
---|
116 | operator|(const DNA&, const DNA&) is also available. |
---|
117 | */ |
---|
118 | DNA& operator|=(const DNA& rhs); |
---|
119 | |
---|
120 | /** |
---|
121 | Modifies lhs to a combination of bases that are present on one |
---|
122 | side (not both). If, for example, lhs is 'M' and rhs is 'A', |
---|
123 | resulting lhs will be 'C'. |
---|
124 | |
---|
125 | As DNA is inherits boost::operators<DNA> corresponding |
---|
126 | operator^(const DNA&, const DNA&) is also available. |
---|
127 | */ |
---|
128 | DNA& operator^=(const DNA& rhs); |
---|
129 | |
---|
130 | private: |
---|
131 | unsigned short code_; |
---|
132 | static std::map<char, unsigned short> char2code_; |
---|
133 | static std::vector<char> code2char_; |
---|
134 | |
---|
135 | void init(void) const; |
---|
136 | |
---|
137 | friend bool operator==(const DNA&, const DNA&); |
---|
138 | }; |
---|
139 | |
---|
140 | /** |
---|
141 | \relates DNA |
---|
142 | |
---|
143 | \return a string of combinations of A, C, G, and T. |
---|
144 | |
---|
145 | \since New in yat 0.7 |
---|
146 | */ |
---|
147 | std::string expand(const DNA&); |
---|
148 | |
---|
149 | /** |
---|
150 | \relates DNA |
---|
151 | |
---|
152 | \return true if bases are the same, i.e., equivalent to |
---|
153 | lhs.get()==rhs.get() |
---|
154 | |
---|
155 | As DNA is inherits boost::operators<DNA> corresponding |
---|
156 | operator!=(const DNA&, const DNA&) is also available. |
---|
157 | |
---|
158 | \since New in yat 0.7 |
---|
159 | */ |
---|
160 | bool operator==(const DNA& lhs, const DNA& rhs); |
---|
161 | |
---|
162 | /** |
---|
163 | Outputs the DNA to os. Equivalent to os << dna.get(). |
---|
164 | |
---|
165 | \relates DNA |
---|
166 | |
---|
167 | \since New in yat 0.7 |
---|
168 | */ |
---|
169 | std::ostream& operator<<(std::ostream& os, const DNA& dna); |
---|
170 | }}} |
---|
171 | #endif |
---|