2342 |
17 Oct 10 |
peter |
1 |
#ifndef theplu_yat_omic_dna |
2342 |
17 Oct 10 |
peter |
2 |
#define theplu_yat_omic_dna |
2342 |
17 Oct 10 |
peter |
3 |
|
2993 |
03 Mar 13 |
peter |
// $Id$ |
2993 |
03 Mar 13 |
peter |
5 |
|
2342 |
17 Oct 10 |
peter |
6 |
/* |
3550 |
03 Jan 17 |
peter |
Copyright (C) 2010, 2011, 2012, 2013, 2016 Peter Johansson |
2342 |
17 Oct 10 |
peter |
8 |
|
2342 |
17 Oct 10 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
2342 |
17 Oct 10 |
peter |
10 |
|
2342 |
17 Oct 10 |
peter |
The yat library is free software; you can redistribute it and/or |
2342 |
17 Oct 10 |
peter |
modify it under the terms of the GNU General Public License as |
2342 |
17 Oct 10 |
peter |
published by the Free Software Foundation; either version 3 of the |
2342 |
17 Oct 10 |
peter |
License, or (at your option) any later version. |
2342 |
17 Oct 10 |
peter |
15 |
|
2342 |
17 Oct 10 |
peter |
The yat library is distributed in the hope that it will be useful, |
2342 |
17 Oct 10 |
peter |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
2342 |
17 Oct 10 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
2342 |
17 Oct 10 |
peter |
General Public License for more details. |
2342 |
17 Oct 10 |
peter |
20 |
|
2342 |
17 Oct 10 |
peter |
You should have received a copy of the GNU General Public License |
2342 |
17 Oct 10 |
peter |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
2342 |
17 Oct 10 |
peter |
23 |
*/ |
2342 |
17 Oct 10 |
peter |
24 |
|
2342 |
17 Oct 10 |
peter |
25 |
#include <boost/operators.hpp> |
2342 |
17 Oct 10 |
peter |
26 |
|
2342 |
17 Oct 10 |
peter |
27 |
#include <iosfwd> |
2342 |
17 Oct 10 |
peter |
28 |
#include <string> |
2342 |
17 Oct 10 |
peter |
29 |
#include <vector> |
2342 |
17 Oct 10 |
peter |
30 |
|
2342 |
17 Oct 10 |
peter |
31 |
namespace theplu { |
2342 |
17 Oct 10 |
peter |
32 |
namespace yat { |
2342 |
17 Oct 10 |
peter |
33 |
namespace omic { |
2342 |
17 Oct 10 |
peter |
34 |
|
2342 |
17 Oct 10 |
peter |
35 |
/** |
2342 |
17 Oct 10 |
peter |
Class for DNA e.g. A, C, G, or T. Nucleotides can be overloaded |
2342 |
17 Oct 10 |
peter |
e.g. 'A' | 'G' == 'R'. Null object (opposite to 'N') is denoted |
2342 |
17 Oct 10 |
peter |
by space, ' '. |
2342 |
17 Oct 10 |
peter |
39 |
|
2342 |
17 Oct 10 |
peter |
<table> |
2342 |
17 Oct 10 |
peter |
<tr><td>A</td><td>A</td></tr> |
2342 |
17 Oct 10 |
peter |
<tr><td>T</td><td>T</td></tr> |
2342 |
17 Oct 10 |
peter |
<tr><td>G</td><td>G</td></tr> |
2342 |
17 Oct 10 |
peter |
<tr><td>C</td><td>C</td></tr> |
2342 |
17 Oct 10 |
peter |
<tr><td>R</td><td>G or A</td></tr> |
2342 |
17 Oct 10 |
peter |
<tr><td>Y</td><td>T or C</td></tr> |
2342 |
17 Oct 10 |
peter |
<tr><td>M</td><td>A or C</td></tr> |
2342 |
17 Oct 10 |
peter |
<tr><td>K</td><td>G or T</td></tr> |
2342 |
17 Oct 10 |
peter |
<tr><td>S</td><td>G or C</td></tr> |
2342 |
17 Oct 10 |
peter |
<tr><td>W</td><td>A or T</td></tr> |
2342 |
17 Oct 10 |
peter |
<tr><td>H</td><td>A or C or T</td></tr> |
2342 |
17 Oct 10 |
peter |
<tr><td>B</td><td>G or T or C</td></tr> |
2342 |
17 Oct 10 |
peter |
<tr><td>V</td><td>G or C or A</td></tr> |
2342 |
17 Oct 10 |
peter |
<tr><td>D</td><td>G or T or A</td></tr> |
2342 |
17 Oct 10 |
peter |
<tr><td>N</td><td>A or C or T or G</td></tr> |
2342 |
17 Oct 10 |
peter |
<tr><td>' '</td><td>none</td></tr> |
2342 |
17 Oct 10 |
peter |
</table> |
2342 |
17 Oct 10 |
peter |
58 |
|
2342 |
17 Oct 10 |
peter |
\since New in yat 0.7 |
2342 |
17 Oct 10 |
peter |
60 |
*/ |
2342 |
17 Oct 10 |
peter |
61 |
class DNA : boost::operators<DNA> |
2342 |
17 Oct 10 |
peter |
62 |
{ |
2342 |
17 Oct 10 |
peter |
63 |
public: |
2342 |
17 Oct 10 |
peter |
64 |
/** |
2342 |
17 Oct 10 |
peter |
\brief Default Constructor |
2342 |
17 Oct 10 |
peter |
66 |
|
2342 |
17 Oct 10 |
peter |
Equivalent to DNA(' '). |
2342 |
17 Oct 10 |
peter |
68 |
*/ |
2342 |
17 Oct 10 |
peter |
69 |
DNA(void); |
2342 |
17 Oct 10 |
peter |
70 |
|
2342 |
17 Oct 10 |
peter |
71 |
/** |
2342 |
17 Oct 10 |
peter |
\param c must be one of the following 16 characters, A, C, G, |
2342 |
17 Oct 10 |
peter |
T, M, R, W, S, Y, K, B, D, H, V, N, or ' '. |
2342 |
17 Oct 10 |
peter |
74 |
|
2342 |
17 Oct 10 |
peter |
\throw std::invalid_argument if \a c is not one of 16 allowed |
2342 |
17 Oct 10 |
peter |
characters |
2342 |
17 Oct 10 |
peter |
77 |
*/ |
2342 |
17 Oct 10 |
peter |
78 |
explicit DNA(char c); |
2342 |
17 Oct 10 |
peter |
79 |
|
2342 |
17 Oct 10 |
peter |
80 |
/** |
2342 |
17 Oct 10 |
peter |
Calculates complement, i.e., 'A' becomes 'T' and 'G' becomes |
2342 |
17 Oct 10 |
peter |
'C' etc. In case of combination the returned DNA will be the |
2342 |
17 Oct 10 |
peter |
combination of all complements, i.e., 'R' becomes 'Y. |
2342 |
17 Oct 10 |
peter |
84 |
|
2342 |
17 Oct 10 |
peter |
\return Complementary base |
2342 |
17 Oct 10 |
peter |
86 |
*/ |
2342 |
17 Oct 10 |
peter |
87 |
DNA complement(void) const; |
2342 |
17 Oct 10 |
peter |
88 |
|
2342 |
17 Oct 10 |
peter |
89 |
/** |
2342 |
17 Oct 10 |
peter |
\return DNA as a character |
2342 |
17 Oct 10 |
peter |
91 |
*/ |
2342 |
17 Oct 10 |
peter |
92 |
char get(void) const; |
2342 |
17 Oct 10 |
peter |
93 |
|
2342 |
17 Oct 10 |
peter |
94 |
/** |
2342 |
17 Oct 10 |
peter |
Modifies lhs and keeps those bases present on both sides, i.e., |
2342 |
17 Oct 10 |
peter |
if lhs, for example, is 'R' and rhs is 'M' the overlap is 'A' |
2342 |
17 Oct 10 |
peter |
so resulting lhs will be an 'A'. |
2342 |
17 Oct 10 |
peter |
98 |
|
2385 |
22 Dec 10 |
peter |
As DNA inherits boost::operators<DNA> corresponding |
2342 |
17 Oct 10 |
peter |
operator&(const DNA&, const DNA&) is also available. |
2342 |
17 Oct 10 |
peter |
101 |
*/ |
2342 |
17 Oct 10 |
peter |
102 |
DNA& operator&=(const DNA& rhs); |
2342 |
17 Oct 10 |
peter |
103 |
|
2342 |
17 Oct 10 |
peter |
104 |
/** |
2342 |
17 Oct 10 |
peter |
Modifies lhs to a combination of bases present on either side. |
2342 |
17 Oct 10 |
peter |
If, for example, lhs is 'A' and rhs is 'C', resuting lhs will |
2342 |
17 Oct 10 |
peter |
be 'M'. |
2342 |
17 Oct 10 |
peter |
108 |
|
2743 |
08 Jun 12 |
peter |
As DNA inherits boost::operators<DNA> corresponding |
2342 |
17 Oct 10 |
peter |
operator|(const DNA&, const DNA&) is also available. |
2342 |
17 Oct 10 |
peter |
111 |
*/ |
2342 |
17 Oct 10 |
peter |
112 |
DNA& operator|=(const DNA& rhs); |
2342 |
17 Oct 10 |
peter |
113 |
|
2342 |
17 Oct 10 |
peter |
114 |
/** |
2342 |
17 Oct 10 |
peter |
Modifies lhs to a combination of bases that are present on one |
2342 |
17 Oct 10 |
peter |
side (not both). If, for example, lhs is 'M' and rhs is 'A', |
2377 |
20 Dec 10 |
peter |
resulting lhs will be 'C'. |
2342 |
17 Oct 10 |
peter |
118 |
|
2743 |
08 Jun 12 |
peter |
As DNA inherits boost::operators<DNA> corresponding |
2342 |
17 Oct 10 |
peter |
operator^(const DNA&, const DNA&) is also available. |
2342 |
17 Oct 10 |
peter |
121 |
*/ |
2342 |
17 Oct 10 |
peter |
122 |
DNA& operator^=(const DNA& rhs); |
2342 |
17 Oct 10 |
peter |
123 |
|
2577 |
03 Oct 11 |
peter |
124 |
/** |
2577 |
03 Oct 11 |
peter |
\brief assign from a char |
2677 |
09 Dec 11 |
peter |
126 |
|
2577 |
03 Oct 11 |
peter |
\result resulting DNA |
2577 |
03 Oct 11 |
peter |
128 |
|
2577 |
03 Oct 11 |
peter |
\since New in yat 0.8 |
2577 |
03 Oct 11 |
peter |
130 |
*/ |
2577 |
03 Oct 11 |
peter |
131 |
DNA& operator=(char c); |
2577 |
03 Oct 11 |
peter |
132 |
|
2342 |
17 Oct 10 |
peter |
133 |
private: |
2342 |
17 Oct 10 |
peter |
134 |
unsigned short code_; |
2342 |
17 Oct 10 |
peter |
135 |
|
3502 |
07 Jun 16 |
peter |
136 |
unsigned short char2code(char) const; |
3502 |
07 Jun 16 |
peter |
137 |
char code2char(unsigned short) const; |
2342 |
17 Oct 10 |
peter |
138 |
friend bool operator==(const DNA&, const DNA&); |
2677 |
09 Dec 11 |
peter |
139 |
}; |
2342 |
17 Oct 10 |
peter |
140 |
|
2342 |
17 Oct 10 |
peter |
141 |
/** |
2342 |
17 Oct 10 |
peter |
\relates DNA |
2342 |
17 Oct 10 |
peter |
143 |
|
2342 |
17 Oct 10 |
peter |
\return a string of combinations of A, C, G, and T. |
2342 |
17 Oct 10 |
peter |
145 |
|
2342 |
17 Oct 10 |
peter |
\since New in yat 0.7 |
2342 |
17 Oct 10 |
peter |
147 |
*/ |
2342 |
17 Oct 10 |
peter |
148 |
std::string expand(const DNA&); |
2342 |
17 Oct 10 |
peter |
149 |
|
2342 |
17 Oct 10 |
peter |
150 |
/** |
2342 |
17 Oct 10 |
peter |
\relates DNA |
2342 |
17 Oct 10 |
peter |
152 |
|
2342 |
17 Oct 10 |
peter |
\return true if bases are the same, i.e., equivalent to |
2342 |
17 Oct 10 |
peter |
lhs.get()==rhs.get() |
2342 |
17 Oct 10 |
peter |
155 |
|
2342 |
17 Oct 10 |
peter |
As DNA is inherits boost::operators<DNA> corresponding |
2342 |
17 Oct 10 |
peter |
operator!=(const DNA&, const DNA&) is also available. |
2342 |
17 Oct 10 |
peter |
158 |
|
2342 |
17 Oct 10 |
peter |
\since New in yat 0.7 |
2342 |
17 Oct 10 |
peter |
160 |
*/ |
2342 |
17 Oct 10 |
peter |
161 |
bool operator==(const DNA& lhs, const DNA& rhs); |
2342 |
17 Oct 10 |
peter |
162 |
|
2342 |
17 Oct 10 |
peter |
163 |
/** |
2377 |
20 Dec 10 |
peter |
Outputs the DNA to os. Equivalent to os << dna.get(). |
2342 |
17 Oct 10 |
peter |
165 |
|
2342 |
17 Oct 10 |
peter |
\relates DNA |
2342 |
17 Oct 10 |
peter |
167 |
|
2342 |
17 Oct 10 |
peter |
\since New in yat 0.7 |
2342 |
17 Oct 10 |
peter |
169 |
*/ |
2342 |
17 Oct 10 |
peter |
170 |
std::ostream& operator<<(std::ostream& os, const DNA& dna); |
2342 |
17 Oct 10 |
peter |
171 |
}}} |
2342 |
17 Oct 10 |
peter |
172 |
#endif |