bpp-seq  2.1.0
 All Classes Namespaces Files Functions Variables Friends Pages
bpp::LetterAlphabet Class Referenceabstract

Specialized partial implementation of Alphabet using single letters. More...

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

+ Inheritance diagram for bpp::LetterAlphabet:
+ Collaboration diagram for bpp::LetterAlphabet:

Public Member Functions

 LetterAlphabet (bool caseSensitive=false)
 
virtual ~LetterAlphabet ()
 
bool isCharInAlphabet (char state) const
 
bool isCharInAlphabet (const std::string &state) const
 Tell if a state (specified by its string description) is allowed by the the alphabet. More...
 
int charToInt (const std::string &state) const throw (BadCharException)
 Give the int description of a state given its string description. More...
 
virtual std::string getAlphabetType () const =0
 Identification method. More...
 
Implement these methods from the Alphabet interface.
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 throw (BadCharException)
 Get the complete name of a state given its string description. More...
 
std::string getName (int state) const throw (BadIntException)
 Get the complete name of a state given its int description. More...
 
std::string intToChar (int state) const throw (BadIntException)
 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...
 
std::vector< int > getAlias (int state) const throw (BadIntException)
 Get all resolved states that match a generic state. More...
 
std::vector< std::string > getAlias (const std::string &state) const throw (BadCharException)
 Get all resolved states that match a generic state. More...
 
int getGeneric (const std::vector< int > &states) const throw (BadIntException)
 Get the generic state that match a set of states. More...
 
std::string getGeneric (const std::vector< std::string > &states) const throw (AlphabetException)
 Get the generic state that match a set of states. More...
 
const std::vector< int > & getSupportedInts () const
 
const std::vector< std::string > & getSupportedChars () const
 
int getGapCharacterCode () const
 
bool isGap (int state) const
 
bool isGap (const std::string &state) const
 
Specific methods to access AlphabetState
const AlphabetStategetState (const std::string &letter) const throw (BadCharException)
 Get a state by its letter. More...
 
const AlphabetStategetState (int num) const throw (BadIntException)
 Get a state by its num. More...
 
Sizes.
virtual unsigned int getNumberOfTypes () const =0
 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...
 
virtual unsigned int getSize () const =0
 Get the number of resolved states in the alphabet (e.g. return 4 for DNA alphabet). This is the method you'll need in most cases. More...
 
Utilitary methods
virtual int getUnknownCharacterCode () const =0
 
virtual bool isUnresolved (int state) const =0
 
virtual bool isUnresolved (const std::string &state) const =0
 

Protected Member Functions

void registerState (const AlphabetState &st)
 Add a state to the Alphabet. More...
 
void setState (size_t pos, const AlphabetState &st) throw (IndexOutOfBoundsException)
 Set a state in the Alphabet. More...
 
void resize (unsigned int size)
 Resize the private alphabet_ vector. More...
 
virtual AlphabetStategetStateAt (size_t pos) throw (IndexOutOfBoundsException)
 Get a state at a position in the alphabet_ vector. More...
 
virtual const AlphabetStategetStateAt (size_t pos) const throw (IndexOutOfBoundsException)
 Get a state at a position in the alphabet_ vector. More...
 
void remap ()
 Re-update the maps using the alphabet_ vector content. More...
 
unsigned int getStateCodingSize () const
 Get the size of the string coding a state. More...
 

Protected Attributes

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 Attributes

std::vector< int > letters_
 
bool caseSensitive_
 

Static Private Attributes

static const int LETTER_UNDEF_VALUE = -99
 

Detailed Description

Specialized partial implementation of Alphabet using single letters.

Author
Sylvain Gaillard

Definition at line 57 of file LetterAlphabet.h.

Constructor & Destructor Documentation

bpp::LetterAlphabet::LetterAlphabet ( bool  caseSensitive = false)
inline

Definition at line 66 of file LetterAlphabet.h.

virtual bpp::LetterAlphabet::~LetterAlphabet ( )
inlinevirtual

Definition at line 67 of file LetterAlphabet.h.

Member Function Documentation

std::vector< int > AbstractAlphabet::getAlias ( int  state) const throw (BadIntException)
virtualinherited

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.

Implements bpp::Alphabet.

Reimplemented in bpp::WordAlphabet, bpp::ProteicAlphabet, bpp::RNY, bpp::DNA, and bpp::RNA.

Definition at line 171 of file AbstractAlphabet.cpp.

std::vector< std::string > AbstractAlphabet::getAlias ( const std::string &  state) const throw (BadCharException)
virtualinherited

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.

Implements bpp::Alphabet.

Reimplemented in bpp::WordAlphabet, bpp::ProteicAlphabet, bpp::RNY, bpp::DNA, and bpp::RNA.

Definition at line 181 of file AbstractAlphabet.cpp.

virtual std::string bpp::Alphabet::getAlphabetType ( ) const
pure virtualinherited

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.

Implemented in bpp::WordAlphabet, bpp::ProteicAlphabet, bpp::CodonAlphabet, bpp::RNY, bpp::CaseMaskedAlphabet, bpp::DNA, bpp::RNA, bpp::DefaultAlphabet, bpp::BinaryAlphabet, bpp::InvertebrateMitochondrialCodonAlphabet, bpp::YeastMitochondrialCodonAlphabet, bpp::EchinodermMitochondrialCodonAlphabet, bpp::VertebrateMitochondrialCodonAlphabet, and bpp::StandardCodonAlphabet.

Referenced by bpp::SiteTools::areSitesIdentical(), bpp::SiteTools::areSitesIdentical(), bpp::SequenceTools::invertComplement(), and bpp::SequenceTools::invertComplement().

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

Implements bpp::Alphabet.

Definition at line 132 of file AbstractAlphabet.h.

Referenced by bpp::SequenceTools::replaceStopsWithGaps().

int AbstractAlphabet::getGeneric ( const std::vector< int > &  states) const throw (BadIntException)
virtualinherited

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.

Implements bpp::Alphabet.

Reimplemented in bpp::WordAlphabet, bpp::ProteicAlphabet, bpp::DNA, and bpp::RNA.

Definition at line 191 of file AbstractAlphabet.cpp.

References bpp::MapTools::getKeys(), and bpp::TextTools::toString().

std::string AbstractAlphabet::getGeneric ( const std::vector< std::string > &  states) const throw (AlphabetException)
virtualinherited

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.

Implements bpp::Alphabet.

Reimplemented in bpp::WordAlphabet, bpp::ProteicAlphabet, bpp::DNA, and bpp::RNA.

Definition at line 217 of file AbstractAlphabet.cpp.

References bpp::MapTools::getKeys(), and bpp::TextTools::toString().

std::string AbstractAlphabet::getName ( const std::string &  state) const throw (BadCharException)
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 123 of file AbstractAlphabet.cpp.

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

std::string AbstractAlphabet::getName ( int  state) const throw (BadIntException)
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 130 of file AbstractAlphabet.cpp.

virtual unsigned int bpp::Alphabet::getNumberOfTypes ( ) const
pure virtualinherited

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.

Implemented in bpp::NucleicAlphabet, bpp::WordAlphabet, bpp::ProteicAlphabet, bpp::RNY, bpp::CaseMaskedAlphabet, bpp::DefaultAlphabet, and bpp::BinaryAlphabet.

Referenced by bpp::CaseMaskedAlphabet::getNumberOfTypes().

virtual unsigned int bpp::Alphabet::getSize ( ) const
pure virtualinherited
const AlphabetState & AbstractAlphabet::getState ( const std::string &  letter) const throw (BadCharException)
virtualinherited

Get a state by its letter.

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

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

Implements bpp::Alphabet.

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

Definition at line 89 of file AbstractAlphabet.cpp.

Referenced by bpp::CaseMaskedAlphabet::CaseMaskedAlphabet(), bpp::ProteicAlphabet::getState(), bpp::ProteicAlphabet::getState(), bpp::NucleicAlphabet::getState(), and bpp::NucleicAlphabet::getState().

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

Get a state by its num.

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

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

Implements bpp::Alphabet.

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

Definition at line 98 of file AbstractAlphabet.cpp.

const AlphabetState & AbstractAlphabet::getStateAt ( size_t  pos) const throw (IndexOutOfBoundsException)
protectedvirtualinherited

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 corect type.

Parameters
posThe index of the state in the alphabet_ vector.
Exceptions
IndexOutOfBoundsExceptionIf pos is out of the vector.

Definition at line 115 of file AbstractAlphabet.cpp.

unsigned int bpp::AbstractAlphabet::getStateCodingSize ( ) const
inlineprotectedvirtualinherited

Get the size of the string coding a state.

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

Implements bpp::Alphabet.

Reimplemented in bpp::WordAlphabet.

Definition at line 213 of file AbstractAlphabet.h.

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 260 of file AbstractAlphabet.cpp.

Referenced by bpp::CaseMaskedAlphabet::CaseMaskedAlphabet().

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 243 of file AbstractAlphabet.cpp.

std::string AbstractAlphabet::intToChar ( int  state) const throw (BadIntException)
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 144 of file AbstractAlphabet.cpp.

Referenced by bpp::EchinodermMitochondrialCodonAlphabet::EchinodermMitochondrialCodonAlphabet(), bpp::EchinodermMitochondrialCodonAlphabet::EchinodermMitochondrialCodonAlphabet(), bpp::EchinodermMitochondrialCodonAlphabet::EchinodermMitochondrialCodonAlphabet(), bpp::RNY::getAlias(), bpp::GeneticCode::getCodingSequence(), bpp::GeneticCode::getCodingSequence(), bpp::GeneticCode::getCodingSequence(), bpp::WordAlphabet::getNPosition(), bpp::NucleicAlphabet::getOverlap(), bpp::WordAlphabet::getPositions(), bpp::InvertebrateMitochondrialCodonAlphabet::InvertebrateMitochondrialCodonAlphabet(), bpp::InvertebrateMitochondrialCodonAlphabet::InvertebrateMitochondrialCodonAlphabet(), bpp::InvertebrateMitochondrialCodonAlphabet::InvertebrateMitochondrialCodonAlphabet(), bpp::CodonAlphabet::isStop(), bpp::StandardCodonAlphabet::StandardCodonAlphabet(), bpp::StandardCodonAlphabet::StandardCodonAlphabet(), bpp::StandardCodonAlphabet::StandardCodonAlphabet(), bpp::NucleicAlphabet::subtract(), bpp::VertebrateMitochondrialCodonAlphabet::VertebrateMitochondrialCodonAlphabet(), bpp::VertebrateMitochondrialCodonAlphabet::VertebrateMitochondrialCodonAlphabet(), bpp::VertebrateMitochondrialCodonAlphabet::VertebrateMitochondrialCodonAlphabet(), bpp::YeastMitochondrialCodonAlphabet::YeastMitochondrialCodonAlphabet(), bpp::YeastMitochondrialCodonAlphabet::YeastMitochondrialCodonAlphabet(), and bpp::YeastMitochondrialCodonAlphabet::YeastMitochondrialCodonAlphabet().

bool bpp::LetterAlphabet::isCharInAlphabet ( char  state) const
inline

Definition at line 70 of file LetterAlphabet.h.

References LETTER_UNDEF_VALUE, and letters_.

Referenced by charToInt(), and isCharInAlphabet().

bool bpp::LetterAlphabet::isCharInAlphabet ( const std::string &  state) const
inlinevirtual

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.

Reimplemented from bpp::AbstractAlphabet.

Definition at line 73 of file LetterAlphabet.h.

References isCharInAlphabet().

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.

Definition at line 133 of file AbstractAlphabet.h.

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 134 of file AbstractAlphabet.h.

References bpp::AbstractAlphabet::charToInt().

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 151 of file AbstractAlphabet.cpp.

virtual bool bpp::Alphabet::isUnresolved ( const std::string &  state) const
pure virtualinherited
Parameters
stateThe state to test.
Returns
'True' if the state is unresolved.

Implemented in bpp::NucleicAlphabet, bpp::WordAlphabet, bpp::ProteicAlphabet, bpp::RNY, bpp::CaseMaskedAlphabet, bpp::DefaultAlphabet, and bpp::BinaryAlphabet.

void bpp::AbstractAlphabet::remap ( )
inlineprotectedinherited

Re-update the maps using the alphabet_ vector content.

Definition at line 207 of file AbstractAlphabet.h.

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

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

void bpp::AbstractAlphabet::resize ( unsigned int  size)
inlineprotectedinherited

Resize the private alphabet_ vector.

Parameters
sizeThe new size of the Alphabet.

Definition at line 182 of file AbstractAlphabet.h.

References bpp::AbstractAlphabet::alphabet_.

Referenced by bpp::BinaryAlphabet::BinaryAlphabet(), bpp::WordAlphabet::build_(), bpp::DefaultAlphabet::DefaultAlphabet(), and bpp::RNY::RNY().

void bpp::LetterAlphabet::setState ( size_t  pos,
const AlphabetState st 
) throw (IndexOutOfBoundsException)
inlineprotectedvirtual

Set a state in the Alphabet.

Parameters
posThe index of the state in the alphabet_ vector.
stThe new state to put in the Alphabet.

Reimplemented from bpp::AbstractAlphabet.

Definition at line 93 of file LetterAlphabet.h.

References caseSensitive_, letters_, letters_, letters_, and bpp::AbstractAlphabet::setState().

Referenced by bpp::DefaultAlphabet::DefaultAlphabet(), bpp::DefaultAlphabet::DefaultAlphabet(), and bpp::NucleicAlphabet::setState().

Member Data Documentation

bool bpp::LetterAlphabet::caseSensitive_
private

Definition at line 63 of file LetterAlphabet.h.

Referenced by registerState(), and setState().

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

Definition at line 99 of file AbstractAlphabet.h.

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

Definition at line 100 of file AbstractAlphabet.h.

const int bpp::LetterAlphabet::LETTER_UNDEF_VALUE = -99
staticprivate

Definition at line 61 of file LetterAlphabet.h.

Referenced by isCharInAlphabet().

std::vector<int> bpp::LetterAlphabet::letters_
private

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