faif
CodonAminoTable.h
1 // singleton , represents the genetic code (corresponding amino acid and codons)
2 
3 #ifndef CODON_AMINO_TABLE_H
4 #define CODON_AMINO_TABLE_H
5 
6 #include"Codon.h"
7 
8 #include<set>
9 #include<map>
10 #include <boost/bind.hpp>
11 
12 namespace faif {
13  namespace dna {
14 
15 
16  /** the enum represents amino */
17  enum AminoAcid {
18  PHENYLALANINE = 'F',
19  LEUCINE = 'L',
20  ISOLEUCINE = 'I',
21  METHIONINE = 'M',
22  VALINE = 'V',
23  SERINE = 'S',
24  PROLINE = 'P',
25  THREONINE = 'T',
26  ALANINE = 'A',
27  TYROSINE = 'Y',
28  STOP_CODON = '.',
29  HISTIDYNE = 'H',
30  GLUTAMINE = 'Q',
31  ASPARAGINE = 'N',
32  LYSINE = 'K',
33  ASPARTIC = 'D',
34  GLUTAMIC = 'E',
35  CYSTEINE = 'C',
36  TRYPTOPHAN = 'W',
37  ARGININE = 'R',
38  GLYCINE = 'G',
39  UNKNOWN = '?'};
40 
41  /** \brief codons for given amino, amino for given codon, singleton
42 
43  The objects store the maps between codons and aminos.
44  */
46  public:
47  static CodonAminoTable& getInstance() {
48  static CodonAminoTable instance;
49  return instance;
50  }
51 
52  /** return amino for given codon */
53  AminoAcid getAmino(const Codon& codon) const;
54 
55  /** return set of codons for given amino (all codons) */
56  std::set<Codon> getCodons(AminoAcid amino) const;
57 
58  /** return the set of codons for given codon which are equivalent (codes the same amino) */
59  std::set<Codon> getCodons(const Codon& codon) const;
60 
61  private:
62  /** singleton, c-tor not allowed */
64  /** singleton, copy c-tor not allowed */
66 
67  void makeInvertedMap();
68 
69  typedef std::map<Codon, AminoAcid> CodonMap;
70  typedef std::multimap<AminoAcid, Codon> InvertedCodonMap;
71  CodonMap codonMap_;
72  InvertedCodonMap invertedCodonMap_;
73  };
74 
75  inline CodonAminoTable::CodonAminoTable() {
76  codonMap_.insert(std::make_pair(Codon("TTT"),PHENYLALANINE));
77  codonMap_.insert(std::make_pair(Codon("TTC"),PHENYLALANINE));
78  codonMap_.insert(std::make_pair(Codon("TTA"),LEUCINE));
79  codonMap_.insert(std::make_pair(Codon("TTG"),LEUCINE));
80  codonMap_.insert(std::make_pair(Codon("CTT"),LEUCINE));
81  codonMap_.insert(std::make_pair(Codon("CTC"),LEUCINE));
82  codonMap_.insert(std::make_pair(Codon("CTA"),LEUCINE));
83  codonMap_.insert(std::make_pair(Codon("CTG"),LEUCINE));
84  codonMap_.insert(std::make_pair(Codon("ATT"),ISOLEUCINE));
85  codonMap_.insert(std::make_pair(Codon("ATC"),ISOLEUCINE));
86  codonMap_.insert(std::make_pair(Codon("ATA"),ISOLEUCINE));
87  codonMap_.insert(std::make_pair(Codon("ATG"),METHIONINE));
88  codonMap_.insert(std::make_pair(Codon("GTT"),VALINE));
89  codonMap_.insert(std::make_pair(Codon("GTC"),VALINE));
90  codonMap_.insert(std::make_pair(Codon("GTA"),VALINE));
91  codonMap_.insert(std::make_pair(Codon("GTG"),VALINE));
92  codonMap_.insert(std::make_pair(Codon("TCT"),SERINE));
93  codonMap_.insert(std::make_pair(Codon("TCC"),SERINE));
94  codonMap_.insert(std::make_pair(Codon("TCA"),SERINE));
95  codonMap_.insert(std::make_pair(Codon("TCG"),SERINE));
96  codonMap_.insert(std::make_pair(Codon("CCT"),PROLINE));
97  codonMap_.insert(std::make_pair(Codon("CCC"),PROLINE));
98  codonMap_.insert(std::make_pair(Codon("CCA"),PROLINE));
99  codonMap_.insert(std::make_pair(Codon("CCG"),PROLINE));
100  codonMap_.insert(std::make_pair(Codon("ACT"),THREONINE));
101  codonMap_.insert(std::make_pair(Codon("ACC"),THREONINE));
102  codonMap_.insert(std::make_pair(Codon("ACA"),THREONINE));
103  codonMap_.insert(std::make_pair(Codon("ACG"),THREONINE));
104  codonMap_.insert(std::make_pair(Codon("GCT"),ALANINE));
105  codonMap_.insert(std::make_pair(Codon("GCC"),ALANINE));
106  codonMap_.insert(std::make_pair(Codon("GCA"),ALANINE));
107  codonMap_.insert(std::make_pair(Codon("GCG"),ALANINE));
108  codonMap_.insert(std::make_pair(Codon("TAT"),TYROSINE));
109  codonMap_.insert(std::make_pair(Codon("TAC"),TYROSINE));
110  codonMap_.insert(std::make_pair(Codon("TAA"),STOP_CODON));//stop
111  codonMap_.insert(std::make_pair(Codon("TAG"),STOP_CODON));//stop
112  codonMap_.insert(std::make_pair(Codon("CAT"),HISTIDYNE));
113  codonMap_.insert(std::make_pair(Codon("CAC"),HISTIDYNE));
114  codonMap_.insert(std::make_pair(Codon("CAA"),GLUTAMINE));
115  codonMap_.insert(std::make_pair(Codon("CAG"),GLUTAMINE));
116  codonMap_.insert(std::make_pair(Codon("AAT"),ASPARAGINE));
117  codonMap_.insert(std::make_pair(Codon("AAC"),ASPARAGINE));
118  codonMap_.insert(std::make_pair(Codon("AAA"),LYSINE));
119  codonMap_.insert(std::make_pair(Codon("AAG"),LYSINE));
120  codonMap_.insert(std::make_pair(Codon("GAT"),ASPARTIC));
121  codonMap_.insert(std::make_pair(Codon("GAC"),ASPARTIC));
122  codonMap_.insert(std::make_pair(Codon("GAA"),GLUTAMIC));
123  codonMap_.insert(std::make_pair(Codon("GAG"),GLUTAMIC));
124  codonMap_.insert(std::make_pair(Codon("TGT"),CYSTEINE));
125  codonMap_.insert(std::make_pair(Codon("TGC"),CYSTEINE));//stop
126  codonMap_.insert(std::make_pair(Codon("TGA"),STOP_CODON));
127  codonMap_.insert(std::make_pair(Codon("TGG"),TRYPTOPHAN));
128  codonMap_.insert(std::make_pair(Codon("CGT"),ARGININE));
129  codonMap_.insert(std::make_pair(Codon("CGA"),ARGININE));
130  codonMap_.insert(std::make_pair(Codon("CGC"),ARGININE));
131  codonMap_.insert(std::make_pair(Codon("CGG"),ARGININE));
132  codonMap_.insert(std::make_pair(Codon("AGT"),SERINE));
133  codonMap_.insert(std::make_pair(Codon("AGC"),SERINE));
134  codonMap_.insert(std::make_pair(Codon("AGA"),ARGININE));
135  codonMap_.insert(std::make_pair(Codon("AGG"),ARGININE));
136  codonMap_.insert(std::make_pair(Codon("GGT"),GLYCINE));
137  codonMap_.insert(std::make_pair(Codon("GGC"),GLYCINE));
138  codonMap_.insert(std::make_pair(Codon("GGA"),GLYCINE));
139  codonMap_.insert(std::make_pair(Codon("GGG"),GLYCINE));
140 
141  makeInvertedMap();
142  }
143 
144  inline void CodonAminoTable::makeInvertedMap() {
145  for(CodonMap::const_iterator it = codonMap_.begin(); it != codonMap_.end(); ++it) {
146  invertedCodonMap_.insert(std::make_pair(it->second, it->first));
147  }
148  }
149 
150  /** \brief the amino for given codon */
151  inline AminoAcid CodonAminoTable::getAmino(const Codon& codon) const {
152  CodonMap::const_iterator p = codonMap_.find(codon);
153  if( p != codonMap_.end() )
154  return p->second;
155  else
156  return UNKNOWN;
157  }
158 
159  /** \brief codons for given amino */
160  inline std::set<Codon> CodonAminoTable::getCodons(AminoAcid amino) const {
161  typedef InvertedCodonMap::const_iterator It;
162 
163  std::pair<It,It> p = invertedCodonMap_.equal_range(amino);
164  std::set<Codon> codons;
165  for(It i = p.first; i != p.second; ++i )
166  codons.insert(i->second );
167  return codons;
168  }
169 
170  /** \brief equiwalent codons */
171  inline std::set<Codon> CodonAminoTable::getCodons(const Codon& codon) const {
172  return getCodons( getAmino(codon) );
173  }
174 
175 
176  /** \brief ostream for amino */
177  inline std::ostream& operator<<(std::ostream& os, const AminoAcid& n) {
178  os << static_cast<char>(n);
179  return os;
180  }
181 
182 
183  } //namespace dna
184 } //namespace faif
185 
186 #endif
AminoAcid getAmino(const Codon &codon) const
the amino for given codon
Definition: CodonAminoTable.h:151
Definition: Chain.h:17
AminoAcid
Definition: CodonAminoTable.h:17
codons for given amino, amino for given codon, singleton
Definition: CodonAminoTable.h:45
the triplet of nucleotides, codon.
Definition: Codon.h:20
std::ostream & operator<<(std::ostream &os, const Chain &chain)
Definition: Chain.h:162
std::set< Codon > getCodons(AminoAcid amino) const
codons for given amino
Definition: CodonAminoTable.h:160