5 #ifndef BPP_SEQ_ALPHABET_CODONALPHABET_H
6 #define BPP_SEQ_ALPHABET_CODONALPHABET_H
33 std::shared_ptr<const NucleicAlphabet>
nAlph_;
73 return "Codon(letter=" +
nAlph_->getAlphabetType() +
")";
84 bool containsGap(
const std::string& state)
const override;
118 bool isResolvedIn(
int state1,
int state2)
const override;
120 std::vector<int>
getAlias(
int state)
const override;
122 std::vector<std::string>
getAlias(
const std::string& state)
const override;
124 int getGeneric(
const std::vector<int>& states)
const override
129 std::string
getGeneric(
const std::vector<std::string>& states)
const override
136 if (state.size() != 3)
139 return static_cast<int>(
getSize());
162 return (
nAlph_->isUnresolved(pos1)
163 ||
nAlph_->isUnresolved(pos2)
165 : pos3 + 4 * pos2 + 16 * pos1;
183 std::string
getCodon(
const std::string& pos1,
const std::string& pos2,
const std::string& pos3)
const
185 return pos1 + pos2 + pos3;
230 return codon.substr(0, 1);
242 return codon.substr(1, 1);
254 return codon.substr(2, 1);
280 if (seq.
size() < pos + 3)
282 return getCodon(seq[pos], seq[pos + 1], seq[pos + 2]);
295 std::string
getWord(
const std::vector<std::string>& vpos,
size_t pos = 0)
const override
297 if (vpos.size() < pos + 3)
300 return getCodon(vpos[pos], vpos[pos + 1], vpos[pos + 2]);
303 int getWord(
const std::vector<int>& vpos,
size_t pos = 0)
const override
305 if (vpos.size() < pos + 3)
308 return getCodon(vpos[pos], vpos[pos + 1], vpos[pos + 2]);
315 return nAlph_->getUnknownCharacterCode();
317 return pos == 0 ? codon / 16 :
318 (pos == 1 ? (codon / 4) % 4
332 int n =
nAlph_->getUnknownCharacterCode();
333 return std::vector<int>{n, n, n};
336 return std::vector<int>{word / 16, (word / 4) % 4, word % 4}
348 std::string
getNPosition(
const std::string& codon,
size_t pos)
const override
350 return codon.substr(pos, 1);
359 std::vector<std::string>
getPositions(
const std::string& word)
const override
361 return std::vector<std::string>{word.substr(0, 1), word.substr(1, 1), word.substr(2, 1)};
A partial implementation of the Alphabet interface.
AbstractAlphabet & operator=(const AbstractAlphabet &alph)
int charToInt(const std::string &state) const
Give the int description of a state given its string description.
size_t size() const override
Get the number of elements in the list.
An alphabet exception thrown when trying to specify a bad char to the alphabet.
std::vector< int > getAlias(int state) const override
Get all resolved states that match a generic state.
bool isResolvedIn(int state1, int state2) const override
Tells if a given (potentially unresolved) state can be resolved in another resolved state.
std::vector< int > getPositions(int word) const override
Get the int codes of each position of a word given its int description.
bool isUnresolved(const std::string &state) const override
std::unique_ptr< SequenceInterface > reverse(const SequenceInterface &sequence) const override
Translate a whole sequence from words alphabet to letters alphabet.
int getGCinCodon(int codon) const
Get the number of G+C in codon.
int getWord(const Sequence &seq, size_t pos=0) const override
bool isUnresolved(int state) const override
bool containsGap(const std::string &state) const override
int getThirdPosition(int codon) const
Get the int code of the third position of a codon given its int description.
int getWord(const std::vector< int > &vpos, size_t pos=0) const override
Get the int code for a word given the int code of the underlying positions.
int charToInt(const std::string &state) const override
Give the int description of a state given its string description.
std::string getNPosition(const std::string &codon, size_t pos) const override
Get the char code of the Nth position of a codon given its char description.
int getNPosition(int codon, size_t pos) const override
Get the int code of the n-position of a word given its int description.
unsigned int getLength() const override
std::string getWord(const std::vector< std::string > &vpos, size_t pos=0) const override
Get the char code for a word given the char code of the underlying positions.
unsigned int getStateCodingSize() const override
Get the size of the string coding a state.
int getUnknownCharacterCode() const override
std::string getAlphabetType() const override
Identification method.
int getFirstPosition(int codon) const
Get the int code of the first position of a codon given its int description.
CodonAlphabet * clone() const override
std::unique_ptr< SequenceInterface > translate(const SequenceInterface &sequence, size_t=0) const override
Translate a whole sequence from letters alphabet to words alphabet.
std::string getGeneric(const std::vector< std::string > &states) const override
Get the generic state that match a set of states.
std::shared_ptr< const NucleicAlphabet > nAlph_
std::shared_ptr< const Alphabet > getNAlphabet(size_t n) const override
CodonAlphabet & operator=(const CodonAlphabet &bia)
std::string getFirstPosition(const std::string &codon) const
Get the char code of the first position of a codon given its char description.
CodonAlphabet(std::shared_ptr< const NucleicAlphabet > alpha)
Builds a new codon alphabet from a nucleic alphabet.
std::string getCodon(const std::string &pos1, const std::string &pos2, const std::string &pos3) const
Get the char code for a codon given the char code of the three underlying positions.
unsigned int getNumberOfTypes() const override
Get the number of distinct states in alphabet (e.g. return 15 for DNA alphabet). This is the number o...
std::string getSecondPosition(const std::string &codon) const
Get the char code of the second position of a codon given its char description.
unsigned int getSize() const override
std::string getThirdPosition(const std::string &codon) const
Get the char code of the third position of a codon given its char description.
CodonAlphabet(const CodonAlphabet &bia)
std::vector< std::string > getPositions(const std::string &word) const override
Get the char codes of each position of a word given its char description.
std::shared_ptr< const NucleicAlphabet > getNucleicAlphabet() const
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.
bool containsUnresolved(const std::string &state) const override
int getSecondPosition(int codon) const
Get the int code of the second position of a codon given its int description.
int getGeneric(const std::vector< int > &states) const override
Get the generic state that match a set of states.
bool hasUniqueAlphabet() const override
The interface class for word alphabets.
A basic implementation of the Sequence interface.
This alphabet is used to deal NumericAlphabet.