bpp-seq  2.1.0
bpp::Alphabet Class Reference

The Alphabet interface. More...

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

+ Inheritance diagram for bpp::Alphabet:

List of all members.

Public Member Functions

 Alphabet ()
virtual ~Alphabet ()
virtual std::string getName (int state) const =0 throw (BadIntException)
 Get the complete name of a state given its int description.
virtual std::string getName (const std::string &state) const =0 throw (BadCharException)
 Get the complete name of a state given its string description.
virtual std::string getAlphabetType () const =0
 Identification method.
virtual unsigned int getStateCodingSize () const =0
 Get the size of the string coding a state.
= Tests
virtual bool isIntInAlphabet (int state) const =0
 Tell if a state (specified by its int description) is allowed by the the alphabet.
virtual bool isCharInAlphabet (const std::string &state) const =0
 Tell if a state (specified by its string description) is allowed by the the alphabet.
State access
virtual const AlphabetStategetState (int state) const =0 throw (BadIntException)
 Get a state given its int description.
virtual const AlphabetStategetState (const std::string &state) const =0 throw (BadCharException)
 Get a state given its string description.
Conversion methods
virtual std::string intToChar (int state) const =0 throw (BadIntException)
 Give the string description of a state given its int description.
virtual int charToInt (const std::string &state) const =0 throw (BadCharException)
 Give the int description of a state given its string description.
Sizes.
virtual unsigned int getNumberOfChars () const =0
 Get the number of supported characters in this alphabet, including generic characters (e.g. return 20 for DNA alphabet).
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.
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.
Utilitary methods
virtual std::vector< int > getAlias (int state) const =0 throw (BadIntException)
 Get all resolved states that match a generic state.
virtual std::vector< std::string > getAlias (const std::string &state) const =0 throw (BadCharException)
 Get all resolved states that match a generic state.
virtual int getGeneric (const std::vector< int > &states) const =0 throw (BadIntException)
 Get the generic state that match a set of states.
virtual std::string getGeneric (const std::vector< std::string > &states) const =0 throw (AlphabetException)
 Get the generic state that match a set of states.
virtual const std::vector< int > & getSupportedInts () const =0
virtual const std::vector
< std::string > & 
getSupportedChars () const =0
virtual int getUnknownCharacterCode () const =0
virtual int getGapCharacterCode () const =0
virtual bool isGap (int state) const =0
virtual bool isGap (const std::string &state) const =0
virtual bool isUnresolved (int state) const =0
virtual bool isUnresolved (const std::string &state) const =0

Detailed Description

The Alphabet interface.

An alphabet object defines all the states allowed for a particular type of sequence. These states are coded as a string and an integer. The string description is the one found in the text (human comprehensive) description of sequences, typically in sequence files. However, for computionnal needs, this is often more efficient to store the sequences as a vector of integers. The link between the two descriptions is made via the Alphabet classes, and the two methods intToChar() and charToInt(). The Alphabet interface also provides other methods, like getting the full name of the states and so on.

The alphabet objects may throw several exceptions derived of the AlphabetException class.

See also:
AlphabetException, BadCharException, BadIntException

Definition at line 121 of file Alphabet.h.


Constructor & Destructor Documentation

Definition at line 124 of file Alphabet.h.

virtual bpp::Alphabet::~Alphabet ( ) [inline, virtual]

Definition at line 125 of file Alphabet.h.


Member Function Documentation

virtual int bpp::Alphabet::charToInt ( const std::string &  state) const throw (BadCharException) [pure virtual]

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.

Implemented in bpp::AbstractAlphabet, bpp::WordAlphabet, bpp::LetterAlphabet, and bpp::RNY.

Referenced by bpp::UserAlphabetIndex1::getIndex(), and bpp::UserAlphabetIndex1::setIndex().

virtual std::vector<int> bpp::Alphabet::getAlias ( int  state) const throw (BadIntException) [pure virtual]

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.

Implemented in bpp::WordAlphabet, bpp::AbstractAlphabet, bpp::ProteicAlphabet, bpp::RNY, bpp::DNA, and bpp::RNA.

Referenced by bpp::SymbolListTools::getCounts(), bpp::SequenceTools::getPutativeHaplotypes(), bpp::AlphabetTools::match(), and bpp::SequenceTools::subtractHaplotype().

virtual std::vector<std::string> bpp::Alphabet::getAlias ( const std::string &  state) const throw (BadCharException) [pure virtual]

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.

Implemented in bpp::WordAlphabet, bpp::AbstractAlphabet, bpp::ProteicAlphabet, bpp::RNY, bpp::DNA, and bpp::RNA.

virtual std::string bpp::Alphabet::getAlphabetType ( ) const [pure virtual]

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(), and bpp::SequenceTools::invertComplement().

virtual int bpp::Alphabet::getGeneric ( const std::vector< int > &  states) const throw (BadIntException) [pure virtual]

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.

Implemented in bpp::WordAlphabet, bpp::AbstractAlphabet, bpp::ProteicAlphabet, bpp::DNA, and bpp::RNA.

Referenced by bpp::SequenceTools::combineSequences(), bpp::PhredPoly::nextSequence(), and bpp::SequenceTools::subtractHaplotype().

virtual std::string bpp::Alphabet::getGeneric ( const std::vector< std::string > &  states) const throw (AlphabetException) [pure virtual]

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.

Implemented in bpp::WordAlphabet, bpp::AbstractAlphabet, bpp::ProteicAlphabet, bpp::DNA, and bpp::RNA.

virtual std::string bpp::Alphabet::getName ( int  state) const throw (BadIntException) [pure virtual]

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.

Implemented in bpp::AbstractAlphabet.

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

virtual std::string bpp::Alphabet::getName ( const std::string &  state) const throw (BadCharException) [pure virtual]

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.

Implemented in bpp::AbstractAlphabet, and bpp::WordAlphabet.

virtual unsigned int bpp::Alphabet::getNumberOfChars ( ) const [pure virtual]

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.

Implemented in bpp::AbstractAlphabet.

virtual unsigned int bpp::Alphabet::getNumberOfTypes ( ) const [pure virtual]

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 virtual]
virtual const AlphabetState& bpp::Alphabet::getState ( int  state) const throw (BadIntException) [pure virtual]

Get a state given its int description.

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

Implemented in bpp::AbstractAlphabet, bpp::NucleicAlphabet, and bpp::ProteicAlphabet.

virtual const AlphabetState& bpp::Alphabet::getState ( const std::string &  state) const throw (BadCharException) [pure virtual]

Get a state given its string description.

Parameters:
stateThe string description.
Returns:
The AlphabetState.
Exceptions:
BadCharExceptionWhen state is not a valid string.

Implemented in bpp::AbstractAlphabet, bpp::NucleicAlphabet, and bpp::ProteicAlphabet.

virtual unsigned int bpp::Alphabet::getStateCodingSize ( ) const [pure virtual]

Get the size of the string coding a state.

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

Implemented in bpp::WordAlphabet, and bpp::AbstractAlphabet.

Referenced by bpp::SequenceWithQuality::append(), bpp::MaseTools::getSelectedSites(), bpp::Phylip::writeInterleaved(), and bpp::Phylip::writeSequential().

virtual const std::vector<std::string>& bpp::Alphabet::getSupportedChars ( ) const [pure virtual]
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.

Implemented in bpp::AbstractAlphabet.

virtual const std::vector<int>& bpp::Alphabet::getSupportedInts ( ) const [pure virtual]
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.

Implemented in bpp::AbstractAlphabet.

virtual std::string bpp::Alphabet::intToChar ( int  state) const throw (BadIntException) [pure virtual]

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.

Implemented in bpp::AbstractAlphabet, and bpp::RNY.

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

virtual bool bpp::Alphabet::isCharInAlphabet ( const std::string &  state) const [pure virtual]

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.

Implemented in bpp::AbstractAlphabet, and bpp::LetterAlphabet.

virtual bool bpp::Alphabet::isGap ( const std::string &  state) const [pure virtual]
Parameters:
stateThe state to test.
Returns:
'True' if the state is a gap.

Implemented in bpp::AbstractAlphabet.

virtual bool bpp::Alphabet::isIntInAlphabet ( int  state) const [pure virtual]

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.

Implemented in bpp::AbstractAlphabet.

virtual bool bpp::Alphabet::isUnresolved ( const std::string &  state) const [pure virtual]
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.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Friends