bpp-seq  2.2.0
GeneticCode.h
Go to the documentation of this file.
1 //
2 // File: GeneticCode.h
3 // Created by: Julien Dutheil
4 // Created on: Mon Oct 13 15:37:25 2003
5 //
6 
7 /*
8  Copyright or © or Copr. Bio++ Development Team, (November 17, 2004)
9 
10  This software is a computer program whose purpose is to provide classes
11  for sequences analysis.
12 
13  This software is governed by the CeCILL license under French law and
14  abiding by the rules of distribution of free software. You can use,
15  modify and/ or redistribute the software under the terms of the CeCILL
16  license as circulated by CEA, CNRS and INRIA at the following URL
17  "http://www.cecill.info".
18 
19  As a counterpart to the access to the source code and rights to copy,
20  modify and redistribute granted by the license, users are provided only
21  with a limited warranty and the software's author, the holder of the
22  economic rights, and the successive licensors have only limited
23  liability.
24 
25  In this respect, the user's attention is drawn to the risks associated
26  with loading, using, modifying and/or developing or reproducing the
27  software by the user in light of its specific status of free software,
28  that may mean that it is complicated to manipulate, and that also
29  therefore means that it is reserved for developers and experienced
30  professionals having in-depth computer knowledge. Users are therefore
31  encouraged to load and test the software's suitability as regards their
32  requirements in conditions enabling the security of their systems and/or
33  data to be ensured and, more generally, to use and operate it in the
34  same conditions as regards security.
35 
36  The fact that you are presently reading this means that you have had
37  knowledge of the CeCILL license and that you accept its terms.
38 */
39 
40 #ifndef _GENETICCODE_H_
41 #define _GENETICCODE_H_
42 
43 #include "../Transliterator.h"
44 #include "../Alphabet/CodonAlphabet.h"
45 #include "../Alphabet/ProteicAlphabet.h"
46 #include <Bpp/Exceptions.h>
47 
48 namespace bpp
49 {
50 
55  public Exception
56  {
57  private:
58  std::string codon_;
59 
60  public:
61  // Class constructor
62  StopCodonException(const std::string& text, const std::string& codon);
63 
64  // Class destructor
65  virtual ~StopCodonException() throw () {}
66 
67  public:
68  virtual const std::string& getCodon() const { return codon_; }
69  };
70 
79  class GeneticCode:
81  public virtual Clonable
82  {
83  protected:
86  std::map<int, int> tlnTable_;
87 
88  public:
89  GeneticCode(const NucleicAlphabet* alphabet):
91  codonAlphabet_(alphabet),
93  tlnTable_()
94  {}
95 
96  virtual ~GeneticCode() {}
97 
98  virtual GeneticCode* clone() const = 0;
99 
100  public:
106  const CodonAlphabet* getSourceAlphabet() const { return &codonAlphabet_; }
108  virtual int translate(int state) const throw (BadIntException, Exception);
109  virtual std::string translate(const std::string& state) const throw (BadCharException, Exception);
110  virtual Sequence* translate(const Sequence& sequence) const throw (Exception)
111  {
112  return AbstractTransliterator::translate(sequence);
113  }
116  public:
126  virtual size_t getNumberOfStopCodons() const = 0;
127 
131  virtual std::vector<int> getStopCodonsAsInt() const = 0;
132 
136  virtual std::vector<std::string> getStopCodonsAsChar() const = 0;
137 
145  virtual bool isStop(int state) const throw (BadIntException) = 0;
146 
154  virtual bool isStop(const std::string& state) const throw (BadCharException) = 0;
155 
163  virtual bool isStart(int state) const throw (BadIntException) {
164  //Test:
165  codonAlphabet_.intToChar(state); //throw exception if invalid state!
166  return (state == 14);
167  }
168 
176  virtual bool isStart(const std::string& state) const throw (BadCharException) {
177  return isStart(codonAlphabet_.charToInt(state));
178  }
179 
187  virtual bool isAltStart(int state) const throw (BadIntException) = 0;
188 
196  virtual bool isAltStart(const std::string& state) const throw (BadCharException) = 0;
197 
206  bool areSynonymous(int i, int j) const throw (BadIntException)
207  {
208  return (translate(i) == translate(j));
209  }
210 
219  bool areSynonymous(const std::string & i, const std::string & j) const throw (BadCharException)
220  {
221  return (translate(i) == translate(j));
222  }
223 
224  std::vector<int> getSynonymous(int aminoacid) const throw (BadIntException);
225 
226  std::vector<std::string> getSynonymous(const std::string & aminoacid) const throw (BadCharException);
227 
234  bool isFourFoldDegenerated(int codon) const;
235 
253  Sequence* getCodingSequence(const Sequence& sequence, bool lookForInitCodon = false, bool includeInitCodon = false) const throw (Exception);
255  };
256 
257 } //end of namespace bpp.
258 
259 #endif //_GENETICCODE_H_
260 
virtual bool isAltStart(int state) const =0
Tells is a particular codon is an alternative start codon.
virtual Sequence * translate(const Sequence &sequence) const
Translate a whole sequence from source alphabet to target alphabet.
Definition: GeneticCode.h:110
bool isFourFoldDegenerated(int codon) const
virtual std::vector< std::string > getStopCodonsAsChar() const =0
An alphabet exception thrown when trying to specify a bad char to the alphabet.
virtual bool isStart(int state) const
Tells is a particular codon is a start codon.
Definition: GeneticCode.h:163
int charToInt(const std::string &state) const
Give the int description of a state given its string description.
Definition: WordAlphabet.h:127
Sequence * getCodingSequence(const Sequence &sequence, bool lookForInitCodon=false, bool includeInitCodon=false) const
Get the subsequence corresponding to the coding part of a given sequence.
virtual size_t getNumberOfStopCodons() const =0
This alphabet is used to deal NumericAlphabet.
const CodonAlphabet * getSourceAlphabet() const
Get the source alphabet.
Definition: GeneticCode.h:106
ProteicAlphabet proteicAlphabet_
Definition: GeneticCode.h:85
Partial implementation of the Transliterator interface.
bool areSynonymous(const std::string &i, const std::string &j) const
Tell if two codons are synonymous, that is, if they encode the same amino-acid.
Definition: GeneticCode.h:219
virtual bool isStart(const std::string &state) const
Tells is a particular codon is a start codon.
Definition: GeneticCode.h:176
This alphabet is used to deal with proteins.
Codon alphabet class.
Definition: CodonAlphabet.h:63
CodonAlphabet codonAlphabet_
Definition: GeneticCode.h:84
bool areSynonymous(int i, int j) const
Tell if two codons are synonymous, that is, if they encode the same amino-acid.
Definition: GeneticCode.h:206
const ProteicAlphabet * getTargetAlphabet() const
Get the target alphabet.
Definition: GeneticCode.h:107
virtual std::vector< int > getStopCodonsAsInt() const =0
std::vector< int > getSynonymous(int aminoacid) const
Definition: GeneticCode.cpp:77
GeneticCode(const NucleicAlphabet *alphabet)
Definition: GeneticCode.h:89
StopCodonException(const std::string &text, const std::string &codon)
Definition: GeneticCode.cpp:49
virtual int translate(int state) const =0
Translate a given state coded as a int from source alphabet to target alphabet.
virtual const std::string & getCodon() const
Definition: GeneticCode.h:68
virtual ~StopCodonException()
Definition: GeneticCode.h:65
virtual bool isStop(int state) const =0
Tells is a particular codon is a stop codon.
The sequence interface.
Definition: Sequence.h:74
virtual ~GeneticCode()
Definition: GeneticCode.h:96
Exception thrown when a stop codon is found.
Definition: GeneticCode.h:54
An alphabet exception thrown when trying to specify a bad int to the alphabet.
std::map< int, int > tlnTable_
Definition: GeneticCode.h:86
Partial implementation of the Transliterator interface for genetic code object.
Definition: GeneticCode.h:79
virtual GeneticCode * clone() const =0
The abstract base class for nucleic alphabets.
std::string intToChar(int state) const
Give the string description of a state given its int description.
virtual int translate(int state) const
Translate a given state coded as a int from source alphabet to target alphabet.
Definition: GeneticCode.cpp:55