source: trunk/yat/omic/Codon.h @ 3487

Last change on this file since 3487 was 3487, checked in by Peter, 6 years ago

add function amino_acid_long

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.0 KB
Line 
1#ifndef theplu_yat_omic_codon
2#define theplu_yat_omic_codon
3
4// $Id: Codon.h 3487 2016-03-24 04:24:05Z peter $
5
6/*
7  Copyright (C) 2010, 2011, 2012, 2013, 2016 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 three characters describing which amino acid the Codon
97       translates to.
98
99       \since New in yat 0.14
100     */
101    std::string amino_acid_long(void) const;
102
103    /**
104       \return \a i th DNA
105     */
106    const DNA& operator()(size_t i) const;
107
108    /**
109       \return \c true if Codon is a start Codon: "ATG"
110     */
111    bool start(void) const;
112
113    /**
114       \return \c true if Codon is a stop codon (see class docs).
115     */
116    bool stop(void) const;
117  private:
118    struct Compare_
119    {
120      bool operator()(const std::vector<DNA>& lhs,
121                      const std::vector<DNA>& rhs) const;
122    };
123    typedef std::map<std::vector<DNA>, char, Compare_> Map_;
124    static Map_ map_;
125
126    Map_::const_iterator iter_;
127
128    void add_to_map(char aa, const std::string& codons);
129
130    void init(const std::vector<DNA>& vec);
131    void create_map(void);
132
133    // using compiler generated copy
134    // Codon(const Codon&)
135    // Codon& operator=(const Codon&)
136  };
137
138  /**
139     \brief Functor comparing if two Codons translate to the same amino acid
140
141     \relates Codon
142
143     \since New in yat 0.7
144   */
145  struct AminoAcidEqual : public std::binary_function<Codon, Codon, bool>
146  {
147    /// \return \c true \a lhs and \a rhs translates to same amino acid
148    bool operator()(const Codon& lhs, const Codon& rhs) const;
149  };
150
151}}}
152#endif
Note: See TracBrowser for help on using the repository browser.