|
bpp-seq
2.1.0
|
A partial implementation of the Alphabet interface. More...
#include <Bpp/Seq/Alphabet/AbstractAlphabet.h>
Inheritance diagram for bpp::AbstractAlphabet:
Collaboration diagram for bpp::AbstractAlphabet:Public Member Functions | |
| AbstractAlphabet () | |
| virtual | ~AbstractAlphabet () |
| virtual std::string | getAlphabetType () const =0 |
| Identification method. | |
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). | |
| std::string | getName (const std::string &state) const throw (BadCharException) |
| Get the complete name of a state given its string description. | |
| std::string | getName (int state) const throw (BadIntException) |
| Get the complete name of a state given its int description. | |
| int | charToInt (const std::string &state) const throw (BadCharException) |
| Give the int description of a state given its string description. | |
| std::string | intToChar (int state) const throw (BadIntException) |
| Give the string description of a state given its int description. | |
| bool | isIntInAlphabet (int state) const |
| Tell if a state (specified by its int description) is allowed by the the alphabet. | |
| bool | isCharInAlphabet (const std::string &state) const |
| Tell if a state (specified by its string description) is allowed by the the alphabet. | |
| std::vector< int > | getAlias (int state) const throw (BadIntException) |
| Get all resolved states that match a generic state. | |
| std::vector< std::string > | getAlias (const std::string &state) const throw (BadCharException) |
| Get all resolved states that match a generic state. | |
| int | getGeneric (const std::vector< int > &states) const throw (BadIntException) |
| Get the generic state that match a set of states. | |
| std::string | getGeneric (const std::vector< std::string > &states) const throw (AlphabetException) |
| Get the generic state that match a set of states. | |
| 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 AlphabetState & | getState (const std::string &letter) const throw (BadCharException) |
| Get a state by its letter. | |
| const AlphabetState & | getState (int num) const throw (BadIntException) |
| Get a state by its num. | |
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. | |
| 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 int | getUnknownCharacterCode () const =0 |
| virtual bool | isUnresolved (int state) const =0 |
| virtual bool | isUnresolved (const std::string &state) const =0 |
Protected Member Functions | |
| virtual void | registerState (const AlphabetState &st) |
| Add a state to the Alphabet. | |
| virtual void | setState (size_t pos, const AlphabetState &st) throw (IndexOutOfBoundsException) |
| Set a state in the Alphabet. | |
| void | resize (unsigned int size) |
| Resize the private alphabet_ vector. | |
| virtual AlphabetState & | getStateAt (size_t pos) throw (IndexOutOfBoundsException) |
| Get a state at a position in the alphabet_ vector. | |
| virtual const AlphabetState & | getStateAt (size_t pos) const throw (IndexOutOfBoundsException) |
| Get a state at a position in the alphabet_ vector. | |
| void | remap () |
| Re-update the maps using the alphabet_ vector content. | |
| unsigned int | getStateCodingSize () const |
| Get the size of the string coding a state. | |
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 Member Functions | |
| void | updateMaps_ (size_t pos, const AlphabetState &st) |
| Update the private maps letters_ and nums_ when adding a state. | |
Private Attributes | |
| std::vector< AlphabetState * > | alphabet_ |
| Alphabet: vector of AlphabetState. | |
maps used to quick search for letter and num. | |
| std::map< std::string, size_t > | letters_ |
| std::map< int, size_t > | nums_ |
A partial implementation of the Alphabet interface.
It contains a vector of AlphabetState. All methods are based uppon this vector but do not provide any method to initialize it. This is up to each constructor of the derived classes.
Definition at line 67 of file AbstractAlphabet.h.
| bpp::AbstractAlphabet::AbstractAlphabet | ( | ) | [inline] |
Definition at line 105 of file AbstractAlphabet.h.
| virtual bpp::AbstractAlphabet::~AbstractAlphabet | ( | ) | [inline, virtual] |
Definition at line 107 of file AbstractAlphabet.h.
References alphabet_.
| int AbstractAlphabet::charToInt | ( | const std::string & | state | ) | const throw (BadCharException) [virtual] |
Give the int description of a state given its string description.
| state | The string description. |
| BadCharException | When state is not a valid char description. |
Implements bpp::Alphabet.
Reimplemented in bpp::WordAlphabet, bpp::LetterAlphabet, and bpp::RNY.
Definition at line 137 of file AbstractAlphabet.cpp.
Referenced by bpp::RNY::charToInt(), and isGap().
| std::vector< int > AbstractAlphabet::getAlias | ( | int | state | ) | const throw (BadIntException) [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.
| state | The alias to resolve. |
| BadIntException | When 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) [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.
| state | The alias to resolve. |
| BadCharException | When 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 virtual, inherited] |
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.
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().
| int bpp::AbstractAlphabet::getGapCharacterCode | ( | ) | const [inline, virtual] |
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) [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.
| states | A vector of states to resolve. |
| BadIntException | When 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) [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.
| states | A vector of states to resolve. |
| BadCharException | when a state is not a valid char description. |
| CharStateNotSupportedException | when 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) [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.
| state | The string description of the given state. |
| BadCharException | When 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) [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.
| state | The int description of the given state. |
| BadIntException | When state is not a valid integer. |
Implements bpp::Alphabet.
Definition at line 130 of file AbstractAlphabet.cpp.
| unsigned int bpp::AbstractAlphabet::getNumberOfChars | ( | ) | const [inline, virtual] |
Get the number of supported characters in this alphabet, including generic characters (e.g. return 20 for DNA alphabet).
Implements bpp::Alphabet.
Definition at line 119 of file AbstractAlphabet.h.
References alphabet_.
Referenced by bpp::EchinodermMitochondrialCodonAlphabet::EchinodermMitochondrialCodonAlphabet(), bpp::WordAlphabet::getNumberOfTypes(), bpp::WordAlphabet::getSize(), bpp::InvertebrateMitochondrialCodonAlphabet::InvertebrateMitochondrialCodonAlphabet(), bpp::NucleicAlphabet::registerState(), bpp::StandardCodonAlphabet::StandardCodonAlphabet(), bpp::VertebrateMitochondrialCodonAlphabet::VertebrateMitochondrialCodonAlphabet(), and bpp::YeastMitochondrialCodonAlphabet::YeastMitochondrialCodonAlphabet().
| virtual unsigned int bpp::Alphabet::getNumberOfTypes | ( | ) | const [pure virtual, inherited] |
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.
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, inherited] |
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.
Implemented in bpp::NucleicAlphabet, bpp::WordAlphabet, bpp::ProteicAlphabet, bpp::RNY, bpp::CaseMaskedAlphabet, bpp::DefaultAlphabet, and bpp::BinaryAlphabet.
Referenced by bpp::SequenceTools::bowkerTest(), bpp::SequenceContainerTools::getFrequencies(), bpp::UserAlphabetIndex1::getIndex(), bpp::SequenceApplicationTools::getSitesToAnalyse(), bpp::CaseMaskedAlphabet::getSize(), bpp::UserAlphabetIndex1::setIndex(), and bpp::SimpleScore::SimpleScore().
| const AlphabetState & AbstractAlphabet::getState | ( | const std::string & | letter | ) | const throw (BadCharException) [virtual] |
Get a state by its letter.
This method must be overloaded in specialized classes to send back a reference of the corect type.
| letter | The letter of the state to find. |
| BadCharException | If 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().
| const AlphabetState & AbstractAlphabet::getState | ( | int | num | ) | const throw (BadIntException) [virtual] |
Get a state by its num.
This method must be overloaded in specialized classes to send back a reference of the corect type.
| num | The num of the state to find. |
| BadIntException | If 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.
| AlphabetState & AbstractAlphabet::getStateAt | ( | size_t | pos | ) | throw (IndexOutOfBoundsException) [protected, virtual] |
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.
| pos | The index of the state in the alphabet_ vector. |
| IndexOutOfBoundsException | If pos is out of the vector. |
Definition at line 107 of file AbstractAlphabet.cpp.
Referenced by bpp::WordAlphabet::build_(), bpp::EchinodermMitochondrialCodonAlphabet::EchinodermMitochondrialCodonAlphabet(), bpp::InvertebrateMitochondrialCodonAlphabet::InvertebrateMitochondrialCodonAlphabet(), bpp::StandardCodonAlphabet::StandardCodonAlphabet(), bpp::VertebrateMitochondrialCodonAlphabet::VertebrateMitochondrialCodonAlphabet(), and bpp::YeastMitochondrialCodonAlphabet::YeastMitochondrialCodonAlphabet().
| const AlphabetState & AbstractAlphabet::getStateAt | ( | size_t | pos | ) | const throw (IndexOutOfBoundsException) [protected, virtual] |
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.
| pos | The index of the state in the alphabet_ vector. |
| IndexOutOfBoundsException | If pos is out of the vector. |
Definition at line 115 of file AbstractAlphabet.cpp.
| unsigned int bpp::AbstractAlphabet::getStateCodingSize | ( | ) | const [inline, protected, virtual] |
Get the size of the string coding a state.
Implements bpp::Alphabet.
Reimplemented in bpp::WordAlphabet.
Definition at line 213 of file AbstractAlphabet.h.
| const std::vector< std::string > & AbstractAlphabet::getSupportedChars | ( | ) | const [virtual] |
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 [virtual] |
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.
| virtual int bpp::Alphabet::getUnknownCharacterCode | ( | ) | const [pure virtual, inherited] |
Implemented in bpp::NucleicAlphabet, bpp::WordAlphabet, bpp::ProteicAlphabet, bpp::RNY, bpp::CaseMaskedAlphabet, bpp::DefaultAlphabet, and bpp::BinaryAlphabet.
Referenced by bpp::SymbolListTools::changeGapsToUnknownCharacters(), bpp::SiteContainerTools::changeGapsToUnknownCharacters(), bpp::CaseMaskedAlphabet::getUnknownCharacterCode(), bpp::SiteTools::hasUnknown(), and bpp::SequenceTools::subtractHaplotype().
| std::string AbstractAlphabet::intToChar | ( | int | state | ) | const throw (BadIntException) [virtual] |
Give the string description of a state given its int description.
| state | The int description. |
| BadIntException | When 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::RNY::getAlias(), bpp::GeneticCode::getCodingSequence(), bpp::WordAlphabet::getNPosition(), bpp::NucleicAlphabet::getOverlap(), bpp::WordAlphabet::getPositions(), bpp::InvertebrateMitochondrialCodonAlphabet::InvertebrateMitochondrialCodonAlphabet(), bpp::CodonAlphabet::isStop(), bpp::StandardCodonAlphabet::StandardCodonAlphabet(), bpp::NucleicAlphabet::subtract(), bpp::VertebrateMitochondrialCodonAlphabet::VertebrateMitochondrialCodonAlphabet(), and bpp::YeastMitochondrialCodonAlphabet::YeastMitochondrialCodonAlphabet().
| bool AbstractAlphabet::isCharInAlphabet | ( | const std::string & | state | ) | const [virtual] |
Tell if a state (specified by its string description) is allowed by the the alphabet.
| state | The string description. |
Implements bpp::Alphabet.
Reimplemented in bpp::LetterAlphabet.
Definition at line 161 of file AbstractAlphabet.cpp.
| bool bpp::AbstractAlphabet::isGap | ( | int | state | ) | const [inline, virtual] |
| state | The state to test. |
Implements bpp::Alphabet.
Reimplemented in bpp::RNY.
Definition at line 133 of file AbstractAlphabet.h.
| bool bpp::AbstractAlphabet::isGap | ( | const std::string & | state | ) | const [inline, virtual] |
| state | The state to test. |
Implements bpp::Alphabet.
Definition at line 134 of file AbstractAlphabet.h.
References charToInt().
| bool AbstractAlphabet::isIntInAlphabet | ( | int | state | ) | const [virtual] |
Tell if a state (specified by its int description) is allowed by the the alphabet.
| state | The int description. |
Implements bpp::Alphabet.
Definition at line 151 of file AbstractAlphabet.cpp.
| virtual bool bpp::Alphabet::isUnresolved | ( | int | state | ) | const [pure virtual, inherited] |
| state | The state to test. |
Implemented in bpp::NucleicAlphabet, bpp::WordAlphabet, bpp::ProteicAlphabet, bpp::RNY, bpp::CaseMaskedAlphabet, bpp::DefaultAlphabet, and bpp::BinaryAlphabet.
Referenced by bpp::SequenceTools::bowkerTest(), bpp::SymbolListTools::changeUnresolvedCharactersToGaps(), bpp::SiteContainerTools::changeUnresolvedCharactersToGaps(), bpp::SiteContainerTools::computeSimilarity(), bpp::SequenceTools::getNumberOfCompleteSites(), bpp::SequenceTools::getNumberOfUnresolvedSites(), bpp::SiteTools::isComplete(), bpp::SiteTools::isGapOrUnresolvedOnly(), bpp::CaseMaskedAlphabet::isUnresolved(), and bpp::SequenceTools::subtractHaplotype().
| virtual bool bpp::Alphabet::isUnresolved | ( | const std::string & | state | ) | const [pure virtual, inherited] |
| state | The state to test. |
Implemented in bpp::NucleicAlphabet, bpp::WordAlphabet, bpp::ProteicAlphabet, bpp::RNY, bpp::CaseMaskedAlphabet, bpp::DefaultAlphabet, and bpp::BinaryAlphabet.
| void AbstractAlphabet::registerState | ( | const AlphabetState & | st | ) | [protected, virtual] |
Add a state to the Alphabet.
| st | The state to add. |
Reimplemented in bpp::LetterAlphabet, bpp::DefaultAlphabet, and bpp::BinaryAlphabet.
Definition at line 65 of file AbstractAlphabet.cpp.
References bpp::AlphabetState::clone().
| void bpp::AbstractAlphabet::remap | ( | ) | [inline, protected] |
Re-update the maps using the alphabet_ vector content.
Definition at line 207 of file AbstractAlphabet.h.
References alphabet_, and updateMaps_().
Referenced by bpp::WordAlphabet::build_().
| void bpp::AbstractAlphabet::resize | ( | unsigned int | size | ) | [inline, protected] |
Resize the private alphabet_ vector.
| size | The new size of the Alphabet. |
Definition at line 182 of file AbstractAlphabet.h.
References alphabet_.
Referenced by bpp::BinaryAlphabet::BinaryAlphabet(), bpp::WordAlphabet::build_(), bpp::DefaultAlphabet::DefaultAlphabet(), and bpp::RNY::RNY().
| void AbstractAlphabet::setState | ( | size_t | pos, |
| const AlphabetState & | st | ||
| ) | throw (IndexOutOfBoundsException) [protected, virtual] |
Set a state in the Alphabet.
| pos | The index of the state in the alphabet_ vector. |
| st | The new state to put in the Alphabet. |
Reimplemented in bpp::LetterAlphabet.
Definition at line 74 of file AbstractAlphabet.cpp.
Referenced by bpp::BinaryAlphabet::BinaryAlphabet(), bpp::WordAlphabet::build_(), and bpp::RNY::RNY().
| void AbstractAlphabet::updateMaps_ | ( | size_t | pos, |
| const AlphabetState & | st | ||
| ) | [private] |
Update the private maps letters_ and nums_ when adding a state.
| pos | The index of the state in the alphabet_ vector. |
| st | The state that have been added or modified |
Definition at line 56 of file AbstractAlphabet.cpp.
References bpp::AlphabetState::getLetter(), and bpp::AlphabetState::getNum().
Referenced by remap().
std::vector<AlphabetState*> bpp::AbstractAlphabet::alphabet_ [private] |
Alphabet: vector of AlphabetState.
Definition at line 75 of file AbstractAlphabet.h.
Referenced by getNumberOfChars(), remap(), resize(), and ~AbstractAlphabet().
std::vector<std::string> bpp::AbstractAlphabet::charList_ [mutable, protected] |
Definition at line 99 of file AbstractAlphabet.h.
std::vector<int> bpp::AbstractAlphabet::intList_ [mutable, protected] |
Definition at line 100 of file AbstractAlphabet.h.
std::map<std::string, size_t> bpp::AbstractAlphabet::letters_ [private] |
Reimplemented in bpp::LetterAlphabet.
Definition at line 80 of file AbstractAlphabet.h.
std::map<int, size_t> bpp::AbstractAlphabet::nums_ [private] |
Definition at line 81 of file AbstractAlphabet.h.