yat/omic/DNA.h

Code
Comments
Other
Rev Date Author Line
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 4 // $Id$
2993 03 Mar 13 peter 5
2342 17 Oct 10 peter 6 /*
3550 03 Jan 17 peter 7   Copyright (C) 2010, 2011, 2012, 2013, 2016 Peter Johansson
2342 17 Oct 10 peter 8
2342 17 Oct 10 peter 9   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 11   The yat library is free software; you can redistribute it and/or
2342 17 Oct 10 peter 12   modify it under the terms of the GNU General Public License as
2342 17 Oct 10 peter 13   published by the Free Software Foundation; either version 3 of the
2342 17 Oct 10 peter 14   License, or (at your option) any later version.
2342 17 Oct 10 peter 15
2342 17 Oct 10 peter 16   The yat library is distributed in the hope that it will be useful,
2342 17 Oct 10 peter 17   but WITHOUT ANY WARRANTY; without even the implied warranty of
2342 17 Oct 10 peter 18   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2342 17 Oct 10 peter 19   General Public License for more details.
2342 17 Oct 10 peter 20
2342 17 Oct 10 peter 21   You should have received a copy of the GNU General Public License
2342 17 Oct 10 peter 22   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 36      Class for DNA e.g. A, C, G, or T. Nucleotides can be overloaded
2342 17 Oct 10 peter 37      e.g. 'A' | 'G' == 'R'. Null object (opposite to 'N') is denoted
2342 17 Oct 10 peter 38      by space, ' '.
2342 17 Oct 10 peter 39
2342 17 Oct 10 peter 40      <table>
2342 17 Oct 10 peter 41      <tr><td>A</td><td>A</td></tr>
2342 17 Oct 10 peter 42      <tr><td>T</td><td>T</td></tr>
2342 17 Oct 10 peter 43      <tr><td>G</td><td>G</td></tr>
2342 17 Oct 10 peter 44      <tr><td>C</td><td>C</td></tr>
2342 17 Oct 10 peter 45      <tr><td>R</td><td>G or A</td></tr>
2342 17 Oct 10 peter 46      <tr><td>Y</td><td>T or C</td></tr>
2342 17 Oct 10 peter 47      <tr><td>M</td><td>A or C</td></tr>
2342 17 Oct 10 peter 48      <tr><td>K</td><td>G or T</td></tr>
2342 17 Oct 10 peter 49      <tr><td>S</td><td>G or C</td></tr>
2342 17 Oct 10 peter 50      <tr><td>W</td><td>A or T</td></tr>
2342 17 Oct 10 peter 51      <tr><td>H</td><td>A or C or T</td></tr>
2342 17 Oct 10 peter 52      <tr><td>B</td><td>G or T or C</td></tr>
2342 17 Oct 10 peter 53      <tr><td>V</td><td>G or C or A</td></tr>
2342 17 Oct 10 peter 54      <tr><td>D</td><td>G or T or A</td></tr>
2342 17 Oct 10 peter 55      <tr><td>N</td><td>A or C or T or G</td></tr>
2342 17 Oct 10 peter 56      <tr><td>' '</td><td>none</td></tr>
2342 17 Oct 10 peter 57      </table>
2342 17 Oct 10 peter 58
2342 17 Oct 10 peter 59      \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 65        \brief Default Constructor
2342 17 Oct 10 peter 66
2342 17 Oct 10 peter 67        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 72        \param c must be one of the following 16 characters, A, C, G,
2342 17 Oct 10 peter 73        T, M, R, W, S, Y, K, B, D, H, V, N, or ' '.
2342 17 Oct 10 peter 74
2342 17 Oct 10 peter 75        \throw std::invalid_argument if \a c is not one of 16 allowed
2342 17 Oct 10 peter 76        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 81        Calculates complement, i.e., 'A' becomes 'T' and 'G' becomes
2342 17 Oct 10 peter 82        'C' etc. In case of combination the returned DNA will be the
2342 17 Oct 10 peter 83        combination of all complements, i.e., 'R' becomes 'Y.
2342 17 Oct 10 peter 84
2342 17 Oct 10 peter 85        \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 90        \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 95        Modifies lhs and keeps those bases present on both sides, i.e.,
2342 17 Oct 10 peter 96        if lhs, for example, is 'R' and rhs is 'M' the overlap is 'A'
2342 17 Oct 10 peter 97        so resulting lhs will be an 'A'.
2342 17 Oct 10 peter 98
2385 22 Dec 10 peter 99        As DNA inherits boost::operators<DNA> corresponding
2342 17 Oct 10 peter 100        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 105        Modifies lhs to a combination of bases present on either side.
2342 17 Oct 10 peter 106        If, for example, lhs is 'A' and rhs is 'C', resuting lhs will
2342 17 Oct 10 peter 107        be 'M'.
2342 17 Oct 10 peter 108
2743 08 Jun 12 peter 109        As DNA inherits boost::operators<DNA> corresponding
2342 17 Oct 10 peter 110        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 115        Modifies lhs to a combination of bases that are present on one
2342 17 Oct 10 peter 116        side (not both). If, for example, lhs is 'M' and rhs is 'A',
2377 20 Dec 10 peter 117        resulting lhs will be 'C'.
2342 17 Oct 10 peter 118
2743 08 Jun 12 peter 119        As DNA inherits boost::operators<DNA> corresponding
2342 17 Oct 10 peter 120        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 125        \brief assign from a char
2677 09 Dec 11 peter 126
2577 03 Oct 11 peter 127        \result resulting DNA
2577 03 Oct 11 peter 128
2577 03 Oct 11 peter 129        \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 142      \relates DNA
2342 17 Oct 10 peter 143
2342 17 Oct 10 peter 144      \return a string of combinations of A, C, G, and T.
2342 17 Oct 10 peter 145
2342 17 Oct 10 peter 146      \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 151      \relates DNA
2342 17 Oct 10 peter 152
2342 17 Oct 10 peter 153      \return true if bases are the same, i.e., equivalent to
2342 17 Oct 10 peter 154      lhs.get()==rhs.get()
2342 17 Oct 10 peter 155
2342 17 Oct 10 peter 156      As DNA is inherits boost::operators<DNA> corresponding
2342 17 Oct 10 peter 157      operator!=(const DNA&, const DNA&) is also available.
2342 17 Oct 10 peter 158
2342 17 Oct 10 peter 159      \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 164      Outputs the DNA to os. Equivalent to os << dna.get().
2342 17 Oct 10 peter 165
2342 17 Oct 10 peter 166      \relates DNA
2342 17 Oct 10 peter 167
2342 17 Oct 10 peter 168      \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