42 #include <Bpp/Text/TextTools.h> 62 for (
unsigned int i = 0; i < num; i++)
74 for (
size_t i = 0; i <
vAbsAlph_.size(); ++i)
79 vector<AlphabetState*> states(size + 2);
82 for (
size_t i = 0; i <
vAbsAlph_.size(); ++i)
89 for (
size_t i = 0; i < size; ++i)
91 states[i + 1] =
new AlphabetState(static_cast<int>(i),
"",
"");
96 for (
size_t na = 0; na <
vAbsAlph_.size(); ++na)
105 for (
size_t k = 0; k < lr; k++)
107 states[j]->setLetter(states[j]->getLetter() + c);
118 for (
size_t i = 0; i <
vAbsAlph_.size(); ++i)
123 states[size + 1] =
new AlphabetState(static_cast<int>(size), s,
"Unresolved");
126 for (
size_t i = 0; i < states.size(); ++i) {
137 string s =
"Word alphabet:";
138 for (
unsigned int i = 0; i <
vAbsAlph_.size(); i++)
140 s +=
" " +
vAbsAlph_[i]->getAlphabetType();
148 string s =
vAbsAlph_[0]->getAlphabetType();
149 for (
unsigned int i = 1; i <
vAbsAlph_.size(); i++)
159 size_t s = vAbsAlph_.size();
160 if (state.length() != s)
163 for (
size_t i = 0; i < vAbsAlph_.size(); i++)
165 if (vAbsAlph_[i]->isUnresolved(state.substr(i, 1)))
177 size_t s = vAbsAlph_.size();
178 if (state.length() != s)
181 for (
size_t i = 0; i < vAbsAlph_.size(); i++)
183 if (vAbsAlph_[i]->isGap(state.substr(i, 1)))
194 if (state.size() != vAbsAlph_.size())
196 if (containsUnresolved(state))
197 return getStateAt(getSize() + 1).getName();
198 if (containsGap(state))
199 return getStateAt(0).getName();
208 if (!isIntInAlphabet(state))
209 throw BadIntException(state,
"WordAlphabet::getAlias(int): Specified base unknown.");
211 size_t s = getSize();
213 if (static_cast<size_t>(state) == s)
216 for (
size_t i = 0; i < s; ++i)
218 v[i] =
static_cast<int>(i);
223 v.resize(1); v[0] = state;
232 string locstate = TextTools::toUpper(state);
233 if (!isCharInAlphabet(locstate))
234 throw BadCharException(locstate,
"WordAlphabet::getAlias(string): Specified base unknown.");
237 size_t s = getSize();
240 for (
size_t i = 0; i < vAbsAlph_.size(); ++i)
248 for (
size_t i = 0; i < s; ++i)
250 v[i] = intToChar(static_cast<int>(i));
255 v.resize(1); v[0] = state;
278 if (vint.size() < pos + vAbsAlph_.size())
279 throw IndexOutOfBoundsException(
"WordAlphabet::getWord", pos, 0, vint.size() - vAbsAlph_.size());
282 for (
size_t i = 0; i < vAbsAlph_.size(); i++)
284 vs.push_back(vAbsAlph_[i]->intToChar(vint[i + pos]));
287 return charToInt(getWord(vs));
294 if (vpos.size() < pos + vAbsAlph_.size())
295 throw IndexOutOfBoundsException(
"WordAlphabet::getWord", pos, 0, vpos.size() - vAbsAlph_.size());
298 for (
size_t i = 0; i < vAbsAlph_.size(); i++)
311 if ((!hasUniqueAlphabet()) or
312 (sequence.getAlphabet()->getAlphabetType() != vAbsAlph_[0]->getAlphabetType()))
315 vector<int> v1 = sequence.getContent();
318 size_t s = sequence.size();
319 unsigned int l = getLength();
324 v2.push_back(getWord(v1, i));
335 if ((!hasUniqueAlphabet()) or
336 (sequence.getAlphabet()->getAlphabetType() != getAlphabetType()))
341 size_t s = sequence.
size();
342 for (
size_t i = 0; i < s; i++)
344 pseq->
append(getPositions(sequence[i]));
This is the base class to describe states in an Alphabet.
An alphabet exception thrown when trying to specify a bad char to the alphabet.
Sequence * reverse(const Sequence &sequence) const
Translate a whole sequence from words alphabet to letters alphabet.
int getGeneric(const std::vector< int > &states) const
Get the generic state that match a set of states.
bool containsUnresolved(const std::string &state) const
This alphabet is used to deal NumericAlphabet.
Sequence * translate(const Sequence &sequence, size_t=0) const
Translate a whole sequence from letters alphabet to words alphabet.
std::string getAlphabetType() const
Identification method.
unsigned int getSize() const
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.
WordAlphabet(const std::vector< const Alphabet *> &vAlpha)
Builds a new word alphabet from a vector of Alphabets.
virtual void append(const std::vector< int > &content)=0
Append the specified content to the sequence.
bool containsGap(const std::string &state) const
std::vector< const Alphabet *> vAbsAlph_
A basic implementation of the Sequence interface.
A partial implementation of the Alphabet interface.
virtual size_t size() const
Get the number of elements in the list.
std::string getName(const std::string &state) const
Get the complete name of a state given its string description.
virtual int getWord(const std::vector< int > &vint, size_t pos=0) const
Get the int code for a word given the int code of the underlying positions.
An alphabet exception thrown when trying to specify a bad int to the alphabet.
Exception thrown when two alphabets do not match.
virtual void registerState(AlphabetState *st)
Add a state to the Alphabet.
bool hasUniqueAlphabet() const
Returns True if the Alphabet of the letters in the word are the same type.
std::string getName(const std::string &state) const
Get the complete name of a state given its string description.
std::vector< int > getAlias(int state) const
Get all resolved states that match a generic state.