source: trunk/yat/omic/Codon.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: 3.8 KB
Line 
1#ifndef theplu_yat_omic_codon
2#define theplu_yat_omic_codon
3
4// $Id: Codon.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 "DNA.h"
26
27#include <functional>
28#include <map>
29#include <string>
30#include <vector>
31
32namespace theplu {
33namespace yat {
34namespace omic {
35
36  /**
37     Class holding a triplet of DNAs that are translated to an amino acid.
38
39     <table>
40     <tr><td>Ala</td><td>A</td><td>GCT,GCC,GCA,GCG</td></tr>
41     <tr><td>Leu</td><td>L</td><td>TTA,TTG,CTT,CTC,CTA,CTG</td></tr>
42     <tr><td>Arg</td><td>R</td><td>CGT,CGC,CGA,CGG,AGA,AGG</td></tr>
43     <tr><td>Lys</td><td>K</td><td>AAA,AAG</td></tr>
44     <tr><td>Asn</td><td>N</td><td>AAT,AAC</td></tr>
45     <tr><td>Met</td><td>M</td><td>ATG</td></tr>
46     <tr><td>Asp</td><td>D</td><td>GAT,GAC</td></tr>
47     <tr><td>Phe</td><td>F</td><td>TTT,TTC</td></tr>
48     <tr><td>Cys</td><td>C</td><td>TGT,TGC</td></tr>
49     <tr><td>Pro</td><td>P</td><td>CCT,CCC,CCA,CCG</td></tr>
50     <tr><td>Gln</td><td>Q</td><td>CAA,CAG</td></tr>
51     <tr><td>Ser</td><td>S</td><td>TCT,TCC,TCA,TCG,AGT,AGC</td></tr>
52     <tr><td>Glu</td><td>E</td><td>GAA,GAG</td></tr>
53     <tr><td>Thr</td><td>T</td><td>ACT,ACC,ACA,ACG</td></tr>
54     <tr><td>Gly</td><td>G</td><td>GGT,GGC,GGA,GGG</td></tr>
55     <tr><td>Trp</td><td>W</td><td>TGG</td></tr>
56     <tr><td>His</td><td>H</td><td>CAT,CAC</td></tr>
57     <tr><td>Tyr</td><td>Y</td><td>TAT,TAC</td></tr>
58     <tr><td>Ile</td><td>I</td><td>ATT,ATC,ATA</td></tr>
59     <tr><td>Val</td><td>V</td><td>GTT,GTC,GTA,GTG</td></tr>
60     <tr><td>START</td><td></td><td>ATG</td></tr>
61     <tr><td>STOP</td>*<td></td><td>TAA,TGA,TAG</td></tr>
62     </table>
63
64     \since New in yat 0.7
65   */
66  class Codon
67  {
68  public:
69    /**
70       \brief Defaulf constructor.
71
72       Value is undefined
73     */
74    Codon(void);
75
76    /**
77       \a str must be three characters long and each character must be
78       convertible to a DNA.
79
80       \see DNA
81     */
82    Codon(const std::string& str);
83
84    /**
85       Create Codon from three DNA
86     */
87    Codon(const DNA& first, const DNA& second, const DNA& third);
88
89    /**
90       \return one character describing which amino acid the Codon
91       translates to.
92     */
93    char amino_acid(void) const;
94
95    /**
96       \return \a i th DNA
97     */
98    const DNA& operator()(size_t i) const;
99
100    /**
101       \return \c true if Codon is a start Codon: "ATG"
102     */
103    bool start(void) const;
104
105    /**
106       \return \c true if Codon is a stop codon (see class docs).
107     */
108    bool stop(void) const;
109  private:
110    struct Compare_
111    {
112      bool operator()(const std::vector<DNA>& lhs,
113                      const std::vector<DNA>& rhs) const;
114    };
115    typedef std::map<std::vector<DNA>, char, Compare_> Map_;
116    static Map_ map_;
117
118    Map_::const_iterator iter_;
119
120    void add_to_map(char aa, const std::string& codons);
121
122    void init(const std::vector<DNA>& vec);
123    void create_map(void);
124
125    // using compiler generated copy
126    // Codon(const Codon&)
127    // Codon& operator=(const Codon&)
128  };
129
130  /**
131     \brief Functor comparing if two Codons translate to the same amino acid
132
133     \relates Codon
134
135     \since New in yat 0.7
136   */
137  struct AminoAcidEqual : public std::binary_function<Codon, Codon, bool>
138  {
139    /// \return \c true \a lhs and \a rhs translates to same amino acid
140    bool operator()(const Codon& lhs, const Codon& rhs) const;
141  };
142
143}}}
144#endif
Note: See TracBrowser for help on using the repository browser.