bpp-seq3  3.0.0
bpp::CodonAlphabet Class Reference

Codon alphabet class. More...

#include <Bpp/Seq/Alphabet/CodonAlphabet.h>

+ Inheritance diagram for bpp::CodonAlphabet:
+ Collaboration diagram for bpp::CodonAlphabet:

Public Member Functions

 CodonAlphabet (std::shared_ptr< const NucleicAlphabet > alpha)
 Builds a new codon alphabet from a nucleic alphabet. More...
 
 CodonAlphabet (const CodonAlphabet &bia)
 
CodonAlphabetoperator= (const CodonAlphabet &bia)
 
CodonAlphabetclone () const override
 
virtual ~CodonAlphabet ()
 
std::string getAlphabetType () const override
 Identification method. More...
 
From AbstractAlphabet
unsigned int getNumberOfTypes () const override
 Get the number of distinct states in alphabet (e.g. return 15 for DNA alphabet). This is the number of integers used for state description. More...
 
unsigned int getSize () const override
 
int getUnknownCharacterCode () const override
 
bool isUnresolved (int state) const override
 
bool isUnresolved (const std::string &state) const override
 
bool isResolvedIn (int state1, int state2) const override
 Tells if a given (potentially unresolved) state can be resolved in another resolved state. More...
 
std::vector< int > getAlias (int state) const override
 Get all resolved states that match a generic state. More...
 
std::vector< std::string > getAlias (const std::string &state) const override
 Get all resolved states that match a generic state. More...
 
int getGeneric (const std::vector< int > &states) const override
 Get the generic state that match a set of states. More...
 
std::string getGeneric (const std::vector< std::string > &states) const override
 Get the generic state that match a set of states. More...
 
int charToInt (const std::string &state) const override
 Give the int description of a state given its string description. More...
 
Codon specific methods
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. More...
 
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. More...
 
int getFirstPosition (int codon) const
 Get the int code of the first position of a codon given its int description. More...
 
int getSecondPosition (int codon) const
 Get the int code of the second position of a codon given its int description. More...
 
int getThirdPosition (int codon) const
 Get the int code of the third position of a codon given its int description. More...
 
std::string getFirstPosition (const std::string &codon) const
 Get the char code of the first position of a codon given its char description. More...
 
std::string getSecondPosition (const std::string &codon) const
 Get the char code of the second position of a codon given its char description. More...
 
std::string getThirdPosition (const std::string &codon) const
 Get the char code of the third position of a codon given its char description. More...
 
From CoreWordAlphabet
unsigned int getLength () const override
 
bool hasUniqueAlphabet () const override
 
std::shared_ptr< const AlphabetgetNAlphabet (size_t n) const override
 
int getWord (const Sequence &seq, size_t pos=0) 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. More...
 
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. More...
 
int getNPosition (int codon, size_t pos) const override
 Get the int code of the n-position of a word given its int description. More...
 
std::vector< int > getPositions (int word) const override
 Get the int codes of each position of a word given its int description. More...
 
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. More...
 
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. More...
 
std::unique_ptr< SequenceInterfacetranslate (const SequenceInterface &sequence, size_t=0) const override
 Translate a whole sequence from letters alphabet to words alphabet. More...
 
std::unique_ptr< SequenceInterfacereverse (const SequenceInterface &sequence) const override
 Translate a whole sequence from words alphabet to letters alphabet. More...
 
int getGCinCodon (int codon) const
 Get the number of G+C in codon. More...
 
std::shared_ptr< const NucleicAlphabetgetNucleicAlphabet () const
 
Overloaded AbstractAlphabet methods.
unsigned int getStateCodingSize () const override
 Get the size of the string coding a state. More...
 
Implement these methods from the Alphabet interface.
size_t getNumberOfStates () const
 This is a convenient alias for getNumberOfChars(), returning a size_t instead of unsigned int. More...
 
unsigned int getNumberOfChars () const
 Get the number of supported characters in this alphabet, including generic characters (e.g. return 20 for DNA alphabet). More...
 
std::string getName (const std::string &state) const
 Get the complete name of a state given its string description. More...
 
std::string getName (int state) const
 Get the complete name of a state given its int description. More...
 
std::string intToChar (int state) const
 Give the string description of a state given its int description. More...
 
bool isIntInAlphabet (int state) const
 Tell if a state (specified by its int description) is allowed by the the alphabet. More...
 
bool isCharInAlphabet (const std::string &state) const
 Tell if a state (specified by its string description) is allowed by the the alphabet. More...
 
const std::vector< int > & getSupportedInts () const
 
const std::vector< std::string > & getSupportedChars () const
 
const std::vector< std::string > & getResolvedChars () const
 
int getGapCharacterCode () const
 
bool isGap (int state) const
 
bool isGap (const std::string &state) const
 
Specific methods to access AlphabetState
virtual AlphabetStategetStateAt (size_t stateIndex)
 Get a state at a position in the alphabet_ vector. More...
 
virtual const AlphabetStategetStateAt (size_t stateIndex) const
 Get a state at a position in the alphabet_ vector. More...
 
const AlphabetStategetState (const std::string &letter) const
 Get a state by its letter. More...
 
AlphabetStategetState (const std::string &letter)
 
const AlphabetStategetState (int num) const
 Get a state by its num. More...
 
AlphabetStategetState (int num)
 
int getIntCodeAt (size_t stateIndex) const
 
const std::string & getCharCodeAt (size_t stateIndex) const
 
size_t getStateIndex (int state) const
 
size_t getStateIndex (const std::string &state) const
 

Protected Member Functions

virtual void registerState (AlphabetState *st)
 Add a state to the Alphabet. More...
 
virtual void setState (size_t pos, AlphabetState *st)
 Set a state in the Alphabet. More...
 
void resize (size_t size)
 Resize the private alphabet_ vector. More...
 
void remap ()
 Re-update the maps using the alphabet_ vector content. More...
 
bool equals (const Alphabet &alphabet) const
 Comparison of alphabets. More...
 

Protected Attributes

std::shared_ptr< const NucleicAlphabetnAlph_
 
Available codes

These vectors will be computed the first time you call the getAvailableInts or getAvailableChars method.

std::vector< std::string > charList_
 
std::vector< int > intList_
 

Private Member Functions

void updateMaps_ (size_t pos, const AlphabetState &st)
 Update the private maps letters_ and nums_ when adding a state. More...
 
Inner utilitary functions
bool containsUnresolved (const std::string &state) const override
 
bool containsGap (const std::string &state) const override
 
void build_ ()
 

Private Attributes

std::vector< AlphabetState * > alphabet_
 Alphabet: vector of AlphabetState. More...
 
maps used to quick search for letter and num.
std::map< std::string, size_t > letters_
 
std::map< int, size_t > nums_
 

Detailed Description

Codon alphabet class.

Author
Laurent Guéguen, Julien Dutheil

Since codons are made of 3 nucleic bases (RNA or DNA), this class has a NucleicAlphabet field used to check char description. This nucleic alphabet is passed to the constructor. This class also adds some methods specific to codon manipulation.

Definition at line 28 of file CodonAlphabet.h.

Constructor & Destructor Documentation

◆ CodonAlphabet() [1/2]

bpp::CodonAlphabet::CodonAlphabet ( std::shared_ptr< const NucleicAlphabet alpha)
inline

Builds a new codon alphabet from a nucleic alphabet.

Parameters
alphaThe nucleic alphabet to be used.

Definition at line 43 of file CodonAlphabet.h.

References build_().

Referenced by clone().

◆ CodonAlphabet() [2/2]

bpp::CodonAlphabet::CodonAlphabet ( const CodonAlphabet bia)
inline

Definition at line 50 of file CodonAlphabet.h.

◆ ~CodonAlphabet()

virtual bpp::CodonAlphabet::~CodonAlphabet ( )
inlinevirtual

Definition at line 68 of file CodonAlphabet.h.

Member Function Documentation

◆ build_()

void CodonAlphabet::build_ ( )
private

Definition at line 17 of file CodonAlphabet.cpp.

Referenced by CodonAlphabet().

◆ charToInt()

int bpp::CodonAlphabet::charToInt ( const std::string &  state) const
inlineoverridevirtual

Give the int description of a state given its string description.

Parameters
stateThe string description.
Returns
The int description.
Exceptions
BadCharExceptionWhen state is not a valid char description.

Reimplemented from bpp::AbstractAlphabet.

Definition at line 134 of file CodonAlphabet.h.

References bpp::AbstractAlphabet::charToInt(), containsGap(), containsUnresolved(), and getSize().

Referenced by isUnresolved().

◆ clone()

CodonAlphabet* bpp::CodonAlphabet::clone ( ) const
inlineoverridevirtual

Implements bpp::AbstractAlphabet.

Definition at line 63 of file CodonAlphabet.h.

References CodonAlphabet().

◆ containsGap()

bool CodonAlphabet::containsGap ( const std::string &  state) const
overrideprivatevirtual

Implements bpp::CoreWordAlphabet.

Definition at line 80 of file CodonAlphabet.cpp.

Referenced by charToInt().

◆ containsUnresolved()

bool CodonAlphabet::containsUnresolved ( const std::string &  state) const
overrideprivatevirtual

Implements bpp::CoreWordAlphabet.

Definition at line 63 of file CodonAlphabet.cpp.

Referenced by charToInt().

◆ equals()

bool bpp::AbstractAlphabet::equals ( const Alphabet alphabet) const
inlineprotectedvirtualinherited

Comparison of alphabets.

Returns
true If the two instances are of the same class.

Implements bpp::Alphabet.

Definition at line 243 of file AbstractAlphabet.h.

References bpp::Alphabet::getAlphabetType().

◆ getAlias() [1/2]

std::vector< std::string > CodonAlphabet::getAlias ( const std::string &  state) const
overridevirtual

Get all resolved states that match a generic state.

If the given state is not a generic code then the output vector will contain this unique code.

Parameters
stateThe alias to resolve.
Returns
A vector of resolved states.
Exceptions
BadCharExceptionWhen state is not a valid char description.

Reimplemented from bpp::AbstractAlphabet.

Definition at line 155 of file CodonAlphabet.cpp.

References bpp::TextTools::toUpper().

◆ getAlias() [2/2]

std::vector< int > CodonAlphabet::getAlias ( int  state) const
overridevirtual

Get all resolved states that match a generic state.

If the given state is not a generic code then the output vector will contain this unique code.

Parameters
stateThe alias to resolve.
Returns
A vector of resolved states.
Exceptions
BadIntExceptionWhen state is not a valid integer.

Reimplemented from bpp::AbstractAlphabet.

Definition at line 132 of file CodonAlphabet.cpp.

◆ getAlphabetType()

std::string bpp::CodonAlphabet::getAlphabetType ( ) const
inlineoverridevirtual

Identification method.

Used to tell if two alphabets describe the same type of sequences. For instance, this method is used by sequence containers to compare two alphabets and allow or deny addition of sequences.

Returns
A text describing the alphabet.

Implements bpp::Alphabet.

Definition at line 71 of file CodonAlphabet.h.

References nAlph_.

◆ getCharCodeAt()

const std::string& bpp::AbstractAlphabet::getCharCodeAt ( size_t  stateIndex) const
inlinevirtualinherited
Returns
The char code of a given state.
Parameters
stateIndexThe index of the state to fetch.

Implements bpp::Alphabet.

Definition at line 192 of file AbstractAlphabet.h.

References bpp::AlphabetState::getLetter(), and bpp::AbstractAlphabet::getStateAt().

◆ getCodon() [1/2]

std::string bpp::CodonAlphabet::getCodon ( const std::string &  pos1,
const std::string &  pos2,
const std::string &  pos3 
) const
inline

Get the char code for a codon given the char code of the three underlying positions.

The char code of each position must match the nucleic alphabet specified for this alphabet.

NB: This performs pos1 + pos2 + pos3 after checking for each position validity.

Parameters
pos1Char description for position 1.
pos2Char description for position 2.
pos3Char description for position 3.
Returns
The Char code of the codon.

Definition at line 183 of file CodonAlphabet.h.

◆ getCodon() [2/2]

int bpp::CodonAlphabet::getCodon ( int  pos1,
int  pos2,
int  pos3 
) const
inline

Get the int code for a codon given the int code of the three underlying positions.

The int code of each position must match the nucleic alphabet specified for this alphabet.

Parameters
pos1Int description for position 1.
pos2Int description for position 2.
pos3Int description for position 3.
Returns
The int code of the codon.

Definition at line 160 of file CodonAlphabet.h.

References getUnknownCharacterCode(), and nAlph_.

Referenced by getWord().

◆ getFirstPosition() [1/2]

std::string bpp::CodonAlphabet::getFirstPosition ( const std::string &  codon) const
inline

Get the char code of the first position of a codon given its char description.

Parameters
codonThe char description of the codon.
Returns
The char description of the first position of the codon.

Definition at line 228 of file CodonAlphabet.h.

◆ getFirstPosition() [2/2]

int bpp::CodonAlphabet::getFirstPosition ( int  codon) const
inline

Get the int code of the first position of a codon given its int description.

Parameters
codonThe int description of the codon.
Returns
The int description of the first position of the codon.

Definition at line 194 of file CodonAlphabet.h.

References isUnresolved(), and nAlph_.

Referenced by bpp::CodonSiteTools::numberOfDifferences().

◆ getGapCharacterCode()

int bpp::AbstractAlphabet::getGapCharacterCode ( ) const
inlinevirtualinherited
Returns
The int code for gap characters.

Implements bpp::Alphabet.

Definition at line 130 of file AbstractAlphabet.h.

◆ getGCinCodon()

int CodonAlphabet::getGCinCodon ( int  codon) const

Get the number of G+C in codon.

Parameters
codonThe int description of the codon.
Returns
The number of G+C in codon

Definition at line 47 of file CodonAlphabet.cpp.

◆ getGeneric() [1/2]

int bpp::CodonAlphabet::getGeneric ( const std::vector< int > &  states) const
inlineoverridevirtual

Get the generic state that match a set of states.

If the given states contain generic code, each generic code is first resolved and then the new generic state is returned. If only a single resolved state is given the function return this state.

Parameters
statesA vector of states to resolve.
Returns
A int code for the computed state.
Exceptions
BadIntExceptionWhen a state is not a valid integer.

Reimplemented from bpp::AbstractAlphabet.

Definition at line 124 of file CodonAlphabet.h.

◆ getGeneric() [2/2]

std::string bpp::CodonAlphabet::getGeneric ( const std::vector< std::string > &  states) const
inlineoverridevirtual

Get the generic state that match a set of states.

If the given states contain generic code, each generic code is first resolved and then the new generic state is returned. If only a single resolved state is given the function return this state.

Parameters
statesA vector of states to resolve.
Returns
A string code for the computed state.
Exceptions
BadCharExceptionwhen a state is not a valid char description.
CharStateNotSupportedExceptionwhen the alphabet does not support Char state for unresolved state.

Reimplemented from bpp::AbstractAlphabet.

Definition at line 129 of file CodonAlphabet.h.

◆ getIntCodeAt()

int bpp::AbstractAlphabet::getIntCodeAt ( size_t  stateIndex) const
inlinevirtualinherited
Returns
The int code of a given state.
Parameters
stateIndexThe index of the state to fetch.

Implements bpp::Alphabet.

Definition at line 187 of file AbstractAlphabet.h.

References bpp::AlphabetState::getNum(), and bpp::AbstractAlphabet::getStateAt().

◆ getLength()

unsigned int bpp::CodonAlphabet::getLength ( ) const
inlineoverridevirtual

Implements bpp::CoreWordAlphabet.

Definition at line 263 of file CodonAlphabet.h.

◆ getNAlphabet()

std::shared_ptr<const Alphabet> bpp::CodonAlphabet::getNAlphabet ( size_t  n) const
inlineoverridevirtual

Implements bpp::CoreWordAlphabet.

Definition at line 273 of file CodonAlphabet.h.

References nAlph_.

◆ getName() [1/2]

std::string AbstractAlphabet::getName ( const std::string &  state) const
virtualinherited

Get the complete name of a state given its string description.

In case of several states with identical number (i.e. N and X for nucleic alphabets), this method will return the name of the first found in the vector.

Parameters
stateThe string description of the given state.
Returns
The name of the state.
Exceptions
BadCharExceptionWhen state is not a valid char description.

Implements bpp::Alphabet.

Reimplemented in bpp::WordAlphabet.

Definition at line 139 of file AbstractAlphabet.cpp.

Referenced by bpp::WordAlphabet::getName(), and bpp::LexicalAlphabet::LexicalAlphabet().

◆ getName() [2/2]

std::string AbstractAlphabet::getName ( int  state) const
virtualinherited

Get the complete name of a state given its int description.

In case of several states with identical number (i.e. N and X for nucleic alphabets), this method returns the name of the first found in the vector.

Parameters
stateThe int description of the given state.
Returns
The name of the state.
Exceptions
BadIntExceptionWhen state is not a valid integer.

Implements bpp::Alphabet.

Definition at line 146 of file AbstractAlphabet.cpp.

◆ getNPosition() [1/2]

std::string bpp::CodonAlphabet::getNPosition ( const std::string &  codon,
size_t  pos 
) const
inlineoverridevirtual

Get the char code of the Nth position of a codon given its char description.

Parameters
codonThe char description of the codon.
posthe position in the codon (starting at 0)
Returns
The char description of the position of the codon.

Implements bpp::CoreWordAlphabet.

Definition at line 348 of file CodonAlphabet.h.

◆ getNPosition() [2/2]

int bpp::CodonAlphabet::getNPosition ( int  word,
size_t  n 
) const
inlineoverridevirtual

Get the int code of the n-position of a word given its int description.

Parameters
wordThe int description of the word.
nThe position in the word (starting at 0).
Returns
The int description of the n-position of the word.

Implements bpp::CoreWordAlphabet.

Definition at line 312 of file CodonAlphabet.h.

References isUnresolved(), and nAlph_.

◆ getNucleicAlphabet()

std::shared_ptr<const NucleicAlphabet> bpp::CodonAlphabet::getNucleicAlphabet ( ) const
inline
Returns
The nucleic alphabet associated to this codon alphabet.

Definition at line 401 of file CodonAlphabet.h.

References nAlph_.

◆ getNumberOfChars()

unsigned int bpp::AbstractAlphabet::getNumberOfChars ( ) const
inlinevirtualinherited

Get the number of supported characters in this alphabet, including generic characters (e.g. return 20 for DNA alphabet).

Returns
The total number of supported character descriptions.

Implements bpp::Alphabet.

Definition at line 115 of file AbstractAlphabet.h.

References bpp::AbstractAlphabet::alphabet_.

Referenced by bpp::LexicalAlphabet::getNumberOfTypes(), bpp::AllelicAlphabet::getNumberOfTypes(), bpp::WordAlphabet::getNumberOfTypes(), bpp::LexicalAlphabet::getSize(), bpp::AllelicAlphabet::getSize(), bpp::WordAlphabet::getSize(), and bpp::NucleicAlphabet::registerState().

◆ getNumberOfStates()

size_t bpp::AbstractAlphabet::getNumberOfStates ( ) const
inlinevirtualinherited

This is a convenient alias for getNumberOfChars(), returning a size_t instead of unsigned int.

This function is typically used il loops over all states of an alphabet.

Implements bpp::Alphabet.

Definition at line 114 of file AbstractAlphabet.h.

References bpp::AbstractAlphabet::alphabet_.

Referenced by bpp::LexicalAlphabet::getAlphabetType().

◆ getNumberOfTypes()

unsigned int bpp::CodonAlphabet::getNumberOfTypes ( ) const
inlineoverridevirtual

Get the number of distinct states in alphabet (e.g. return 15 for DNA alphabet). This is the number of integers used for state description.

Returns
The number of distinct states.

Implements bpp::Alphabet.

Definition at line 96 of file CodonAlphabet.h.

◆ getPositions() [1/2]

std::vector<std::string> bpp::CodonAlphabet::getPositions ( const std::string &  word) const
inlineoverridevirtual

Get the char codes of each position of a word given its char description.

Parameters
wordThe char description of the word.
Returns
The char description of the three positions of the word.

Implements bpp::CoreWordAlphabet.

Definition at line 359 of file CodonAlphabet.h.

◆ getPositions() [2/2]

std::vector<int> bpp::CodonAlphabet::getPositions ( int  word) const
inlineoverridevirtual

Get the int codes of each position of a word given its int description.

Parameters
wordThe int description of the word.
Returns
The int description of the positions of the codon.

Implements bpp::CoreWordAlphabet.

Definition at line 328 of file CodonAlphabet.h.

References isUnresolved(), and nAlph_.

◆ getResolvedChars()

const std::vector< std::string > & AbstractAlphabet::getResolvedChars ( ) const
virtualinherited
Returns
A list of all resolved character codes.

Note for developers of new alphabets: we return a const reference here since the list is supposed to be stored within the class and should not be modified outside the class.

Implements bpp::Alphabet.

Definition at line 327 of file AbstractAlphabet.cpp.

◆ getSecondPosition() [1/2]

std::string bpp::CodonAlphabet::getSecondPosition ( const std::string &  codon) const
inline

Get the char code of the second position of a codon given its char description.

Parameters
codonThe char description of the codon.
Returns
The char description of the second position of the codon.

Definition at line 240 of file CodonAlphabet.h.

◆ getSecondPosition() [2/2]

int bpp::CodonAlphabet::getSecondPosition ( int  codon) const
inline

Get the int code of the second position of a codon given its int description.

Parameters
codonThe int description of the codon.
Returns
The int description of the second position of the codon.

Definition at line 205 of file CodonAlphabet.h.

References isUnresolved(), and nAlph_.

Referenced by bpp::CodonSiteTools::numberOfDifferences().

◆ getSize()

unsigned int bpp::CodonAlphabet::getSize ( ) const
inlineoverridevirtual

Implements bpp::CoreWordAlphabet.

Definition at line 98 of file CodonAlphabet.h.

Referenced by charToInt().

◆ getState() [1/4]

AlphabetState & AbstractAlphabet::getState ( const std::string &  letter)
inherited

Definition at line 101 of file AbstractAlphabet.cpp.

◆ getState() [2/4]

const AlphabetState & AbstractAlphabet::getState ( const std::string &  letter) const
virtualinherited

Get a state by its letter.

This method must be overloaded in specialized classes to send back a reference of the correct type.

Parameters
letterThe letter of the state to find.
Exceptions
BadCharExceptionIf the letter is not in the Alphabet.

Implements bpp::Alphabet.

Reimplemented in bpp::ProteicAlphabet, and bpp::NucleicAlphabet.

Definition at line 61 of file AbstractAlphabet.cpp.

Referenced by bpp::AllelicAlphabet::getAlias(), bpp::NucleicAlphabet::getState(), bpp::ProteicAlphabet::getState(), bpp::RNY::intToChar(), and bpp::NumericAlphabet::intToValue().

◆ getState() [3/4]

AlphabetState & AbstractAlphabet::getState ( int  num)
inherited

Definition at line 111 of file AbstractAlphabet.cpp.

◆ getState() [4/4]

const AlphabetState & AbstractAlphabet::getState ( int  num) const
virtualinherited

Get a state by its num.

This method must be overloaded in specialized classes to send back a reference of the correct type.

Parameters
numThe num of the state to find.
Exceptions
BadIntExceptionIf the num is not in the Alphabet.

Implements bpp::Alphabet.

Reimplemented in bpp::ProteicAlphabet, and bpp::NucleicAlphabet.

Definition at line 81 of file AbstractAlphabet.cpp.

◆ getStateAt() [1/2]

AlphabetState & AbstractAlphabet::getStateAt ( size_t  stateIndex)
virtualinherited

Get a state at a position in the alphabet_ vector.

This method must be overloaded in specialized classes to send back a reference of the correct type.

Parameters
stateIndexThe index of the state in the alphabet_ vector.
Exceptions
IndexOutOfBoundsExceptionIf the index is invalid.

Reimplemented in bpp::NumericAlphabet, bpp::NucleicAlphabet, and bpp::ProteicAlphabet.

Definition at line 121 of file AbstractAlphabet.cpp.

Referenced by bpp::LexicalAlphabet::getAlphabetType(), bpp::AbstractAlphabet::getCharCodeAt(), bpp::AbstractAlphabet::getIntCodeAt(), bpp::WordAlphabet::getName(), bpp::ProteicAlphabet::getStateAt(), bpp::NumericAlphabet::getStateAt(), and bpp::NucleicAlphabet::getStateAt().

◆ getStateAt() [2/2]

const AlphabetState & AbstractAlphabet::getStateAt ( size_t  stateIndex) const
virtualinherited

Get a state at a position in the alphabet_ vector.

This method must be overloaded in specialized classes to send back a reference of the correct type.

Parameters
stateIndexThe index of the state in the alphabet_ vector.
Exceptions
IndexOutOfBoundsExceptionIf the index is invalid.

Implements bpp::Alphabet.

Reimplemented in bpp::NumericAlphabet, bpp::NucleicAlphabet, and bpp::ProteicAlphabet.

Definition at line 130 of file AbstractAlphabet.cpp.

◆ getStateCodingSize()

unsigned int bpp::CodonAlphabet::getStateCodingSize ( ) const
inlineoverridevirtual

Get the size of the string coding a state.

Returns
The size of the string coding each states in the Alphabet.
Author
Sylvain Gaillard

Reimplemented from bpp::AbstractAlphabet.

Definition at line 410 of file CodonAlphabet.h.

◆ getStateIndex() [1/2]

size_t AbstractAlphabet::getStateIndex ( const std::string &  state) const
virtualinherited
Returns
The index of the state with corresponding char code.

Implements bpp::Alphabet.

Definition at line 71 of file AbstractAlphabet.cpp.

◆ getStateIndex() [2/2]

size_t AbstractAlphabet::getStateIndex ( int  state) const
virtualinherited
Returns
The indices of the states with corresponding int code.

Implements bpp::Alphabet.

Definition at line 91 of file AbstractAlphabet.cpp.

◆ getSupportedChars()

const std::vector< std::string > & AbstractAlphabet::getSupportedChars ( ) const
virtualinherited
Returns
A list of all supported character codes.

Note for developers of new alphabets: we return a const reference here since the list is supposed to be stored within the class and should not be modified outside the class.

Implements bpp::Alphabet.

Definition at line 310 of file AbstractAlphabet.cpp.

Referenced by bpp::AllelicAlphabet::getAlias().

◆ getSupportedInts()

const std::vector< int > & AbstractAlphabet::getSupportedInts ( ) const
virtualinherited
Returns
A list of all supported int codes.

Note for developers of new alphabets: we return a const reference here since the list is supposed to be stored within the class and should not be modified outside the class.

Implements bpp::Alphabet.

Definition at line 293 of file AbstractAlphabet.cpp.

Referenced by bpp::AllelicAlphabet::getAlias().

◆ getThirdPosition() [1/2]

std::string bpp::CodonAlphabet::getThirdPosition ( const std::string &  codon) const
inline

Get the char code of the third position of a codon given its char description.

Parameters
codonThe char description of the codon.
Returns
The char description of the third position of the codon.

Definition at line 252 of file CodonAlphabet.h.

◆ getThirdPosition() [2/2]

int bpp::CodonAlphabet::getThirdPosition ( int  codon) const
inline

Get the int code of the third position of a codon given its int description.

Parameters
codonThe int description of the codon.
Returns
The int description of the third position of the codon.

Definition at line 217 of file CodonAlphabet.h.

References isUnresolved(), and nAlph_.

Referenced by bpp::CodonSiteTools::numberOfDifferences().

◆ getUnknownCharacterCode()

int bpp::CodonAlphabet::getUnknownCharacterCode ( ) const
inlineoverridevirtual
Returns
The int code for unknown characters.

Implements bpp::Alphabet.

Definition at line 103 of file CodonAlphabet.h.

Referenced by getCodon().

◆ getWord() [1/3]

int bpp::CodonAlphabet::getWord ( const Sequence seq,
size_t  pos = 0 
) const
inlineoverridevirtual

Implements bpp::CoreWordAlphabet.

Definition at line 278 of file CodonAlphabet.h.

References getCodon(), and bpp::AbstractTemplateSymbolList< T >::size().

◆ getWord() [2/3]

int bpp::CodonAlphabet::getWord ( const std::vector< int > &  vint,
size_t  pos = 0 
) const
inlineoverridevirtual

Get the int code for a word given the int code of the underlying positions.

The int code of each position must match the corresponding alphabet specified at this position.

Parameters
vintdescription for all the positions.
posthe start position to match in the vector.
Returns
The int code of the word.
Exceptions
IndexOutOfBoundsExceptionIn case of wrong position.

Implements bpp::CoreWordAlphabet.

Definition at line 303 of file CodonAlphabet.h.

References getCodon().

◆ getWord() [3/3]

std::string bpp::CodonAlphabet::getWord ( const std::vector< std::string > &  vpos,
size_t  pos = 0 
) const
inlineoverridevirtual

Get the char code for a word given the char code of the underlying positions.

The char code of each position must match the corresponding alphabet specified at this position.

Parameters
vposvector description for all the positions.
posthe start position to match in the vector.
Returns
The string of the word.
Exceptions
IndexOutOfBoundsExceptionIn case of wrong position.

Implements bpp::CoreWordAlphabet.

Definition at line 295 of file CodonAlphabet.h.

References getCodon().

◆ hasUniqueAlphabet()

bool bpp::CodonAlphabet::hasUniqueAlphabet ( ) const
inlineoverridevirtual

Implements bpp::CoreWordAlphabet.

Definition at line 268 of file CodonAlphabet.h.

◆ intToChar()

std::string AbstractAlphabet::intToChar ( int  state) const
virtualinherited

Give the string description of a state given its int description.

Parameters
stateThe int description.
Returns
The string description.
Exceptions
BadIntExceptionWhen state is not a valid integer.

Implements bpp::Alphabet.

Reimplemented in bpp::RNY.

Definition at line 160 of file AbstractAlphabet.cpp.

Referenced by bpp::RNY::getAlias(), bpp::WordAlphabet::getAlias(), bpp::CaseMaskedAlphabet::getMaskedEquivalentState(), bpp::WordAlphabet::getNPosition(), bpp::NucleicAlphabet::getOverlap(), bpp::WordAlphabet::getPositions(), bpp::WordAlphabet::getWord(), bpp::BinaryAlphabet::isResolvedIn(), and bpp::NucleicAlphabet::subtract().

◆ isCharInAlphabet()

bool AbstractAlphabet::isCharInAlphabet ( const std::string &  state) const
virtualinherited

Tell if a state (specified by its string description) is allowed by the the alphabet.

Parameters
stateThe string description.
Returns
'true' if the state in known.

Implements bpp::Alphabet.

Reimplemented in bpp::LetterAlphabet.

Definition at line 177 of file AbstractAlphabet.cpp.

Referenced by bpp::BinaryAlphabet::getAlias(), bpp::RNY::getAlias(), bpp::AllelicAlphabet::getAlias(), and bpp::WordAlphabet::getAlias().

◆ isGap() [1/2]

bool bpp::AbstractAlphabet::isGap ( const std::string &  state) const
inlinevirtualinherited
Parameters
stateThe state to test.
Returns
'True' if the state is a gap.

Implements bpp::Alphabet.

Definition at line 132 of file AbstractAlphabet.h.

References bpp::AbstractAlphabet::charToInt().

◆ isGap() [2/2]

bool bpp::AbstractAlphabet::isGap ( int  state) const
inlinevirtualinherited
Parameters
stateThe state to test.
Returns
'True' if the state is a gap.

Implements bpp::Alphabet.

Reimplemented in bpp::RNY, and bpp::NumericAlphabet.

Definition at line 131 of file AbstractAlphabet.h.

Referenced by bpp::WordAlphabet::containsGap().

◆ isIntInAlphabet()

bool AbstractAlphabet::isIntInAlphabet ( int  state) const
virtualinherited

Tell if a state (specified by its int description) is allowed by the the alphabet.

Parameters
stateThe int description.
Returns
'true' if the state in known.

Implements bpp::Alphabet.

Definition at line 167 of file AbstractAlphabet.cpp.

Referenced by bpp::BinaryAlphabet::getAlias(), bpp::RNY::getAlias(), bpp::AllelicAlphabet::getAlias(), bpp::WordAlphabet::getAlias(), bpp::CaseMaskedAlphabet::getMaskedEquivalentState(), bpp::BinaryAlphabet::isResolvedIn(), bpp::RNY::isResolvedIn(), bpp::AllelicAlphabet::isResolvedIn(), and bpp::WordAlphabet::isResolvedIn().

◆ isResolvedIn()

bool CodonAlphabet::isResolvedIn ( int  state1,
int  state2 
) const
overridevirtual

Tells if a given (potentially unresolved) state can be resolved in another resolved state.

Parameters
state1The alias to resolve.
state2The candidate for resolution.
Returns
A boolean
Exceptions
BadIntExceptionWhen state is not a valid integer.

Reimplemented from bpp::AbstractAlphabet.

Definition at line 178 of file CodonAlphabet.cpp.

◆ isUnresolved() [1/2]

bool bpp::CodonAlphabet::isUnresolved ( const std::string &  state) const
inlineoverridevirtual
Parameters
stateThe state to test.
Returns
'True' if the state is unresolved.

Implements bpp::Alphabet.

Definition at line 113 of file CodonAlphabet.h.

References charToInt(), and isUnresolved().

◆ isUnresolved() [2/2]

bool bpp::CodonAlphabet::isUnresolved ( int  state) const
inlineoverridevirtual
Parameters
stateThe state to test.
Returns
'True' if the state is unresolved.

Implements bpp::Alphabet.

Definition at line 108 of file CodonAlphabet.h.

Referenced by getFirstPosition(), getNPosition(), getPositions(), getSecondPosition(), getThirdPosition(), and isUnresolved().

◆ operator=()

CodonAlphabet& bpp::CodonAlphabet::operator= ( const CodonAlphabet bia)
inline

Definition at line 55 of file CodonAlphabet.h.

References nAlph_, and bpp::AbstractAlphabet::operator=().

◆ registerState()

void AbstractAlphabet::registerState ( AlphabetState st)
protectedvirtualinherited

◆ remap()

void bpp::AbstractAlphabet::remap ( )
inlineprotectedinherited

Re-update the maps using the alphabet_ vector content.

Definition at line 231 of file AbstractAlphabet.h.

References bpp::AbstractAlphabet::alphabet_, bpp::AbstractAlphabet::letters_, bpp::AbstractAlphabet::nums_, and bpp::AbstractAlphabet::updateMaps_().

Referenced by bpp::NumericAlphabet::remap().

◆ resize()

void bpp::AbstractAlphabet::resize ( size_t  size)
inlineprotectedinherited

Resize the private alphabet_ vector.

Parameters
sizeThe new size of the Alphabet.

Definition at line 226 of file AbstractAlphabet.h.

References bpp::AbstractAlphabet::alphabet_.

◆ reverse()

unique_ptr< SequenceInterface > CodonAlphabet::reverse ( const SequenceInterface sequence) const
overridevirtual

Translate a whole sequence from words alphabet to letters alphabet.

Parameters
sequenceA sequence in words alphabet.
Returns
The corresponding sequence in letters alphabet.
Exceptions
AlphabetMismatchExceptionIf the sequence alphabet do not match the target alphabet.
ExceptionOther kind of error, depending on the implementation.

Implements bpp::CoreWordAlphabet.

Definition at line 116 of file CodonAlphabet.cpp.

References bpp::CoreSequenceInterface::getName(), and bpp::CruxSymbolListInterface::size().

◆ setState()

void AbstractAlphabet::setState ( size_t  pos,
AlphabetState st 
)
protectedvirtualinherited

Set a state in the Alphabet.

Parameters
posThe index of the state in the alphabet_ vector.
stThe new state to put in the Alphabet.
Exceptions
ExceptionIf a wrong alphabet state is provided.
IndexOutOfBoundsExceptionIf an incorrect index is provided.

Reimplemented in bpp::NumericAlphabet, bpp::NucleicAlphabet, and bpp::LetterAlphabet.

Definition at line 46 of file AbstractAlphabet.cpp.

Referenced by bpp::LetterAlphabet::setState(), and bpp::NumericAlphabet::setState().

◆ translate()

unique_ptr< SequenceInterface > CodonAlphabet::translate ( const SequenceInterface sequence,
size_t  pos = 0 
) const
overridevirtual

Translate a whole sequence from letters alphabet to words alphabet.

Parameters
sequenceA sequence in letters alphabet.
posthe start position (default 0)
Returns
The corresponding sequence in words alphabet.
Exceptions
AlphabetMismatchExceptionIf the sequence alphabet do not match the source alphabet.
ExceptionOther kind of error, depending on the implementation.

Implements bpp::CoreWordAlphabet.

Definition at line 97 of file CodonAlphabet.cpp.

References bpp::CoreSequenceInterface::getName(), and bpp::CruxSymbolListInterface::size().

◆ updateMaps_()

void AbstractAlphabet::updateMaps_ ( size_t  pos,
const AlphabetState st 
)
privateinherited

Update the private maps letters_ and nums_ when adding a state.

Parameters
posThe index of the state in the alphabet_ vector.
stThe state that has been added or modified

Definition at line 22 of file AbstractAlphabet.cpp.

References bpp::AlphabetState::getLetter(), and bpp::AlphabetState::getNum().

Referenced by bpp::AbstractAlphabet::remap().

Member Data Documentation

◆ alphabet_

◆ charList_

std::vector<std::string> bpp::AbstractAlphabet::charList_
mutableprotectedinherited

Definition at line 63 of file AbstractAlphabet.h.

Referenced by bpp::AbstractAlphabet::operator=().

◆ intList_

std::vector<int> bpp::AbstractAlphabet::intList_
mutableprotectedinherited

Definition at line 64 of file AbstractAlphabet.h.

Referenced by bpp::AbstractAlphabet::operator=().

◆ letters_

std::map<std::string, size_t> bpp::AbstractAlphabet::letters_
privateinherited

◆ nAlph_

std::shared_ptr<const NucleicAlphabet> bpp::CodonAlphabet::nAlph_
protected

◆ nums_

std::map<int, size_t> bpp::AbstractAlphabet::nums_
privateinherited

The documentation for this class was generated from the following files: