41 #include "../SequenceTools.h" 42 #include "../Alphabet/AlphabetTools.h" 50 Exception(
"StopCodonException: " + text +
"(" + codon +
")"),
58 throw StopCodonException(
"GeneticCode::translate().", codonAlphabet_.intToChar(state));
60 map<int, int>::const_iterator it = tlnTable_.find(state);
61 if (it == tlnTable_.end())
71 int x = codonAlphabet_.charToInt(state);
72 return proteicAlphabet_.intToChar(translate(x));
80 proteicAlphabet_.intToChar(aminoacid);
82 vector<int> synonymes;
83 for (
int i = 0; i < static_cast<int>(codonAlphabet_.getSize()); ++i)
87 if (translate(i) == aminoacid)
88 synonymes.push_back(i);
101 int aa = proteicAlphabet_.charToInt(aminoacid);
103 vector<string> synonymes;
104 for (
int i = 0; i < static_cast<int>(codonAlphabet_.getSize()); ++i)
108 if (translate(i) == aa)
109 synonymes.push_back(codonAlphabet_.intToChar(i));
128 for (
int an = 0; an < 4; an++)
132 vector<int> mutcodon = codon;
152 size_t stopPos = sequence.
size();
156 if (lookForInitCodon)
158 for (
size_t i = 0; i < sequence.size(); i++)
160 vector<int> pos = codonAlphabet_.getPositions(sequence[i]);
161 if (pos[0] == 0 && pos[1] == 3 && pos[2] == 2)
163 initPos = includeInitCodon ? i : i + 1;
169 for (
size_t i = initPos; i < sequence.size(); i++)
171 if (isStop(sequence[i]))
181 if (lookForInitCodon)
183 for (
size_t i = 0; i < sequence.size() - 2; i++)
185 if (sequence[i] == 0 && sequence[i + 1] == 3 && sequence[i + 2] == 2)
187 initPos = includeInitCodon ? i : i + 3;
194 for (
size_t i = initPos; i < sequence.size() - 2; i += 3)
196 string codon = nucAlpha->
intToChar(sequence[i])
207 throw AlphabetMismatchException(
"Sequence must have alphabet of type nucleic or codon in GeneticCode::getCodingSequence.", 0, sequence.getAlphabet());
bool isFourFoldDegenerated(int codon) const
An alphabet exception thrown when trying to specify a bad char to the alphabet.
Sequence * getCodingSequence(const Sequence &sequence, bool lookForInitCodon=false, bool includeInitCodon=false) const
Get the subsequence corresponding to the coding part of a given sequence.
This alphabet is used to deal NumericAlphabet.
virtual int getCodon(int pos1, int pos2, int pos3) const
Get the int code for a codon given the int code of the three underlying positions.
std::vector< int > getPositions(int word) const
Get the int codes of each position of a word given its int description.
CodonAlphabet codonAlphabet_
std::vector< int > getSynonymous(int aminoacid) const
StopCodonException(const std::string &text, const std::string &codon)
virtual size_t size() const =0
Get the number of elements in the list.
virtual bool isStop(int state) const =0
Tells is a particular codon is a stop codon.
Exception thrown when a stop codon is found.
An alphabet exception thrown when trying to specify a bad int to the alphabet.
Exception thrown when two alphabets do not match.
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.