faif
Codon.h
1 // codon - nucleotide triplet, coding single amino acid
2 // @author Robert Nowak
3 
4 #ifndef CODON_H
5 #define CODON_H
6 
7 #include<boost/tuple/tuple.hpp>
8 #include<boost/tuple/tuple_comparison.hpp>
9 
10 #include "Nucleotide.h"
11 #include "ExceptionsDna.h"
12 
13 namespace faif {
14  namespace dna {
15 
16  /** \brief the triplet of nucleotides, codon.
17 
18  The triplet of nucleotides representing codon (each codon corresponds to given amino
19  */
20  class Codon : public boost::tuple<Nucleotide, Nucleotide, Nucleotide> {
21  public:
22  /** c-tor */
23  Codon(const Nucleotide& n1v = Nucleotide(),
24  const Nucleotide& n2v = Nucleotide(),
25  const Nucleotide& n3v = Nucleotide() )
26  : boost::tuple<Nucleotide,Nucleotide,Nucleotide>(n1v, n2v, n3v)
27  {}
28 
29  /** c-tor from string */
30  Codon(const std::string& str) {
31  if (str.size() < 3)
33  get<0>() = create(str[0]);
34  get<1>() = create(str[1]);
35  get<2>() = create(str[2]);
36  }
37 
38  /** \brief accessor */
39  const Nucleotide& getFirst() const { return get<0>(); }
40 
41  /** \brief accessor */
42  const Nucleotide& getSecond() const { return get<1>(); }
43 
44  /** \brief accessor */
45  const Nucleotide& getThird() const { return get<2>(); }
46  };
47 
48  /** ostream operator for codon */
49  inline std::ostream& operator<<(std::ostream& os, const Codon& codon) {
50  os << "(" << codon.getFirst() << "," << codon.getSecond() << "," << codon.getThird() << ")";
51  return os;
52  }
53  } //namespace dna
54 } //namespace faif
55 
56 #endif
const Nucleotide & getFirst() const
accessor
Definition: Codon.h:39
Definition: Chain.h:17
the DNA nucleotide
Definition: Nucleotide.h:21
Codon(const std::string &str)
Definition: Codon.h:30
const Nucleotide & getThird() const
accessor
Definition: Codon.h:45
const Nucleotide & getSecond() const
accessor
Definition: Codon.h:42
the triplet of nucleotides, codon.
Definition: Codon.h:20
std::ostream & operator<<(std::ostream &os, const Chain &chain)
Definition: Chain.h:162
Codon(const Nucleotide &n1v=Nucleotide(), const Nucleotide &n2v=Nucleotide(), const Nucleotide &n3v=Nucleotide())
Definition: Codon.h:23
Nucleotide create(const char &n)
Definition: Nucleotide.h:60
the exception when chain representing codon is shorted than 3 nucleotides
Definition: ExceptionsDna.h:32