source: trunk/yat/omic/DNA.h @ 2993

Last change on this file since 2993 was 2993, checked in by Peter, 9 years ago

conform GPL header to same style as in other yat files

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.3 KB
Line 
1#ifndef theplu_yat_omic_dna
2#define theplu_yat_omic_dna
3
4// $Id: DNA.h 2993 2013-03-03 07:38:22Z peter $
5
6/*
7  Copyright (C) 2010, 2011, 2012 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 <string>
29#include <vector>
30
31namespace theplu {
32namespace yat {
33namespace omic {
34
35  /**
36     Class for DNA e.g. A, C, G, or T. Nucleotides can be overloaded
37     e.g. 'A' | 'G' == 'R'. Null object (opposite to 'N') is denoted
38     by space, ' '.
39
40     <table>
41     <tr><td>A</td><td>A</td></tr>
42     <tr><td>T</td><td>T</td></tr>
43     <tr><td>G</td><td>G</td></tr>
44     <tr><td>C</td><td>C</td></tr>
45     <tr><td>R</td><td>G or A</td></tr>
46     <tr><td>Y</td><td>T or C</td></tr>
47     <tr><td>M</td><td>A or C</td></tr>
48     <tr><td>K</td><td>G or T</td></tr>
49     <tr><td>S</td><td>G or C</td></tr>
50     <tr><td>W</td><td>A or T</td></tr>
51     <tr><td>H</td><td>A or C or T</td></tr>
52     <tr><td>B</td><td>G or T or C</td></tr>
53     <tr><td>V</td><td>G or C or A</td></tr>
54     <tr><td>D</td><td>G or T or A</td></tr>
55     <tr><td>N</td><td>A or C or T or G</td></tr>
56     <tr><td>' '</td><td>none</td></tr>
57     </table>
58
59     \since New in yat 0.7
60   */
61  class DNA : boost::operators<DNA>
62  {
63  public:
64    /**
65       \brief Default Constructor
66
67       Equivalent to DNA(' ').
68     */
69    DNA(void);
70
71    /**
72       \brief Copy Constructor
73     */
74    DNA(const DNA&);
75
76    /**
77       \param c must be one of the following 16 characters, A, C, G,
78       T, M, R, W, S, Y, K, B, D, H, V, N, or ' '.
79
80       \throw std::invalid_argument if \a c is not one of 16 allowed
81       characters
82     */
83    explicit DNA(char c);
84
85    /**
86       Calculates complement, i.e., 'A' becomes 'T' and 'G' becomes
87       'C' etc. In case of combination the returned DNA will be the
88       combination of all complements, i.e., 'R' becomes 'Y.
89
90       \return Complementary base
91     */
92    DNA complement(void) const;
93
94    /**
95       \return DNA as a character
96     */
97    char get(void) const;
98
99    /**
100       Modifies lhs and keeps those bases present on both sides, i.e.,
101       if lhs, for example, is 'R' and rhs is 'M' the overlap is 'A'
102       so resulting lhs will be an 'A'.
103
104       As DNA inherits boost::operators<DNA> corresponding
105       operator&(const DNA&, const DNA&) is also available.
106     */
107    DNA& operator&=(const DNA& rhs);
108
109    /**
110       Modifies lhs to a combination of bases present on either side.
111       If, for example, lhs is 'A' and rhs is 'C', resuting lhs will
112       be 'M'.
113
114       As DNA inherits boost::operators<DNA> corresponding
115       operator|(const DNA&, const DNA&) is also available.
116     */
117    DNA& operator|=(const DNA& rhs);
118
119    /**
120       Modifies lhs to a combination of bases that are present on one
121       side (not both). If, for example, lhs is 'M' and rhs is 'A',
122       resulting lhs will be 'C'.
123
124       As DNA inherits boost::operators<DNA> corresponding
125       operator^(const DNA&, const DNA&) is also available.
126     */
127    DNA& operator^=(const DNA& rhs);
128
129    /**
130       \brief assign from a char
131
132       \result resulting DNA
133
134       \since New in yat 0.8
135     */
136    DNA& operator=(char c);
137
138  private:
139    unsigned short code_;
140    static std::vector<unsigned short> char2code_;
141    static std::string code2char_;
142
143    void init(void) const;
144
145    friend bool operator==(const DNA&, const DNA&);
146};
147
148  /**
149     \relates DNA
150
151     \return a string of combinations of A, C, G, and T.
152
153     \since New in yat 0.7
154   */
155  std::string expand(const DNA&);
156
157  /**
158     \relates DNA
159
160     \return true if bases are the same, i.e., equivalent to
161     lhs.get()==rhs.get()
162
163     As DNA is inherits boost::operators<DNA> corresponding
164     operator!=(const DNA&, const DNA&) is also available.
165
166     \since New in yat 0.7
167   */
168  bool operator==(const DNA& lhs, const DNA& rhs);
169
170  /**
171     Outputs the DNA to os. Equivalent to os << dna.get().
172
173     \relates DNA
174
175     \since New in yat 0.7
176   */
177  std::ostream& operator<<(std::ostream& os, const DNA& dna);
178}}}
179#endif
Note: See TracBrowser for help on using the repository browser.