5 #ifndef BPP_SEQ_ALPHABET_WORDALPHABET_H
6 #define BPP_SEQ_ALPHABET_WORDALPHABET_H
15 #include "../Sequence.h"
37 virtual std::shared_ptr<const Alphabet>
getNAlphabet(
size_t n)
const = 0;
51 virtual int getWord(
const std::vector<int>& vint,
size_t pos = 0)
const = 0;
63 virtual std::string
getWord(
const std::vector<std::string>& vpos,
size_t pos = 0)
const = 0;
89 virtual std::string
getNPosition(
const std::string& word,
size_t n)
const = 0;
97 virtual std::vector<std::string>
getPositions(
const std::string& word)
const = 0;
153 std::vector< std::shared_ptr<const Alphabet>>
vAbsAlph_;
165 WordAlphabet(
const std::vector< std::shared_ptr<const Alphabet>>& vAlpha);
174 WordAlphabet(std::shared_ptr<const Alphabet> pAlpha,
size_t num);
208 std::string
getName(
const std::string& state)
const override;
215 return static_cast<int>(
getSize());
229 bool isResolvedIn(
int state1,
int state2)
const override;
244 return static_cast<unsigned int>(
vAbsAlph_.size());
261 return static_cast<int>(
getSize());
267 std::vector<int>
getAlias(
int state)
const override;
269 std::vector<std::string>
getAlias(
const std::string& state)
const override;
271 int getGeneric(
const std::vector<int>& states)
const override;
273 std::string
getGeneric(
const std::vector<std::string>& states)
const override;
282 bool containsGap(
const std::string& state)
const override;
317 virtual int getWord(
const Sequence& seq,
size_t pos = 0)
const override;
330 virtual int getWord(
const std::vector<int>& vint,
size_t pos = 0)
const override;
343 virtual std::string
getWord(
const std::vector<std::string>& vpos,
size_t pos = 0)
const override;
358 return vAbsAlph_[n]->charToInt(s.substr(n, 1));
370 std::vector<int> positions;
371 for (
size_t i = 0; i < s.size(); i++)
385 std::string
getNPosition(
const std::string& word,
size_t n)
const override
392 return "" + word.substr(n, 1);
402 std::vector<std::string>
getPositions(
const std::string& word)
const override
405 std::vector<std::string> positions;
406 for (
size_t i = 0; i < word.size(); i++)
408 positions.push_back(word.substr(i, 1));
443 return static_cast<unsigned int>(
vAbsAlph_.size());
A partial implementation of the Alphabet interface.
unsigned int getNumberOfChars() const
Get the number of supported characters in this alphabet, including generic characters (e....
AbstractAlphabet & operator=(const AbstractAlphabet &alph)
std::string intToChar(int state) const
Give the string description of a state given its int description.
int charToInt(const std::string &state) const
Give the int description of a state given its string description.
An alphabet exception thrown when trying to specify a bad char to the alphabet.
The interface class for word alphabets.
virtual std::string getNPosition(const std::string &word, size_t n) const =0
Get the char code of the n-position of a word given its char description.
virtual bool containsUnresolved(const std::string &state) const =0
virtual int getWord(const std::vector< int > &vint, size_t pos=0) const =0
Get the int code for a word given the int code of the underlying positions.
virtual std::vector< std::string > getPositions(const std::string &word) const =0
Get the char codes of each position of a word given its char description.
virtual std::shared_ptr< const Alphabet > getNAlphabet(size_t n) const =0
virtual int getWord(const Sequence &seq, size_t pos=0) const =0
virtual std::unique_ptr< SequenceInterface > translate(const SequenceInterface &sequence, size_t pos=0) const =0
Translate a whole sequence from letters alphabet to words alphabet.
virtual std::unique_ptr< SequenceInterface > reverse(const SequenceInterface &sequence) const =0
Translate a whole sequence from words alphabet to letters alphabet.
virtual unsigned int getSize() const =0
virtual std::vector< int > getPositions(int word) const =0
Get the int codes of each position of a word given its int description.
virtual ~CoreWordAlphabet()
virtual bool containsGap(const std::string &state) const =0
virtual int getNPosition(int word, size_t n) const =0
Get the int code of the n-position of a word given its int description.
virtual unsigned int getLength() const =0
virtual bool hasUniqueAlphabet() const =0
virtual std::string getWord(const std::vector< std::string > &vpos, size_t pos=0) const =0
Get the char code for a word given the char code of the underlying positions.
A basic implementation of the Sequence interface.
The base class for word alphabets.
bool isUnresolved(int state) const override
unsigned int getLength() const override
Returns the length of the word.
WordAlphabet(const WordAlphabet &bia)
bool containsGap(const std::string &state) const override
bool containsUnresolved(const std::string &state) const override
virtual int getWord(const Sequence &seq, size_t pos=0) const override
Get the int code for a word given the int code of the underlying positions.
std::vector< std::shared_ptr< const Alphabet > > vAbsAlph_
unsigned int getNumberOfTypes() const override
Returns the number of resolved states + one for unresolved.
unsigned int getStateCodingSize() const override
Get the size of the string coding a state.
std::vector< int > getAlias(int state) const override
Get all resolved states that match a generic state.
bool isResolvedIn(int state1, int state2) const override
Tells if a given (potentially unresolved) state can be resolved in another resolved state.
bool hasUniqueAlphabet() const override
Returns True if the Alphabet of the letters in the word are the same type.
std::string getAlphabetType() const override
Identification method.
int getUnknownCharacterCode() const override
int getNPosition(int word, size_t n) const override
Get the int code of the n-position of a word given its int description.
int getGeneric(const std::vector< int > &states) const override
Get the generic state that match a set of states.
std::unique_ptr< SequenceInterface > translate(const SequenceInterface &sequence, size_t=0) const override
Translate a whole sequence from letters alphabet to words alphabet.
std::unique_ptr< SequenceInterface > reverse(const SequenceInterface &sequence) const override
Translate a whole sequence from words alphabet to letters alphabet.
WordAlphabet(const std::vector< std::shared_ptr< const Alphabet >> &vAlpha)
Builds a new word alphabet from a vector of Alphabets.
int charToInt(const std::string &state) const override
Give the int description of a state given its string description.
std::string getNPosition(const std::string &word, size_t n) const override
Get the char code of the n-position of a word given its char description.
unsigned int getSize() const override
std::vector< std::string > getPositions(const std::string &word) const override
Get the char codes of each position of a word given its char description.
std::vector< int > getPositions(int word) const override
Get the int codes of each position of a word given its int description.
std::string getName(const std::string &state) const override
Get the complete name of a state given its string description.
std::shared_ptr< const Alphabet > getNAlphabet(size_t n) const override
Get the pointer to the Alphabet at the n-position.
WordAlphabet * clone() const override
bool isUnresolved(const std::string &state) const override
WordAlphabet & operator=(const WordAlphabet &bia)
This alphabet is used to deal NumericAlphabet.