19 vector<AlphabetState*> states(66);
24 for (
int i1 = 0; i1 < 4; ++i1)
26 for (
int i2 = 0; i2 < 4; ++i2)
28 for (
int i3 = 0; i3 < 4; ++i3)
30 string s = nAlph_->intToChar(i1) + nAlph_->intToChar(i2) + nAlph_->intToChar(i3);
38 states[65] =
new AlphabetState(
static_cast<int>(64),
"NNN",
"Unresolved");
41 for (i = 0; i < states.size(); ++i)
43 registerState(states[i]);
50 int j = getFirstPosition(codon);
53 j = getSecondPosition(codon);
56 j = getThirdPosition(codon);
65 if (state.length() != 3)
68 for (
size_t i = 0; i < 3; i++)
70 if (nAlph_->isUnresolved(state.substr(i, 1)))
82 if (state.length() != 3)
85 for (
size_t i = 0; i < 3; i++)
87 if (nAlph_->isGap(state.substr(i, 1)))
101 size_t s = sequence.
size();
106 content.push_back(getWord(sequence, i));
110 auto alphaPtr = shared_from_this();
111 return make_unique<Sequence>(sequence.
getName(), content, alphaPtr);
118 auto alphaPtr = getNAlphabet(0);
119 auto seqPtr = make_unique<Sequence>(sequence.
getName(),
"", alphaPtr);
121 size_t s = sequence.
size();
122 for (
size_t i = 0; i < s; i++)
124 seqPtr->append(getPositions(sequence[i]));
134 if (!isIntInAlphabet(state))
135 throw BadIntException(state,
"WordAlphabet::getAlias(int): Specified base unknown.",
this);
141 for (
size_t i = 0; i < 64; ++i)
143 v[i] =
static_cast<int>(i);
148 v.resize(1); v[0] = state;
158 if (!isCharInAlphabet(locstate))
159 throw BadCharException(locstate,
"CodonAlphabet::getAlias(string): Specified base unknown.",
this);
162 if (locstate ==
"NNN")
165 for (
size_t i = 0; i < 64; ++i)
167 v[i] = intToChar(
static_cast<int>(i));
172 v.resize(1); v[0] = state;
180 if (state1 < 0 || !isIntInAlphabet(state1))
181 throw BadIntException(state1,
"CodonAlphabet::isResolvedIn(int, int): Specified base " + intToChar(state1) +
" is unknown.",
this);
183 if (state2 < 0 || !isIntInAlphabet(state2))
184 throw BadIntException(state2,
"CodonAlphabet::isResolvedIn(int, int): Specified base " + intToChar(state2) +
" is unknown.",
this);
186 if (isUnresolved(state2))
187 throw BadIntException(state2,
"CodonAlphabet::isResolvedIn(int, int): Unresolved base " + intToChar(state2),
this);
189 return (state1 == 64) ? (state2 >= 0) : (state1 == state2);
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.
An alphabet exception thrown when trying to specify a bad int to the alphabet.
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.
std::unique_ptr< SequenceInterface > reverse(const SequenceInterface &sequence) const override
Translate a whole sequence from words alphabet to letters alphabet.
int getGCinCodon(int codon) const
Get the number of G+C in codon.
bool containsGap(const std::string &state) const override
std::unique_ptr< SequenceInterface > translate(const SequenceInterface &sequence, size_t=0) const override
Translate a whole sequence from letters alphabet to words alphabet.
bool containsUnresolved(const std::string &state) const override
virtual const std::string & getName() const =0
Get the name of this sequence.
virtual size_t size() const =0
Get the number of elements in the list.
std::string toUpper(const std::string &s)
This alphabet is used to deal NumericAlphabet.